spotube/test/drift/app_db/migration_test.dart
Alessio fece073def This pull request primarily involves the removal of several configuration files and assets, as well as minor updates to documentation. The most significant changes are the deletion of various .vscode configuration files and the removal of unused assets from the project.
Configuration File Removals:

    .vscode/c_cpp_properties.json: Removed the entire configuration for C/C++ properties.
    .vscode/launch.json: Removed the Dart launch configurations for different environments and modes.
    .vscode/settings.json: Removed settings related to CMake, spell checking, file nesting, and Dart Flutter SDK path.
    .vscode/snippets.code-snippets: Removed code snippets for Dart, including PaginatedState and PaginatedNotifier templates.
    .vscode/tasks.json: Removed the tasks configuration file.

Documentation Updates:

    CONTRIBUTION.md: Removed heart emoji from the introductory text.
    README.md: Updated the logo image and made minor text adjustments, including removing emojis and updating section titles. [1] [2] [3] [4] [5]

Asset Removals:

    lib/collections/assets.gen.dart: Removed multiple unused asset references, including images related to Spotube logos and banners. [1] [2] [3]

Minor Code Cleanups:

    cli/commands/build/linux.dart, cli/commands/build/windows.dart, cli/commands/translated.dart, cli/commands/untranslated.dart: Adjusted import statements for consistency. [1] [2] [3] [4]
    integration_test/app_test.dart: Removed an unnecessary blank line.
    lib/collections/routes.dart: Commented out the TrackRoute configuration.
2025-04-13 18:40:37 +02:00

129 lines
5.7 KiB
Dart

// ignore_for_file: unused_local_variable, unused_import
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations.dart';
import 'package:spotube/models/database/database.dart';
import 'package:test/test.dart';
import 'generated/schema.dart';
import 'generated/schema_v1.dart' as v1;
import 'generated/schema_v2.dart' as v2;
void main() {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
late SchemaVerifier verifier;
setUpAll(() {
verifier = SchemaVerifier(GeneratedHelper());
});
group('simple database migrations', () {
// These simple tests verify all possible schema updates with a simple (no
// data) migration. This is a quick way to ensure that written database
// migrations properly alter the schema.
final versions = GeneratedHelper.versions;
for (final (i, fromVersion) in versions.indexed) {
group('from $fromVersion', () {
for (final toVersion in versions.skip(i + 1)) {
test('to $toVersion', () async {
final schema = await verifier.schemaAt(fromVersion);
final db = Database(schema.newConnection());
await verifier.migrateAndValidate(db, toVersion);
await db.close();
});
}
});
}
});
// Simple tests ensure the schema is transformed correctly, but some
// migrations benefit from a test verifying that data is transformed correctly
// too. This is particularly true for migrations that change existing columns
// (e.g. altering their type or constraints). Migrations that only add tables
// or columns typically don't need these advanced tests.
// TODO: Check whether you have migrations that could benefit from these tests
// and adapt this example to your database if necessary:
test("migration from v1 to v2 does not corrupt data", () async {
// Add data to insert into the old database, and the expected rows after the
// migration.
final oldAuthenticationTableData = <v1.AuthenticationTableData>[];
final expectedNewAuthenticationTableData = <v2.AuthenticationTableData>[];
final oldBlacklistTableData = <v1.BlacklistTableData>[];
final expectedNewBlacklistTableData = <v2.BlacklistTableData>[];
final oldPreferencesTableData = <v1.PreferencesTableData>[];
final expectedNewPreferencesTableData = <v2.PreferencesTableData>[];
final oldScrobblerTableData = <v1.ScrobblerTableData>[];
final expectedNewScrobblerTableData = <v2.ScrobblerTableData>[];
final oldSkipSegmentTableData = <v1.SkipSegmentTableData>[];
final expectedNewSkipSegmentTableData = <v2.SkipSegmentTableData>[];
final oldSourceMatchTableData = <v1.SourceMatchTableData>[];
final expectedNewSourceMatchTableData = <v2.SourceMatchTableData>[];
final oldAudioPlayerStateTableData = <v1.AudioPlayerStateTableData>[];
final expectedNewAudioPlayerStateTableData =
<v2.AudioPlayerStateTableData>[];
final oldPlaylistTableData = <v1.PlaylistTableData>[];
final expectedNewPlaylistTableData = <v2.PlaylistTableData>[];
final oldPlaylistMediaTableData = <v1.PlaylistMediaTableData>[];
final expectedNewPlaylistMediaTableData = <v2.PlaylistMediaTableData>[];
final oldHistoryTableData = <v1.HistoryTableData>[];
final expectedNewHistoryTableData = <v2.HistoryTableData>[];
final oldLyricsTableData = <v1.LyricsTableData>[];
final expectedNewLyricsTableData = <v2.LyricsTableData>[];
await verifier.testWithDataIntegrity(
oldVersion: 1,
newVersion: 2,
createOld: v1.DatabaseAtV1.new,
createNew: v2.DatabaseAtV2.new,
openTestedDatabase: (x) => AppDatabase(),
createItems: (batch, oldDb) {
batch.insertAll(oldDb.authenticationTable, oldAuthenticationTableData);
batch.insertAll(oldDb.blacklistTable, oldBlacklistTableData);
batch.insertAll(oldDb.preferencesTable, oldPreferencesTableData);
batch.insertAll(oldDb.scrobblerTable, oldScrobblerTableData);
batch.insertAll(oldDb.skipSegmentTable, oldSkipSegmentTableData);
batch.insertAll(oldDb.sourceMatchTable, oldSourceMatchTableData);
batch.insertAll(
oldDb.audioPlayerStateTable, oldAudioPlayerStateTableData);
batch.insertAll(oldDb.playlistTable, oldPlaylistTableData);
batch.insertAll(oldDb.playlistMediaTable, oldPlaylistMediaTableData);
batch.insertAll(oldDb.historyTable, oldHistoryTableData);
batch.insertAll(oldDb.lyricsTable, oldLyricsTableData);
},
validateItems: (newDb) async {
expect(expectedNewAuthenticationTableData,
await newDb.select(newDb.authenticationTable).get());
expect(expectedNewBlacklistTableData,
await newDb.select(newDb.blacklistTable).get());
expect(expectedNewPreferencesTableData,
await newDb.select(newDb.preferencesTable).get());
expect(expectedNewScrobblerTableData,
await newDb.select(newDb.scrobblerTable).get());
expect(expectedNewSkipSegmentTableData,
await newDb.select(newDb.skipSegmentTable).get());
expect(expectedNewSourceMatchTableData,
await newDb.select(newDb.sourceMatchTable).get());
expect(expectedNewAudioPlayerStateTableData,
await newDb.select(newDb.audioPlayerStateTable).get());
expect(expectedNewPlaylistTableData,
await newDb.select(newDb.playlistTable).get());
expect(expectedNewPlaylistMediaTableData,
await newDb.select(newDb.playlistMediaTable).get());
expect(expectedNewHistoryTableData,
await newDb.select(newDb.historyTable).get());
expect(expectedNewLyricsTableData,
await newDb.select(newDb.lyricsTable).get());
},
);
});
}