Skip to content

Commit

Permalink
make sure that xids_owner_xid_key only gets created if it doesn't exist
Browse files Browse the repository at this point in the history
would lead to errors when running the add_xid_constraint migration on properly set up db; migration should be idempotent
  • Loading branch information
metasoarous committed Aug 24, 2022
1 parent 3466cf2 commit 25b4974
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server/postgres/migrations/000002_add_xid_constraint.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
ALTER TABLE xids
DROP CONSTRAINT IF EXISTS xids_owner_uid_key,
ADD CONSTRAINT xids_owner_xid_key UNIQUE (owner, xid);
DROP CONSTRAINT IF EXISTS xids_owner_uid_key;

DO $$
BEGIN
IF NOT EXISTS ( SELECT constraint_schema
, constraint_name
FROM information_schema.constraint_column_usage
WHERE constraint_name = 'xids_owner_xid_key'
)
THEN
ALTER TABLE xids ADD CONSTRAINT xids_owner_xid_key UNIQUE (owner, xid);
END IF;
END$$;

0 comments on commit 25b4974

Please sign in to comment.