fix(migrations): re-issue the 12xx label backfill inside an explicit transaction block (#2422)
* fix(migrations): re-issue the 12xx label backfill inside an explicit transaction block 20260908113353 (PR #2419) used a bare LOCK TABLE. The CI replay (psql -f per file) and the Supabase branch runner execute migration statements in autocommit, so Postgres refused it ("LOCK TABLE can only be used in transaction blocks"): pg-real, pg-upgrade and tool-pg went red on main and prod's migration queue stopped at that version, which also blocks 20260908130127 (PR #2420). Prod never recorded 113353, so the file is replaced rather than edited: same statements wrapped in BEGIN/COMMIT (precedent 20260513140000), new version 20260908120449. Applied and pg-tested on staging. Refs #2413 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NXSuVejFCvRDyNXF1otEPd * docs(decisions): migrations wrap transaction-only statements in BEGIN/COMMIT Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NXSuVejFCvRDyNXF1otEPd --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
e85eac317c
commit
5987523a25
@@ -1664,3 +1664,4 @@ One line per decision: `[YYYY-MM-DD] <decision>: <why>`. Appended by agents and
|
||||
[2026-09-08] delete_last_voucher returns a correction's bank anchors (transactions.journal_entry_id and transaction_voucher_links rows) to correction_of_id before the row is deleted (migration 20260908095907). Why: the #2364 skeptic showed that once the junction follows the correction, the two-step undo (delete the correction, then the storno) cascaded the links away and restored an original that explains bank rows nobody points at, so the rows surfaced as bookable again; before, the links had stayed on the original by accident. Chosen over releasing the rows (the restored original would still explain them, same trap) and over a TS pre-step in the DELETE route (not atomic with the RPC's own guards: a refused delete would leave anchors on a reversed entry). A duplicate of a link the original already holds is dropped, not re-pointed (UNIQUE (transaction_id, journal_entry_id)).
|
||||
[2026-09-08] Medelantal anställda (Not 2, ÅRL 5:20 §) gets a whole-number override on arsredovisning_narratives (migration 20260908130127) instead of the free-text note override the support request asked for. Why: the number keeps the statutory sentence and the iXBRL MedelantaletAnstallda fact correct; free text would let a non-compliant note through and could not be tagged. One resolver (lib/salary/medelantal.ts resolveMedelantalAnstallda: override, else FTE average over employees) feeds the K2 and K3 note builders and the iXBRL input, which also reads the previous period's override so the jämförelseår column shows the same figure the previous year's document did. Rejected: rounding 0.5 up globally (silently changes every company's note and does nothing for the 148 of 195 aktiebolag with salary but no employees rows); asking the user to backdate employment_start (fixes one company, misstates the hire date).
|
||||
[2026-09-08] Issue #2413 BAS 2026 kontogrupp 12: kept 1249/1259/1269 in the catalog renamed after their free heads and dropped only 1241/1242/1251/1261, instead of removing all seven retired sub-accounts and moving the asset module's vehicle/computer defaults to BAS 2026 (1226/1224 on 1229): the asset module's DEFAULT_ACCOUNTS_BY_CATEGORY still books vehicles on 1240/1249 and computers on 1250/1259 (31 live assets in prod, guard test requires the triple in BAS_REFERENCE), so dropping the contra accounts would have forced a depreciation-default change into a label fix; that change is the founder's call and lives in #2414. The prod backfill renames only the exact catalog literal next to a free-labelled head, so old-BAS imports (1240 Bilar + 1249 Ack. avskr. bilar) and user renames stay untouched.
|
||||
[2026-09-08] Migration files must carry their own BEGIN/COMMIT when they use transaction-only statements (LOCK TABLE, SET LOCAL, SET CONSTRAINTS): CI replays each file with psql -f in autocommit and the Supabase branch runner does the same on prod, so the bare LOCK TABLE in 20260908113353 (#2413, PR #2419) failed both and stalled prod's migration queue behind it. Prod never recorded the failed version, so the file was deleted and re-issued as 20260908120449 rather than edited in place.
|
||||
|
||||
+9
-2
@@ -26,11 +26,16 @@
|
||||
-- corrects the label the picker handed out before anything was booked on it.
|
||||
-- No row is deleted; bookings key on account_number, never on the label.
|
||||
--
|
||||
-- The migration runs in one transaction (Supabase CLI wraps it). The SHARE
|
||||
-- lock below makes the "no journal lines" check and the rename atomic against
|
||||
-- Explicit transaction block: the CI replay (psql -f per file) and the
|
||||
-- Supabase branch runner both execute statements in autocommit, where a bare
|
||||
-- LOCK TABLE is refused ("can only be used in transaction blocks"); that is
|
||||
-- how 20260908113353 failed on main and blocked the prod queue. The SHARE
|
||||
-- lock makes the "no journal lines" check and the rename atomic against
|
||||
-- concurrent postings: inserts on journal_entry_lines wait the few
|
||||
-- milliseconds this takes, reads are unaffected.
|
||||
|
||||
BEGIN;
|
||||
|
||||
LOCK TABLE public.journal_entry_lines IN SHARE MODE;
|
||||
|
||||
UPDATE public.chart_of_accounts a
|
||||
@@ -95,3 +100,5 @@ UPDATE public.chart_of_accounts a
|
||||
WHERE e.company_id = a.company_id
|
||||
AND l.account_number = a.account_number
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
@@ -5,7 +5,7 @@ import { insertPostedJournalEntry, seedCompany } from '@/tests/pg/fixtures'
|
||||
import { getPool } from '@/tests/pg/setup'
|
||||
|
||||
/**
|
||||
* pg-real coverage for 20260908113353_backfill_bas2026_retired_12xx_labels.sql
|
||||
* pg-real coverage for 20260908120449_backfill_bas2026_retired_12xx_labels.sql
|
||||
* (#2413).
|
||||
*
|
||||
* The backfill renames 1249/1259/1269 only where the chart carries the
|
||||
@@ -22,7 +22,7 @@ import { getPool } from '@/tests/pg/setup'
|
||||
*/
|
||||
|
||||
const BACKFILL_SQL = readFileSync(
|
||||
join(process.cwd(), 'supabase/migrations/20260908113353_backfill_bas2026_retired_12xx_labels.sql'),
|
||||
join(process.cwd(), 'supabase/migrations/20260908120449_backfill_bas2026_retired_12xx_labels.sql'),
|
||||
'utf8',
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user