Correctly restore composite VKeys in DomainContent (#825)

* Restore composite vkeys in DomainContent

PollMessage/BillingEvent vkeys in DomainContent must have their ofy keys
restored from other fields in DomainContent (namely the repo id and their
specific history event ids).

Add PostLoad methods to DomainContent and DomainHistory to do the restoration.

* Fixes for review.

* Deal with foreign-key cycles
This commit is contained in:
Michael Muller 2020-10-07 12:42:01 -04:00 committed by GitHub
parent 96e9c1e0af
commit 151a2afb14
10 changed files with 343 additions and 5 deletions

View file

@ -58,3 +58,4 @@ V57__history_null_content.sql
V58__drop_default_value_and_sequences_for_billing_event.sql
V59__use_composite_primary_key_for_contact_and_host_history_table.sql
V60__remove_pollmessage_sequence.sql
V61__domain_hist_columns.sql

View file

@ -0,0 +1,39 @@
-- 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.
-- These history ids are technically foreign keys, we don't want to constrain
-- them because they're temporary and we don't need to because they are
-- already indirectly constrained by the relationships with the
-- PollMessages/BillingEvents involved.
ALTER TABLE "Domain" ADD COLUMN billing_recurrence_history_id int8;
ALTER TABLE "Domain" ADD COLUMN autorenew_poll_message_history_id int8;
ALTER TABLE "Domain" ADD COLUMN deletion_poll_message_history_id int8;
ALTER TABLE "DomainHistory" ADD COLUMN billing_recurrence_history_id int8;
ALTER TABLE "DomainHistory" ADD COLUMN autorenew_poll_message_history_id int8;
ALTER TABLE "DomainHistory" ADD COLUMN deletion_poll_message_history_id int8;
-- Drop and re-add DomainHistory's Domain FK constraint to make it deferrable,
-- this breaks a cycle with Domain -> PollMessage|BillingEvent -> History.
ALTER TABLE "DomainHistory" DROP CONSTRAINT fk_domain_history_domain_repo_id;
ALTER TABLE "DomainHistory"
ADD CONSTRAINT fk_domain_history_domain_repo_id
FOREIGN KEY (domain_repo_id) REFERENCES "Domain"(repo_id)
DEFERRABLE INITIALLY DEFERRED;
-- Same for PollMessage -> Domain, breaking Domain -> PollMessage -> Domain.
ALTER TABLE "PollMessage" DROP CONSTRAINT fk_poll_message_domain_repo_id;
ALTER TABLE "PollMessage"
ADD CONSTRAINT fk_poll_message_domain_repo_id
FOREIGN KEY (domain_repo_id) REFERENCES "Domain"(repo_id)
DEFERRABLE INITIALLY DEFERRED;

View file

@ -249,10 +249,13 @@ create sequence temp_history_id_sequence start 1 increment 50;
auth_info_repo_id text,
auth_info_value text,
billing_recurrence_id int8,
billing_recurrence_history_id int8,
autorenew_end_time timestamptz,
autorenew_poll_message_id int8,
autorenew_poll_message_history_id int8,
billing_contact text,
deletion_poll_message_id int8,
deletion_poll_message_history_id int8,
domain_name text,
idn_table_name text,
last_transfer_time timestamptz,
@ -301,10 +304,13 @@ create sequence temp_history_id_sequence start 1 increment 50;
auth_info_repo_id text,
auth_info_value text,
billing_recurrence_id int8,
billing_recurrence_history_id int8,
autorenew_end_time timestamptz,
autorenew_poll_message_id int8,
autorenew_poll_message_history_id int8,
billing_contact text,
deletion_poll_message_id int8,
deletion_poll_message_history_id int8,
domain_name text,
idn_table_name text,
last_transfer_time timestamptz,

View file

@ -353,7 +353,10 @@ CREATE TABLE public."Domain" (
billing_recurrence_id bigint,
autorenew_poll_message_id bigint,
deletion_poll_message_id bigint,
autorenew_end_time timestamp with time zone
autorenew_end_time timestamp with time zone,
billing_recurrence_history_id bigint,
autorenew_poll_message_history_id bigint,
deletion_poll_message_history_id bigint
);
@ -420,7 +423,10 @@ CREATE TABLE public."DomainHistory" (
autorenew_end_time timestamp with time zone,
history_other_registrar_id text,
history_period_unit text,
history_period_value integer
history_period_value integer,
billing_recurrence_history_id bigint,
autorenew_poll_message_history_id bigint,
deletion_poll_message_history_id bigint
);
@ -1768,7 +1774,7 @@ ALTER TABLE ONLY public."Domain"
--
ALTER TABLE ONLY public."DomainHistory"
ADD CONSTRAINT fk_domain_history_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id);
ADD CONSTRAINT fk_domain_history_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id) DEFERRABLE INITIALLY DEFERRED;
--
@ -1904,7 +1910,7 @@ ALTER TABLE ONLY public."PollMessage"
--
ALTER TABLE ONLY public."PollMessage"
ADD CONSTRAINT fk_poll_message_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id);
ADD CONSTRAINT fk_poll_message_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id) DEFERRABLE INITIALLY DEFERRED;
--