From 6401a8198d186fca712a9d71961b07fd3ef855c5 Mon Sep 17 00:00:00 2001 From: mAi Date: Wed, 20 May 2026 09:52:28 +0200 Subject: [PATCH] feat(offices): add Madrid as a firm office (mig 106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m's ask 2026-05-20 09:42. Eighth HLC office alongside Munich, Düsseldorf, Hamburg, Amsterdam, London, Paris, Milan. - `internal/offices/offices.go` — append Madrid to All[] (display order: end of list, after Milan). Doc comment refreshed to point at the actual current CHECK constraints (users mig 002 + partner_units mig 018/024/027), not the obsolete akten reference from before projects-v2. - `internal/offices/offices_test.go` — add `madrid` to the valid-keys table. - mig 106 — extend the two CHECK constraints on users.office and partner_units.office. Idempotent (DROP IF EXISTS), audit_reason set_config at top, dry-run validated against the live youpc paliad schema (BEGIN; ALTER...; ROLLBACK). Frontend picks up Madrid automatically via GET /api/offices. Admin UI for managing firm office list is a separate longer-term issue — m's "for now, just add Madrid already" path. --- .../migrations/106_add_madrid_office.down.sql | 28 +++++++++++++ .../migrations/106_add_madrid_office.up.sql | 42 +++++++++++++++++++ internal/offices/offices.go | 6 ++- internal/offices/offices_test.go | 2 +- 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 internal/db/migrations/106_add_madrid_office.down.sql create mode 100644 internal/db/migrations/106_add_madrid_office.up.sql diff --git a/internal/db/migrations/106_add_madrid_office.down.sql b/internal/db/migrations/106_add_madrid_office.down.sql new file mode 100644 index 0000000..f89e294 --- /dev/null +++ b/internal/db/migrations/106_add_madrid_office.down.sql @@ -0,0 +1,28 @@ +-- Revert mig 106 — drop 'madrid' from the office CHECK constraints. +-- +-- Will fail if any users.office or partner_units.office row carries +-- 'madrid' — that's intentional (the down has no opinion on the data; +-- caller must clean up first or accept the failure). + +SELECT set_config( + 'paliad.audit_reason', + 'mig 106 down: restore pre-madrid office CHECK on users + partner_units', + true); + +ALTER TABLE paliad.users + DROP CONSTRAINT IF EXISTS users_office_check; +ALTER TABLE paliad.users + ADD CONSTRAINT users_office_check + CHECK (office IN ( + 'munich', 'duesseldorf', 'hamburg', + 'amsterdam', 'london', 'paris', 'milan' + )); + +ALTER TABLE paliad.partner_units + DROP CONSTRAINT IF EXISTS partner_units_office_check; +ALTER TABLE paliad.partner_units + ADD CONSTRAINT partner_units_office_check + CHECK (office IN ( + 'munich', 'duesseldorf', 'hamburg', + 'amsterdam', 'london', 'paris', 'milan' + )); diff --git a/internal/db/migrations/106_add_madrid_office.up.sql b/internal/db/migrations/106_add_madrid_office.up.sql new file mode 100644 index 0000000..a2c1f62 --- /dev/null +++ b/internal/db/migrations/106_add_madrid_office.up.sql @@ -0,0 +1,42 @@ +-- mig 106 — add 'madrid' to firm office CHECK constraints +-- +-- m's ask 2026-05-20 09:42: add Madrid as an HLC office, alongside the +-- existing seven (munich, duesseldorf, hamburg, amsterdam, london, +-- paris, milan). Two active CHECK constraints to extend: +-- - paliad.users.office (mig 002) +-- - paliad.partner_units.office (mig 018; renamed mig 024 + mig 027) +-- +-- The Go-side source of truth lives in internal/offices/offices.go; +-- this migration keeps the DB in sync. +-- +-- Long-term, the admin area will let firms manage their own office +-- list (separate issue) — but for now the list is hard-coded here +-- + offices.go. +-- +-- Non-blocking: extending a CHECK constraint is a metadata-only change +-- on a small enum-style column. + +SELECT set_config( + 'paliad.audit_reason', + 'mig 106: add madrid to firm office CHECK on users + partner_units', + true); + +ALTER TABLE paliad.users + DROP CONSTRAINT IF EXISTS users_office_check; +ALTER TABLE paliad.users + ADD CONSTRAINT users_office_check + CHECK (office IN ( + 'munich', 'duesseldorf', 'hamburg', + 'amsterdam', 'london', 'paris', 'milan', + 'madrid' + )); + +ALTER TABLE paliad.partner_units + DROP CONSTRAINT IF EXISTS partner_units_office_check; +ALTER TABLE paliad.partner_units + ADD CONSTRAINT partner_units_office_check + CHECK (office IN ( + 'munich', 'duesseldorf', 'hamburg', + 'amsterdam', 'london', 'paris', 'milan', + 'madrid' + )); diff --git a/internal/offices/offices.go b/internal/offices/offices.go index 03e3e0e..561cc73 100644 --- a/internal/offices/offices.go +++ b/internal/offices/offices.go @@ -1,7 +1,8 @@ // Package offices is the single source of truth for the firm's office list. // -// The keys here must stay in sync with the CHECK constraint on -// paliad.users.office and paliad.akten.owning_office (migration 001). +// The keys here must stay in sync with the CHECK constraints on +// paliad.users.office (mig 002) and paliad.partner_units.office +// (mig 018, renamed mig 024 + mig 027). Madrid added mig 106. package offices // Office is a single firm office with its i18n-ready labels. @@ -20,6 +21,7 @@ var All = []Office{ {Key: "london", LabelDE: "London", LabelEN: "London"}, {Key: "paris", LabelDE: "Paris", LabelEN: "Paris"}, {Key: "milan", LabelDE: "Mailand", LabelEN: "Milan"}, + {Key: "madrid", LabelDE: "Madrid", LabelEN: "Madrid"}, } // IsValid reports whether the given key names a known office. diff --git a/internal/offices/offices_test.go b/internal/offices/offices_test.go index 0af07bb..52c73d8 100644 --- a/internal/offices/offices_test.go +++ b/internal/offices/offices_test.go @@ -3,7 +3,7 @@ package offices import "testing" func TestIsValid(t *testing.T) { - for _, key := range []string{"munich", "duesseldorf", "hamburg", "amsterdam", "london", "paris", "milan"} { + for _, key := range []string{"munich", "duesseldorf", "hamburg", "amsterdam", "london", "paris", "milan", "madrid"} { if !IsValid(key) { t.Errorf("IsValid(%q) = false, want true", key) }