mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-08-02 09:08:35 +02:00
fix(database): make playback session migration idempotent
This commit is contained in:
@@ -103,8 +103,11 @@ class AppStateDatabase {
|
||||
}
|
||||
|
||||
static Future<void> _createPlaybackSessionTable(Database db) {
|
||||
// Keep this idempotent so an interrupted migration or a database restored
|
||||
// from an intermediate build can resume v1 -> v2 without losing queue
|
||||
// state merely because the table was already created.
|
||||
return db.execute('''
|
||||
CREATE TABLE $_playbackSessionTable (
|
||||
CREATE TABLE IF NOT EXISTS $_playbackSessionTable (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
session_json TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
|
||||
@@ -139,6 +139,26 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('app state database migrations', () {
|
||||
final source = File(
|
||||
'lib/services/app_state_database.dart',
|
||||
).readAsStringSync();
|
||||
|
||||
test('v1 to v2 tolerates an existing playback session table', () {
|
||||
expect(
|
||||
source,
|
||||
contains('CREATE TABLE IF NOT EXISTS \$_playbackSessionTable'),
|
||||
);
|
||||
expect(
|
||||
RegExp(
|
||||
r'if \(oldVersion < 2\)\s*\{\s*'
|
||||
r'await _createPlaybackSessionTable\(db\);',
|
||||
).hasMatch(source),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('native worker contracts', () {
|
||||
final finalizerSource = File(
|
||||
'android/app/src/main/kotlin/com/zarz/spotiflac/'
|
||||
|
||||
Reference in New Issue
Block a user