v1.15: Haus -> Wohneinheiten Struktur in der Verwaltung + Fix Haus-Umbenennung (costs FK ON UPDATE CASCADE)

This commit is contained in:
2026-10-04 12:25:47 +02:00
parent b57e9276f8
commit 189ce10d65
3 changed files with 169 additions and 103 deletions
+11
View File
@@ -153,6 +153,17 @@ CREATE TABLE IF NOT EXISTS costs (
);
CREATE INDEX IF NOT EXISTS idx_costs_building ON costs(building);
CREATE INDEX IF NOT EXISTS idx_costs_unit ON costs(unit_id);
-- FK hausweit: Umbenennung eines Hauses muss costs.building automatisch
-- mitziehen (sonst bricht jede Haus-Umbenennung mit FK-Verletzung ab,
-- sobald Kostenpositionen existieren). Constraint idempotent neu setzen.
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'costs_building_fkey') THEN
ALTER TABLE costs DROP CONSTRAINT costs_building_fkey;
END IF;
ALTER TABLE costs ADD CONSTRAINT costs_building_fkey
FOREIGN KEY (building) REFERENCES buildings(name) ON UPDATE CASCADE;
END $$;
`
async function init() {