Update an existing track in place instead of replacing it

Upserting a track for an entry and tracker that already have one updates that row, instead of the table's REPLACE deleting it and inserting a new one under a new id. Anything keyed to the old id, such as a queued tracking update, keeps working. The query, repository methods and interactor are renamed from insert to upsert to say so.
This commit is contained in:
AntsyLich
2026-09-27 23:02:26 +06:00
parent 2b4b8472bb
commit 9a77baedcc
12 changed files with 50 additions and 35 deletions
@@ -40,9 +40,24 @@ SELECT *
FROM manga_sync
WHERE manga_id = :mangaId;
insert:
upsert:
INSERT INTO manga_sync(manga_id,sync_id,remote_id,library_id,title,last_chapter_read,total_chapters,status,score,remote_url,start_date,finish_date,private)
VALUES (:mangaId,:syncId,:remoteId,:libraryId,:title,:lastChapterRead,:totalChapters,:status,:score,:remoteUrl,:startDate,:finishDate,:private);
VALUES (:mangaId,:syncId,:remoteId,:libraryId,:title,:lastChapterRead,:totalChapters,:status,:score,:remoteUrl,:startDate,:finishDate,:private)
ON CONFLICT(manga_id, sync_id)
DO UPDATE
SET
remote_id = :remoteId,
library_id = :libraryId,
title = :title,
last_chapter_read = :lastChapterRead,
total_chapters = :totalChapters,
status = :status,
score = :score,
remote_url = :remoteUrl,
start_date = :startDate,
finish_date = :finishDate,
private = :private
WHERE manga_id = :mangaId AND sync_id = :syncId;
update:
UPDATE manga_sync