mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
SyncGroupRateMultipliers and SyncGroupRPMOverrides ran three destructive statements in autocommit mode: clear rows missing from the payload, delete all-NULL rows, then upsert the payload. If the upsert failed (deleted user FK, duplicate user_id, transient DB error), the clear and delete had already committed, silently wiping the group's overrides. Wrap each sync in one transaction and dedupe entries by user_id before writing so ON CONFLICT cannot hit the same row twice. Any failure now rolls the whole sync back. Add sqlmock tests covering commit, rollback and dedupe.