mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
client: Allow updating existing works
This commit is contained in:
parent
adeb975890
commit
60989b2e18
1 changed files with 8 additions and 4 deletions
|
|
@ -256,16 +256,20 @@ class MusicusClientDatabase extends _$MusicusClientDatabase {
|
||||||
await transaction(() async {
|
await transaction(() async {
|
||||||
final workId = workInfo.work.id;
|
final workId = workInfo.work.id;
|
||||||
|
|
||||||
// Delete old work data first. The parts, sections and instrumentations
|
// Delete data associated rows in other tables first. We can't just
|
||||||
// will be deleted automatically due to their foreign key constraints.
|
// delete the work itself, because that would violate the foreign key
|
||||||
await deleteWork(workId);
|
// constraints.
|
||||||
|
await (delete(instrumentations)..where((i) => i.work.equals(workId)))
|
||||||
|
.go();
|
||||||
|
await (delete(workParts)..where((p) => p.partOf.equals(workId))).go();
|
||||||
|
await (delete(workSections)..where((s) => s.work.equals(workId))).go();
|
||||||
|
|
||||||
// This will also include the composers of the work's parts.
|
// This will also include the composers of the work's parts.
|
||||||
for (final person in workInfo.composers) {
|
for (final person in workInfo.composers) {
|
||||||
await updatePerson(person);
|
await updatePerson(person);
|
||||||
}
|
}
|
||||||
|
|
||||||
await into(works).insert(workInfo.work);
|
await into(works).insert(workInfo.work, mode: InsertMode.insertOrReplace);
|
||||||
|
|
||||||
// At the moment, this will also update all provided instruments, even if
|
// At the moment, this will also update all provided instruments, even if
|
||||||
// they were already there previously.
|
// they were already there previously.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue