diff --git a/migrations/000040_app_versions_deferred_constraints.down.sql b/migrations/000040_app_versions_deferred_constraints.down.sql new file mode 100644 index 0000000..5c42182 --- /dev/null +++ b/migrations/000040_app_versions_deferred_constraints.down.sql @@ -0,0 +1,12 @@ +BEGIN; + +SET search_path = public, pg_catalog; + +ALTER TABLE ONLY app_versions + DROP CONSTRAINT IF EXISTS app_versions_app_id_version_order_key; + +ALTER TABLE ONLY app_versions + ADD CONSTRAINT app_versions_app_id_version_order_key + UNIQUE (app_id, version_order); + +COMMIT; diff --git a/migrations/000040_app_versions_deferred_constraints.up.sql b/migrations/000040_app_versions_deferred_constraints.up.sql new file mode 100644 index 0000000..d5a00a9 --- /dev/null +++ b/migrations/000040_app_versions_deferred_constraints.up.sql @@ -0,0 +1,14 @@ +BEGIN; + +SET search_path = public, pg_catalog; + +ALTER TABLE ONLY app_versions + DROP CONSTRAINT IF EXISTS app_versions_app_id_version_order_key; + +-- Make the version_order unique constraint deferrable +-- so that the order can be updated in a transaction. +ALTER TABLE ONLY app_versions + ADD CONSTRAINT app_versions_app_id_version_order_key + UNIQUE (app_id, version_order) DEFERRABLE INITIALLY DEFERRED; + +COMMIT;