Skip to content

fix(upsert): rewrite plain INSERT into UNIQUE-keyed tables as ON CONFLICT DO UPDATE#12

Draft
JorisM wants to merge 1 commit into
cgnl:mainfrom
JorisM:fix/upsert-do-update
Draft

fix(upsert): rewrite plain INSERT into UNIQUE-keyed tables as ON CONFLICT DO UPDATE#12
JorisM wants to merge 1 commit into
cgnl:mainfrom
JorisM:fix/upsert-do-update

Conversation

@JorisM

@JorisM JorisM commented May 22, 2026

Copy link
Copy Markdown
Contributor

Draft pending live pilot verification. Plain INSERTs into shim-added UNIQUE-keyed tables (statistics_bandwidth, statistics_media, metadata_item_settings) hit unique_violation on PG and PMS aborts. Extends transform_insert to emit ON CONFLICT DO UPDATE for plain INSERTs whose target table has known conflict columns. DO UPDATE (not DO NOTHING) is intentional — see #3.

Detailed write-up: docs/debug/plex-pg-db-exception-bug-report.md (to be filed alongside).

…LICT DO UPDATE

Plain INSERT into shim-added UNIQUE-keyed tables (statistics_bandwidth,
statistics_media, metadata_item_settings) raises unique_violation on PG;
PMS does not catch and aborts with DB::Exception. Extend transform_insert
to emit ON CONFLICT DO UPDATE for plain INSERTs whose target table has
known conflict columns. DO UPDATE (not DO NOTHING) is intentional so the
trailing RETURNING id clause in cached_write still returns the row id.

Verified via cargo run --example crash_repro and live pilot pod.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant