chore: ensure default org always exists (#12412)

* chore: ensure default org always exists

First user just joins the org created by the migration
This commit is contained in:
Steven Masley
2024-03-05 14:06:35 -06:00
committed by GitHub
parent bc30c9c013
commit 17c486c5e6
9 changed files with 71 additions and 32 deletions

View File

@ -0,0 +1 @@
-- There is no down. If the org is created, just let it be. Deleting an org feels dangerous in a migration.

View File

@ -0,0 +1,16 @@
-- This ensures a default organization always exists.
INSERT INTO
organizations(id, name, description, created_at, updated_at, is_default)
SELECT
-- Avoid calling it "default" as we are reserving that word as a keyword to fetch
-- the default org regardless of the name.
gen_random_uuid(),
'first-organization',
'Builtin default organization.',
now(),
now(),
true
WHERE
-- Only insert if no organizations exist.
NOT EXISTS (SELECT * FROM organizations);