-- Platform database initialisation
-- Runs once on first container boot via docker-entrypoint-initdb.d.
-- Only creates databases that platform infrastructure owns.
--
-- controlplanedb  → ControlPlane bootstraps this itself on first run.
-- giteadb         → Gitea creates this itself via GITEA__database env vars.
-- clarity_{tenant} → Created at provisioning time by ControlPlane.Worker.

SELECT 'CREATE DATABASE keycloakdb' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'keycloakdb')\gexec
SELECT 'CREATE DATABASE giteadb'    WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'giteadb')\gexec
