steid

@jamesgill /

steid/migrations/20260927100000_create_instance_settings.sql
SQL1.2 KBCode·Blame·History·Raw
1-- Settings that belong to the instance rather than to anything in it.
2--
3-- One row, forever. Steid is single tenant, so "which organisation is the home page"
4-- is a fact about the installation and not about any organisation in it — and a
5-- `home_org_id` column on `orgs` would be null on every row but one, turning a read
6-- into a scan and inviting two rows that claim it.
7--
8-- The single row is the `check (id = 1)`: a second insert fails on the primary key,
9-- and an insert with any other id fails the check. It is seeded here so every caller
10-- can read rather than upsert.
11--
12-- `home_org_id` is nullable and stays nullable. Null means nobody has chosen, and the
13-- root falls back to the sole owner's handle — which is exactly how every instance
14-- behaved before this table existed, so an upgrade changes nothing until someone picks.
15-- `on delete set null` rather than cascade: deleting the home organisation must not
16-- delete the instance's settings, it must leave the instance without a home.
17create table instance_settings (
18 id integer primary key check (id = 1),
19 home_org_id text references orgs (id) on delete set null
20);
21
22insert into instance_settings (id, home_org_id) values (1, null);