75 lines
2.0 KiB
Plaintext
75 lines
2.0 KiB
Plaintext
\set ON_ERROR_STOP on
|
|
|
|
BEGIN;
|
|
SET LOCAL lock_timeout = '10s';
|
|
SET LOCAL statement_timeout = '30s';
|
|
|
|
-- All migration runners for this application must use this same lock key.
|
|
SELECT pg_advisory_xact_lock(2026, 2);
|
|
|
|
CREATE TABLE IF NOT EXISTS schema_migrations (
|
|
version BIGINT PRIMARY KEY,
|
|
applied_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
SELECT EXISTS (
|
|
SELECT 1 FROM schema_migrations WHERE version = 1
|
|
) AS initial_applied \gset
|
|
|
|
\if :initial_applied
|
|
\echo 'Migration 000001 already applied; skipping.'
|
|
\else
|
|
\ir 000001_initial.up.sql
|
|
INSERT INTO schema_migrations (version) VALUES (1);
|
|
\echo 'Migration 000001 applied (commit follows).'
|
|
\endif
|
|
|
|
SELECT EXISTS (
|
|
SELECT 1 FROM schema_migrations WHERE version = 2
|
|
) AS message_keys_applied \gset
|
|
|
|
\if :message_keys_applied
|
|
\echo 'Migration 000002 already applied; skipping.'
|
|
\else
|
|
\ir 000002_message_keys.up.sql
|
|
INSERT INTO schema_migrations (version) VALUES (2);
|
|
\endif
|
|
|
|
SELECT EXISTS (
|
|
SELECT 1 FROM schema_migrations WHERE version = 3
|
|
) AS attachments_applied \gset
|
|
|
|
\if :attachments_applied
|
|
\echo 'Migration 000003 already applied; skipping.'
|
|
\else
|
|
\ir 000003_attachments.up.sql
|
|
INSERT INTO schema_migrations (version) VALUES (3);
|
|
\echo 'Migration 000003 applied (commit follows).'
|
|
\endif
|
|
|
|
SELECT EXISTS (
|
|
SELECT 1 FROM schema_migrations WHERE version = 4
|
|
) AS attachment_messages_applied \gset
|
|
|
|
\if :attachment_messages_applied
|
|
\echo 'Migration 000004 already applied; skipping.'
|
|
\else
|
|
\ir 000004_attachment_messages.up.sql
|
|
INSERT INTO schema_migrations (version) VALUES (4);
|
|
\echo 'Migration 000004 applied (commit follows).'
|
|
\endif
|
|
|
|
SELECT EXISTS (
|
|
SELECT 1 FROM schema_migrations WHERE version = 5
|
|
) AS upload_intents_applied \gset
|
|
|
|
\if :upload_intents_applied
|
|
\echo 'Migration 000005 already applied; skipping.'
|
|
\else
|
|
\ir 000005_upload_intents.up.sql
|
|
INSERT INTO schema_migrations (version) VALUES (5);
|
|
\echo 'Migration 000005 applied (commit follows).'
|
|
\endif
|
|
|
|
COMMIT;
|