From 73534f0a7c975931dbe17b2372f56402de4bdf9d Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:39:52 -0300 Subject: [PATCH 1/4] Update main.dart --- lib/main.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 3b968f7d0b..e81c98c900 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -81,8 +81,27 @@ void main() async { await _initializeServices(); await _startApp(); - }, (error, stackTrace) { + }, (error, stackTrace) async { logger.e('Error caught.', error, stackTrace); + + if (error.toString().contains('snapshot_entries')) { + logger.d('Handling snapshot_entries exception'); + WidgetsFlutterBinding.ensureInitialized(); + + final database = Database(); + logger.d('Dropping snapshot_entries table'); + + await database.customStatement(''' + DROP TABLE IF EXISTS snapshot_entries; + '''); + + logger.d('Re-initializing services'); + + await _initializeServices(); + + logger.d('Restarting app'); + _startApp(); + } }); } From a92f69c10219c0848b59e19f0f04d5b71cbc4001 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 12 Sep 2024 12:40:40 -0300 Subject: [PATCH 2/4] remove snapshot_entries table --- lib/models/database/database.dart | 1 - lib/models/tables/snapshot_entries.drift | 13 ------------- 2 files changed, 14 deletions(-) delete mode 100644 lib/models/tables/snapshot_entries.drift diff --git a/lib/models/database/database.dart b/lib/models/database/database.dart index 5a5add8f0c..6bd51a4ca3 100644 --- a/lib/models/database/database.dart +++ b/lib/models/database/database.dart @@ -21,7 +21,6 @@ part 'database.g.dart'; '../tables/licenses.drift', '../tables/network_transactions.drift', '../tables/profiles.drift', - '../tables/snapshot_entries.drift', '../tables/arns_records.drift', '../tables/ant_records.drift', }, diff --git a/lib/models/tables/snapshot_entries.drift b/lib/models/tables/snapshot_entries.drift deleted file mode 100644 index c2228a0f59..0000000000 --- a/lib/models/tables/snapshot_entries.drift +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE snapshot_entries ( - id TEXT NOT NULL, - driveId TEXT NOT NULL, - blockStart INTEGER NOT NULL, - blockEnd INTEGER NOT NULL, - dataStart INTEGER NOT NULL, - dataEnd INTEGER NOT NULL, - - txId TEXT NOT NULL, - - dateCreated DATETIME NOT NULL DEFAULT (strftime('%s','now')), - PRIMARY KEY (id, driveId) -) As SnapshotEntry; From 450c39b6a48f33e83d5561c1479757c4d4de4ac0 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:36:14 -0300 Subject: [PATCH 3/4] bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e847326136..b980c6b8e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Secure, permanent storage publish_to: 'none' -version: 2.54.0 +version: 2.54.2 environment: sdk: '>=3.2.0 <4.0.0' From 52b69c15e76c58b5b8f97eb52b63cbfc212551cb Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:22:27 -0300 Subject: [PATCH 4/4] refator: migrate instead of handle exception --- lib/main.dart | 19 ------------------- lib/models/database/database.dart | 14 +++++++++++++- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e81c98c900..1c6556f794 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -83,25 +83,6 @@ void main() async { await _startApp(); }, (error, stackTrace) async { logger.e('Error caught.', error, stackTrace); - - if (error.toString().contains('snapshot_entries')) { - logger.d('Handling snapshot_entries exception'); - WidgetsFlutterBinding.ensureInitialized(); - - final database = Database(); - logger.d('Dropping snapshot_entries table'); - - await database.customStatement(''' - DROP TABLE IF EXISTS snapshot_entries; - '''); - - logger.d('Re-initializing services'); - - await _initializeServices(); - - logger.d('Restarting app'); - _startApp(); - } }); } diff --git a/lib/models/database/database.dart b/lib/models/database/database.dart index 6bd51a4ca3..3e152d366a 100644 --- a/lib/models/database/database.dart +++ b/lib/models/database/database.dart @@ -30,7 +30,7 @@ class Database extends _$Database { Database([QueryExecutor? e]) : super(e ?? openConnection()); @override - int get schemaVersion => 21; + int get schemaVersion => 22; @override MigrationStrategy get migration => MigrationStrategy( onCreate: (Migrator m) { @@ -130,6 +130,18 @@ class Database extends _$Database { await m.createTable(arnsRecords); await m.createTable(antRecords); } + + if (from < 22) { + logger.d('Migrating schema from v21 to v22'); + + logger.d('Dropping snapshot_entries table'); + + await customStatement(''' + DROP TABLE IF EXISTS snapshot_entries; + '''); + + logger.d('snapshot_entries table dropped'); + } } catch (e, stacktrace) { logger.e( 'CRITICAL! Failed to migrate database from $from to $to',