fix(database): tolerate retried v14 migration

This commit is contained in:
edde746
2026-05-07 11:27:12 +02:00
parent 187eeb19d3
commit 2208d6c637
2 changed files with 44 additions and 5 deletions
+30
View File
@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:drift/drift.dart' hide isNull, isNotNull;
import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -106,6 +108,34 @@ class _AppDatabaseTestSuite {
containsAll(['idx_profiles_kind', 'idx_profile_connections_profile_id', 'idx_offline_watch_progress_server']),
);
});
test('retried v14 migration tolerates existing indices', () async {
await db.close();
final tempDir = await Directory.systemTemp.createTemp('plezy_db_migration_test_');
final file = File('${tempDir.path}/plezy_downloads.db');
AppDatabase? seeded;
AppDatabase? reopened;
try {
seeded = AppDatabase.forTesting(NativeDatabase(file));
await seeded.select(seeded.connections).get();
await seeded.customStatement('PRAGMA user_version = 13');
await seeded.close();
seeded = null;
reopened = AppDatabase.forTesting(NativeDatabase(file));
expect(await reopened.select(reopened.connections).get(), isEmpty);
final rows = await reopened
.customSelect("SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'idx_connections_kind'")
.get();
expect(rows, hasLength(1));
} finally {
await reopened?.close();
await seeded?.close();
await tempDir.delete(recursive: true);
db = AppDatabase.forTesting(NativeDatabase.memory());
}
});
});
}