docs(hq): comment ON CONFLICT portability quirk in doc series (D12 guardrail)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
feat/client-detail-redesign
Thomas Joise 2 weeks ago
parent 5fc07b97ed
commit 63b0d9932a

@ -8,6 +8,7 @@ export const TYPE_PREFIX: Record<string, string> = {
export function nextDocNo(db: DB, docType: string, fy: string): string {
const prefix = `${TYPE_PREFIX[docType]}/${fy.slice(2)}`
db.prepare(
// Portability quirk: ON CONFLICT upsert is SQLite/Postgres dialect (standard SQL has MERGE).
`INSERT INTO doc_series (doc_type, fy, prefix, next_seq) VALUES (?, ?, ?, 1)
ON CONFLICT (doc_type, fy) DO NOTHING`,
).run(docType, fy, prefix)
@ -21,6 +22,7 @@ export function nextDocNo(db: DB, docType: string, fy: string): string {
export function seedSeries(db: DB, docType: string, fy: string, lastUsedSeq: number): void {
const prefix = `${TYPE_PREFIX[docType]}/${fy.slice(2)}`
db.prepare(
// Portability quirk: ON CONFLICT upsert is SQLite/Postgres dialect (standard SQL has MERGE).
`INSERT INTO doc_series (doc_type, fy, prefix, next_seq) VALUES (?, ?, ?, ?)
ON CONFLICT (doc_type, fy) DO UPDATE SET next_seq = excluded.next_seq`,
).run(docType, fy, prefix, lastUsedSeq + 1)

Loading…
Cancel
Save