Schema 11: Playlists.cloudId fuer die einseitige Sicherung

This commit is contained in:
Hermes (Server)
2026-08-27 13:31:33 +02:00
parent 11a01d1a09
commit 3cd88565ec
3 changed files with 166 additions and 5 deletions
+28 -1
View File
@@ -72,6 +72,10 @@ class Playlists extends Table {
IntColumn get updatedAtMs => integer()();
BoolColumn get deleted => boolean().withDefault(const Constant(false))();
/// ID derselben Playlist am Melo-Server, sobald sie einmal gesichert
/// wurde. `null` heißt: nur auf diesem Gerät.
TextColumn get cloudId => text().nullable()();
@override
Set<Column> get primaryKey => {id};
}
@@ -148,7 +152,7 @@ class MeloDb extends _$MeloDb {
MeloDb([QueryExecutor? executor]) : super(executor ?? _open());
@override
int get schemaVersion => 10;
int get schemaVersion => 11;
@override
MigrationStrategy get migration => MigrationStrategy(
@@ -190,6 +194,9 @@ class MeloDb extends _$MeloDb {
if (from < 10) {
await m.createTable(downloads);
}
if (from < 11) {
await m.addColumn(playlists, playlists.cloudId);
}
},
);
@@ -284,6 +291,26 @@ class MeloDb extends _$MeloDb {
);
}
Future<Playlist?> playlistById(String id) =>
(select(playlists)..where((p) => p.id.equals(id))).getSingleOrNull();
Future<void> setPlaylistCloudId(String id, String cloudId) async {
await (update(playlists)..where((p) => p.id.equals(id)))
.write(PlaylistsCompanion(cloudId: Value(cloudId)));
}
/// Wie viele Playlisten es hier gibt — **inklusive Grabsteinen**.
///
/// Grundlage der Wiederherstellung: nur eine wirklich leere Tabelle gilt
/// als Neuinstallation. Wer alle Playlisten selbst gelöscht hat, soll sie
/// nicht vom Server zurückbekommen.
Future<int> countPlaylists() async {
final zaehler = playlists.id.count();
final zeile = await (selectOnly(playlists)..addColumns([zaehler]))
.getSingle();
return zeile.read(zaehler) ?? 0;
}
// === PlaylistSongs ===
Stream<List<Song>> watchPlaylistSongs(String playlistId) {
final query = select(songs).join([