diff --git a/db/src/main/resources/sql/er_diagram/brief_er_diagram.html b/db/src/main/resources/sql/er_diagram/brief_er_diagram.html index cb9d64cd0..a17aa9e29 100644 --- a/db/src/main/resources/sql/er_diagram/brief_er_diagram.html +++ b/db/src/main/resources/sql/er_diagram/brief_er_diagram.html @@ -261,11 +261,11 @@ td.section { generated on - 2020-11-24 20:57:00.530791 + 2020-11-30 21:59:21.319302 last flyway file - V79__drop_foreign_keys_on_pollmessage.sql + V80__defer_bill_event_key.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-11-24 20:57:00.530791 + 2020-11-30 21:59:21.319302 diff --git a/db/src/main/resources/sql/er_diagram/full_er_diagram.html b/db/src/main/resources/sql/er_diagram/full_er_diagram.html index 3f12e4c00..235e4219d 100644 --- a/db/src/main/resources/sql/er_diagram/full_er_diagram.html +++ b/db/src/main/resources/sql/er_diagram/full_er_diagram.html @@ -261,11 +261,11 @@ td.section { generated on - 2020-11-24 20:56:58.3401 + 2020-11-30 21:59:18.813825 last flyway file - V79__drop_foreign_keys_on_pollmessage.sql + V80__defer_bill_event_key.sql @@ -274,19 +274,19 @@ td.section { SchemaCrawler_Diagram - + generated by - + SchemaCrawler 16.10.1 - + generated on - - 2020-11-24 20:56:58.3401 + + 2020-11-30 21:59:18.813825 - + allocationtoken_a08ccbef diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt index d895b4b78..806e9fc6e 100644 --- a/db/src/main/resources/sql/flyway.txt +++ b/db/src/main/resources/sql/flyway.txt @@ -77,3 +77,4 @@ V76__change_history_nullability.sql V77__fixes_for_replay.sql V78__add_history_id_for_redemption_history_entry.sql V79__drop_foreign_keys_on_pollmessage.sql +V80__defer_bill_event_key.sql diff --git a/db/src/main/resources/sql/flyway/V80__defer_bill_event_key.sql b/db/src/main/resources/sql/flyway/V80__defer_bill_event_key.sql new file mode 100644 index 000000000..bc5a20277 --- /dev/null +++ b/db/src/main/resources/sql/flyway/V80__defer_bill_event_key.sql @@ -0,0 +1,27 @@ +-- Copyright 2020 The Nomulus Authors. All Rights Reserved. +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- We have to make this foreign key initially deferred even though +-- BillingEvent is saved before Domain (and deleted after). If we don't, it +-- appears that Hibernate can sporadically introduce FK constraint failures +-- when updating a Domain to reference a new BillingEvent and then deleting +-- the old BillingEvent. This may be due to the fact that this FK +-- relationships is not known to hibernate. +ALTER TABLE "Domain" DROP CONSTRAINT fk_domain_transfer_billing_event_id; +ALTER TABLE if exists "Domain" + ADD CONSTRAINT fk_domain_transfer_billing_event_id + FOREIGN KEY (transfer_billing_event_id) + REFERENCES "BillingEvent" + DEFERRABLE INITIALLY DEFERRED; + diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index c77483884..40da09be6 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -2064,7 +2064,7 @@ ALTER TABLE ONLY public."Domain" -- ALTER TABLE ONLY public."Domain" - ADD CONSTRAINT fk_domain_transfer_billing_event_id FOREIGN KEY (transfer_billing_event_id) REFERENCES public."BillingEvent"(billing_event_id); + ADD CONSTRAINT fk_domain_transfer_billing_event_id FOREIGN KEY (transfer_billing_event_id) REFERENCES public."BillingEvent"(billing_event_id) DEFERRABLE INITIALLY DEFERRED; --