From 3717446371c8687dd6d4c5b77f8349337197aea3 Mon Sep 17 00:00:00 2001 From: AminBhst Date: Sun, 22 Dec 2024 11:53:14 +0330 Subject: [PATCH] Remove force reset to default for settings, Add initial migration box --- lib/db/hive_util.dart | 8 +++---- lib/db/migration_manager.dart | 3 +++ lib/model/migration.dart | 14 +++++++++++ lib/model/migration.g.dart | 44 +++++++++++++++++++++++++++++++++++ pubspec.lock | 40 +++++++++++++++---------------- 5 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 lib/db/migration_manager.dart create mode 100644 lib/model/migration.dart create mode 100644 lib/model/migration.g.dart diff --git a/lib/db/hive_util.dart b/lib/db/hive_util.dart index 5ac5b14..c8ca7a3 100644 --- a/lib/db/hive_util.dart +++ b/lib/db/hive_util.dart @@ -1,6 +1,7 @@ import 'package:brisk/constants/setting_options.dart'; import 'package:brisk/model/download_queue.dart'; import 'package:brisk/model/general_data.dart'; +import 'package:brisk/model/migration.dart'; import 'package:brisk/model/setting.dart'; import 'package:brisk/util/settings_cache.dart'; import 'package:hive_flutter/adapters.dart'; @@ -21,6 +22,8 @@ class HiveUtil { late final Box generalDataBox; + late final Box migrationBox; + Future initHive() async { await Hive.initFlutter("Brisk_v2"); Hive.registerAdapter(DownloadItemAdapter()); @@ -35,6 +38,7 @@ class HiveUtil { downloadQueueBox = await Hive.openBox("download_queues"); settingBox = await Hive.openBox("settings"); generalDataBox = await Hive.openBox("general_data"); + migrationBox = await Hive.openBox("migrations"); } static Setting? getSetting(SettingOptions option) { @@ -47,10 +51,6 @@ class HiveUtil { if (downloadQueueBox.get(0) == null) { downloadQueueBox.put(0, DownloadQueue(name: "Main")); } - if (settingBox.values.length -1 != SettingsCache.defaultSettings.length) { - await SettingsCache.setDefaultSettings(); - } - final appVersion = generalDataBox.values .where((val) => val.fieldName == "appVersion") .firstOrNull; diff --git a/lib/db/migration_manager.dart b/lib/db/migration_manager.dart new file mode 100644 index 0000000..d8d2831 --- /dev/null +++ b/lib/db/migration_manager.dart @@ -0,0 +1,3 @@ +class MigrationManager { + +} \ No newline at end of file diff --git a/lib/model/migration.dart b/lib/model/migration.dart new file mode 100644 index 0000000..da84a23 --- /dev/null +++ b/lib/model/migration.dart @@ -0,0 +1,14 @@ +import 'package:hive/hive.dart'; + +part 'migration.g.dart'; + +@HiveType(typeId: 4) +class Migration extends HiveObject { + @HiveField(1) + int version; + + @HiveField(2) + String description; + + Migration(this.version, this.description); +} diff --git a/lib/model/migration.g.dart b/lib/model/migration.g.dart new file mode 100644 index 0000000..5a692d5 --- /dev/null +++ b/lib/model/migration.g.dart @@ -0,0 +1,44 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'migration.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class MigrationAdapter extends TypeAdapter { + @override + final int typeId = 4; + + @override + Migration read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return Migration( + fields[1] as int, + fields[2] as String, + ); + } + + @override + void write(BinaryWriter writer, Migration obj) { + writer + ..writeByte(2) + ..writeByte(1) + ..write(obj.version) + ..writeByte(2) + ..write(obj.description); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is MigrationAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/pubspec.lock b/pubspec.lock index 90c6c7f..7b1c44a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -173,10 +173,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" convert: dependency: transitive description: @@ -540,18 +540,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.7" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.8" leak_tracker_testing: dependency: transitive description: @@ -596,10 +596,10 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" menu_base: dependency: transitive description: @@ -612,10 +612,10 @@ packages: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" mime: dependency: transitive description: @@ -867,7 +867,7 @@ packages: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_gen: dependency: transitive description: @@ -904,10 +904,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: "direct main" description: @@ -928,10 +928,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -944,10 +944,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.3" time: dependency: transitive description: @@ -1104,10 +1104,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.3.0" watcher: dependency: transitive description: @@ -1205,5 +1205,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.4.0 <4.0.0" + dart: ">=3.4.0 <=3.6.0" flutter: ">=3.22.0"