From 25d418539e851057b3c6908dd4af6cd85e90da96 Mon Sep 17 00:00:00 2001 From: Matthias Hochmeister Date: Mon, 13 Apr 2026 20:15:29 +0200 Subject: [PATCH] fix(migration): make trigger creation idempotent with DROP IF EXISTS Previous failed runs committed the CREATE TABLE/TRIGGER DDL outside a transaction (pool.query BEGIN/ROLLBACK is not connection-pinned), leaving the trigger in place. Re-runs then fail with 'already exists'. Co-Authored-By: Claude Sonnet 4.6 --- .../src/database/migrations/084_persoenliche_ausruestung.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/database/migrations/084_persoenliche_ausruestung.sql b/backend/src/database/migrations/084_persoenliche_ausruestung.sql index a79118b..3206d90 100644 --- a/backend/src/database/migrations/084_persoenliche_ausruestung.sql +++ b/backend/src/database/migrations/084_persoenliche_ausruestung.sql @@ -30,6 +30,9 @@ CREATE INDEX IF NOT EXISTS idx_persoenliche_ausruestung_artikel ON persoenliche_ausruestung(artikel_id); -- Auto-update aktualisiert_am trigger (uses the aktualisiert_am variant from migration 018) +-- DROP first to make this idempotent — previous failed migration runs may have committed the DDL +-- without recording the migration (pool.query BEGIN/ROLLBACK does not guarantee same connection). +DROP TRIGGER IF EXISTS trg_persoenliche_ausruestung_aktualisiert_am ON persoenliche_ausruestung; CREATE TRIGGER trg_persoenliche_ausruestung_aktualisiert_am BEFORE UPDATE ON persoenliche_ausruestung FOR EACH ROW EXECUTE FUNCTION update_aktualisiert_am_column();