mirror of
https://github.com/block/buzz.git
synced 2026-11-24 02:02:07 +00:00
buzz-db: drop the remaining relay foreign keys (#9740)
This commit is contained in:
30
scripts/drop-partitioned-foreign-keys.sql
Normal file
30
scripts/drop-partitioned-foreign-keys.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- Drop the foreign keys on the partitioned tables before pgschema apply.
|
||||
--
|
||||
-- pgschema cannot drop a foreign key from a partitioned table. Its plan drops
|
||||
-- the parent's constraint, then the copy on each partition, which the first
|
||||
-- drop already removed (SQLSTATE 42704). This file runs migration 0104's drop
|
||||
-- for a database that pgschema brings up to date instead.
|
||||
--
|
||||
-- For the test launchers only: scripts/start-relay-for-tests.sh, which reuses
|
||||
-- its database, and the populated-upgrade test run it before apply.
|
||||
-- Deployments apply migration 0104 instead (docs/database.md, "Retiring a
|
||||
-- trigger, function, or foreign key"). It does nothing on an empty database or
|
||||
-- one without the keys.
|
||||
--
|
||||
-- As in 0104: each drop locks the table, every partition and communities, so
|
||||
-- take every lock in one statement, communities last, with budgets that end
|
||||
-- the attempt before the 1s deadlock_timeout. On failure nothing changes;
|
||||
-- retry.
|
||||
BEGIN;
|
||||
SET LOCAL lock_timeout = '300ms';
|
||||
SET LOCAL statement_timeout = '800ms';
|
||||
DO $$
|
||||
BEGIN
|
||||
IF to_regclass('events') IS NULL THEN
|
||||
RETURN;
|
||||
END IF;
|
||||
LOCK TABLE events, delivery_log, communities IN ACCESS EXCLUSIVE MODE;
|
||||
ALTER TABLE events DROP CONSTRAINT IF EXISTS events_community_id_fkey;
|
||||
ALTER TABLE delivery_log DROP CONSTRAINT IF EXISTS delivery_log_community_id_fkey;
|
||||
END $$;
|
||||
COMMIT;
|
||||
@@ -107,6 +107,9 @@ export PGSCHEMA_PLAN_PASSWORD=buzz_dev
|
||||
# repair existed would fail apply, so repair it first (see the script).
|
||||
docker exec -i -e PGPASSWORD="${PGPASSWORD}" buzz-postgres \
|
||||
psql -U "${PGUSER}" -d "${PGDATABASE}" -v ON_ERROR_STOP=1 < scripts/repair-events-pkey.sql
|
||||
# pgschema cannot drop the partitioned tables' foreign keys (see the script).
|
||||
docker exec -i -e PGPASSWORD="${PGPASSWORD}" buzz-postgres \
|
||||
psql -U "${PGUSER}" -d "${PGDATABASE}" -v ON_ERROR_STOP=1 < scripts/drop-partitioned-foreign-keys.sql
|
||||
./bin/pgschema apply --file schema/schema.sql --auto-approve
|
||||
docker exec -i -e PGPASSWORD="${PGPASSWORD}" buzz-postgres \
|
||||
psql -U "${PGUSER}" -d "${PGDATABASE}" -v ON_ERROR_STOP=1 < scripts/reconcile-schema-after-pgschema.sql
|
||||
|
||||
Reference in New Issue
Block a user