Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Skip write transaction for up-to-date databases

laurenspriemc8a302a19ef8
diff --git a/mobile/apps/photos/lib/db/common/base.dart b/mobile/apps/photos/lib/db/common/base.dart
index 327d2bb8a7..7fd5f3e544 100644
--- a/mobile/apps/photos/lib/db/common/base.dart
+++ b/mobile/apps/photos/lib/db/common/base.dart
@@ -17,6 +17,20 @@ mixin SqlDbBase {
List<String> migrationScripts,
) async {
final toVersion = migrationScripts.length;
+ final probe = await database.writeLock(
+ (tx) => tx.get('PRAGMA user_version'),
+ );
+ final probedVersion = probe['user_version'] as int;
+
+ if (probedVersion > toVersion) {
+ throw AssertionError(
+ "currentVersion($probedVersion) cannot be greater than toVersion($toVersion)",
+ );
+ }
+ if (probedVersion == toVersion) {
+ return;
+ }
+
final didMigrate = await database.writeTransaction((tx) async {
final result = await tx.get('PRAGMA user_version');
final currentVersion = result['user_version'] as int;