\set ON_ERROR_STOP on BEGIN; CREATE SCHEMA IF NOT EXISTS app_migrations; CREATE TABLE IF NOT EXISTS app_migrations.applied (name text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now()); SELECT NOT EXISTS (SELECT 1 FROM app_migrations.applied WHERE name = '20260930000000_simulation_runs') AS needs_migration \gset \if :needs_migration \ir /app-migrations/20260930000000_simulation_runs.sql GRANT USAGE ON SCHEMA public TO authenticated; GRANT SELECT, INSERT, DELETE ON public.simulation_runs TO authenticated; INSERT INTO app_migrations.applied(name) VALUES ('20260930000000_simulation_runs'); \endif NOTIFY pgrst, 'reload schema'; COMMIT;