fix(db): rewrite INSERT OR IGNORE to ON CONFLICT DO NOTHING for PG

SQLite INSERT OR IGNORE syntax not valid in PG. PG adapter now
auto-rewrites to INSERT INTO ... ON CONFLICT DO NOTHING. Fixes
attach layout, label assignments, and join table inserts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mitchell R 2026-05-25 00:12:25 +02:00
parent 649c64728a
commit e3254ed46b
No known key found for this signature in database

View file

@ -27,6 +27,15 @@ export class PgAdapter implements DbAdapter {
}
private rewriteSql(sql: string): string {
// SQLite → PG dialect fixups.
if (/INSERT\s+OR\s+IGNORE/i.test(sql)) {
sql = sql.replace(/INSERT\s+OR\s+IGNORE\s+INTO/gi, "INSERT INTO");
sql = sql.trimEnd().replace(/;?\s*$/, " ON CONFLICT DO NOTHING");
}
if (/INSERT\s+OR\s+REPLACE/i.test(sql)) {
sql = sql.replace(/INSERT\s+OR\s+REPLACE\s+INTO/gi, "INSERT INTO");
}
// `?` → `$1`, `$2`, ... Skips `?` characters inside string literals.
let out = "";
let n = 0;