27 lines
961 B
PL/PgSQL
27 lines
961 B
PL/PgSQL
\set ON_ERROR_STOP on
|
|
BEGIN;
|
|
SET LOCAL search_path = pg_catalog;
|
|
SET LOCAL statement_timeout = '10s';
|
|
SET LOCAL lock_timeout = '5s';
|
|
SELECT pg_catalog.pg_advisory_xact_lock(71420001);
|
|
SELECT current_setting('server_version_num')::int = 180006 AS supported \gset
|
|
\if :supported
|
|
\else
|
|
\echo 'Unsupported PostgreSQL version; expected 18.6'
|
|
DO $$ BEGIN RAISE EXCEPTION 'unsupported PostgreSQL version'; END $$;
|
|
\endif
|
|
SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname='evolution') AS exists \gset
|
|
\if :exists
|
|
-- Unknown/partial schema fails closed; no IF NOT EXISTS repair of foreign data.
|
|
SELECT count(*) = 1 AND min(version) = 1 AND min(sha256) = :'migration_sha'
|
|
AS compatible FROM evolution.schema_migrations \gset
|
|
\if :compatible
|
|
\else
|
|
\echo 'Unknown or changed migration history'
|
|
DO $$ BEGIN RAISE EXCEPTION 'unknown or changed migration history'; END $$;
|
|
\endif
|
|
\else
|
|
\ir 0001_region_bootstrap.sql
|
|
\endif
|
|
COMMIT;
|