搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.0

data_migration

一個用於套用一連串遷移,將舊版本的資料結構更新至最新版本的函式庫。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
44
喜歡數
3
Pub 分數
150

安裝套件

flutter pub add data_migration

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

data_migration 套件提供了一種結構化的方式,透過應用一系列遷移來跨不同版本演進資料模型。它設計用於安全地將過時的資料結構更新至最新架構,確保應用程式更新期間的資料完整性。開發者可定義遷移步驟,將舊的資料格式轉換為新格式,非常適合具有持久性本機儲存的應用程式。此套件支援多個平台,並能與 Flutter 應用程式無縫整合。

適用情境

  • 更新本地資料庫模式
  • 在應用版本之間遷移用戶資料
  • 保持向後相容性
  • 處理共享首選項中的模式變更
  • 在應用啟動時自動執行資料轉換
  • 支援複雜資料模型演進

主要特色

  • 版本化遷移系統
  • 安全的資料轉換
  • 可擴展的遷移定義
  • 跨平台支援
  • 用於定義遷移的簡單 API
  • 內建錯誤處理

適合對象

  • 具有持久本地資料的應用程式
  • 開發人員管理架構變更
  • 需要向後兼容的項目
  • 使用版本化數據模型的團隊
  • 具有不斷演變的資料結構的 Flutter 應用

使用建議

  • 需要仔細規劃遷移步驟
  • 手動定義每次遷移
  • 大資料集可能帶來的效能影響
  • 有限的內建驗證
  • 不適用於即時同步場景
  • 依賴於正確的版本追蹤

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Data Migration

ci License: MIT coverage

A library for applying a series of migrations to update old versions of data structures to the most recent one.

Installation

dependencies:
  data_migration:

How to use

  1. Create your set of migration

    class CounterV1DataMigration implements DataMigration {
      const CounterV1DataMigration();
    
      @override
      int get fromVersion => 1;
    
      @override
      int get toVersion => 2;
    
      @override
      Future<dynamic> migrate(dynamic data) async {
        final counter = SimpleCounter(data as int);
        return counter.toJson();
      }
    }
    
    final migrator = DataMigrationManager(
      [
        CounterV1DataMigration(),
      ],
    );
    
  2. Apply migration on data

      final migrated1 = await _migrator.migrateIfNeeded(
         3,
         fromVersion: 1,
      );
    

Examples

In the example and tests, there are some examples of "data migration."

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。