Refactor DomainBase into DomainContent and create DomainHistory (#668)

* Refactor DomainBase into DomainContent and create DomainHistory

This is similar to #587 and #634, but for domains.

One caveat is that we refactor some of the Domain* instance methods to
be static so that they can be called either on DomainBase or
DomainContent, returning the appropriate type each time.

Note that we set DomainHistory to use the same revision ID sequence as
HostHistory and ContactHistory.

In addition, we refactor the tests to the History objects a bit to
reduce duplicate code and because we cannot guarantee yet that the
SQL-stored VKeys are symmetrical -- the ofy keys are not persisted at
the moment.

In addition, rename the DomainHost table to the default Domain_nsHosts so that it automatically creates two separate nsHosts tables for us -- one foreign-keyed on the domain repo ID, and one foreign-keyed on the history revision ID

* Use access hackery to allow manual names for nsHosts tables

* Clean up post merge artifacts

* Add unused setters that Hibernate requires

* Fix the tests and semantic merge conflicts

* Change ns_hosts to ns_host everywhere

* Rename ns_host to host_repo_id

* V42 -> V44
This commit is contained in:
gbrodman 2020-08-03 17:36:12 -04:00 committed by GitHub
parent 9304e2f421
commit d8ec6294c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1393 additions and 800 deletions

View file

@ -0,0 +1,102 @@
-- 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.
CREATE TABLE "DomainHistory" (
history_revision_id int8 NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text,
history_modification_time timestamptz NOT NULL,
history_reason text NOT NULL,
history_requested_by_registrar boolean NOT NULL,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text NOT NULL,
history_xml_bytes bytea NOT NULL,
admin_contact text,
auth_info_repo_id text,
auth_info_value text,
billing_recurrence_id int8,
autorenew_poll_message_id int8,
billing_contact text,
deletion_poll_message_id int8,
domain_name text,
idn_table_name text,
last_transfer_time timestamptz,
launch_notice_accepted_time timestamptz,
launch_notice_expiration_time timestamptz,
launch_notice_tcn_id text,
launch_notice_validator_id text,
registrant_contact text,
registration_expiration_time timestamptz,
smd_id text,
subordinate_hosts text[],
tech_contact text,
tld text,
transfer_billing_cancellation_id int8,
transfer_billing_recurrence_id int8,
transfer_autorenew_poll_message_id int8,
transfer_billing_event_id int8,
transfer_renew_period_unit text,
transfer_renew_period_value int4,
transfer_registration_expiration_time timestamptz,
transfer_gaining_poll_message_id int8,
transfer_losing_poll_message_id int8,
transfer_client_txn_id text,
transfer_server_txn_id text,
transfer_gaining_registrar_id text,
transfer_losing_registrar_id text,
transfer_pending_expiration_time timestamptz,
transfer_request_time timestamptz,
transfer_status text,
creation_registrar_id text NOT NULL,
creation_time timestamptz NOT NULL,
current_sponsor_registrar_id text NOT NULL,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
statuses text[],
update_timestamp timestamptz,
domain_repo_id text NOT NULL,
PRIMARY KEY (history_revision_id)
);
CREATE TABLE "DomainHistoryHost" (
domain_history_history_revision_id int8 NOT NULL,
host_repo_id text
);
ALTER TABLE IF EXISTS "DomainHost" RENAME ns_hosts TO host_repo_id;
CREATE INDEX IDXrh4xmrot9bd63o382ow9ltfig ON "DomainHistory" (creation_time);
CREATE INDEX IDXaro1omfuaxjwmotk3vo00trwm ON "DomainHistory" (history_registrar_id);
CREATE INDEX IDXsu1nam10cjes9keobapn5jvxj ON "DomainHistory" (history_type);
CREATE INDEX IDX6w3qbtgce93cal2orjg1tw7b7 ON "DomainHistory" (history_modification_time);
ALTER TABLE IF EXISTS "DomainHistory"
ADD CONSTRAINT fk_domain_history_registrar_id
FOREIGN KEY (history_registrar_id)
REFERENCES "Registrar";
ALTER TABLE IF EXISTS "DomainHistory"
ADD CONSTRAINT fk_domain_history_domain_repo_id
FOREIGN KEY (domain_repo_id)
REFERENCES "Domain";
ALTER TABLE ONLY public."DomainHistory" ALTER COLUMN history_revision_id
SET DEFAULT nextval('public."history_id_sequence"'::regclass);
ALTER TABLE IF EXISTS "DomainHistoryHost"
ADD CONSTRAINT FK6b8eqdxwe3guc56tgpm89atx
FOREIGN KEY (domain_history_history_revision_id)
REFERENCES "DomainHistory";

View file

@ -268,9 +268,73 @@ create sequence history_id_sequence start 1 increment 1;
primary key (repo_id)
);
create table "DomainHistory" (
history_revision_id int8 not null,
history_by_superuser boolean not null,
history_registrar_id text,
history_modification_time timestamptz not null,
history_reason text not null,
history_requested_by_registrar boolean not null,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text not null,
history_xml_bytes bytea not null,
admin_contact text,
auth_info_repo_id text,
auth_info_value text,
billing_recurrence_id int8,
autorenew_poll_message_id int8,
billing_contact text,
deletion_poll_message_id int8,
domain_name text,
idn_table_name text,
last_transfer_time timestamptz,
launch_notice_accepted_time timestamptz,
launch_notice_expiration_time timestamptz,
launch_notice_tcn_id text,
launch_notice_validator_id text,
registrant_contact text,
registration_expiration_time timestamptz,
smd_id text,
subordinate_hosts text[],
tech_contact text,
tld text,
transfer_billing_cancellation_id int8,
transfer_billing_recurrence_id int8,
transfer_autorenew_poll_message_id int8,
transfer_billing_event_id int8,
transfer_renew_period_unit text,
transfer_renew_period_value int4,
transfer_registration_expiration_time timestamptz,
transfer_gaining_poll_message_id int8,
transfer_losing_poll_message_id int8,
transfer_client_txn_id text,
transfer_server_txn_id text,
transfer_gaining_registrar_id text,
transfer_losing_registrar_id text,
transfer_pending_expiration_time timestamptz,
transfer_request_time timestamptz,
transfer_status text,
creation_registrar_id text not null,
creation_time timestamptz not null,
current_sponsor_registrar_id text not null,
deletion_time timestamptz,
last_epp_update_registrar_id text,
last_epp_update_time timestamptz,
statuses text[],
update_timestamp timestamptz,
domain_repo_id text not null,
primary key (history_revision_id)
);
create table "DomainHistoryHost" (
domain_history_history_revision_id int8 not null,
host_repo_id text
);
create table "DomainHost" (
domain_repo_id text not null,
ns_hosts text
host_repo_id text
);
create table "GracePeriod" (
@ -528,6 +592,10 @@ create index IDXhsjqiy2lyobfymplb28nm74lm on "Domain" (current_sponsor_registrar
create index IDX5mnf0wn20tno4b9do88j61klr on "Domain" (deletion_time);
create index IDXc5aw4pk1vkd6ymhvkpanmoadv on "Domain" (domain_name);
create index IDXrwl38wwkli1j7gkvtywi9jokq on "Domain" (tld);
create index IDXrh4xmrot9bd63o382ow9ltfig on "DomainHistory" (creation_time);
create index IDXaro1omfuaxjwmotk3vo00trwm on "DomainHistory" (history_registrar_id);
create index IDXsu1nam10cjes9keobapn5jvxj on "DomainHistory" (history_type);
create index IDX6w3qbtgce93cal2orjg1tw7b7 on "DomainHistory" (history_modification_time);
create index IDXfg2nnjlujxo6cb9fha971bq2n on "HostHistory" (creation_time);
create index IDX1iy7njgb7wjmj9piml4l2g0qi on "HostHistory" (history_registrar_id);
create index IDXkkwbwcwvrdkkqothkiye4jiff on "HostHistory" (host_name);
@ -554,6 +622,11 @@ create index spec11threatmatch_check_date_idx on "Spec11ThreatMatch" (check_date
foreign key (revision_id)
references "ClaimsList";
alter table if exists "DomainHistoryHost"
add constraint FK378h8v3j8qd8xtjn2e0bcmrtj
foreign key (domain_history_history_revision_id)
references "DomainHistory";
alter table if exists "DomainHost"
add constraint FKeq1guccbre1yk3oosgp2io554
foreign key (domain_repo_id)

View file

@ -405,13 +405,86 @@ CREATE TABLE public."Domain" (
);
--
-- Name: DomainHistory; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."DomainHistory" (
history_revision_id bigint DEFAULT nextval('public.history_id_sequence'::regclass) NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text,
history_modification_time timestamp with time zone NOT NULL,
history_reason text NOT NULL,
history_requested_by_registrar boolean NOT NULL,
history_client_transaction_id text,
history_server_transaction_id text,
history_type text NOT NULL,
history_xml_bytes bytea NOT NULL,
admin_contact text,
auth_info_repo_id text,
auth_info_value text,
billing_recurrence_id bigint,
autorenew_poll_message_id bigint,
billing_contact text,
deletion_poll_message_id bigint,
domain_name text,
idn_table_name text,
last_transfer_time timestamp with time zone,
launch_notice_accepted_time timestamp with time zone,
launch_notice_expiration_time timestamp with time zone,
launch_notice_tcn_id text,
launch_notice_validator_id text,
registrant_contact text,
registration_expiration_time timestamp with time zone,
smd_id text,
subordinate_hosts text[],
tech_contact text,
tld text,
transfer_billing_cancellation_id bigint,
transfer_billing_recurrence_id bigint,
transfer_autorenew_poll_message_id bigint,
transfer_billing_event_id bigint,
transfer_renew_period_unit text,
transfer_renew_period_value integer,
transfer_registration_expiration_time timestamp with time zone,
transfer_gaining_poll_message_id bigint,
transfer_losing_poll_message_id bigint,
transfer_client_txn_id text,
transfer_server_txn_id text,
transfer_gaining_registrar_id text,
transfer_losing_registrar_id text,
transfer_pending_expiration_time timestamp with time zone,
transfer_request_time timestamp with time zone,
transfer_status text,
creation_registrar_id text NOT NULL,
creation_time timestamp with time zone NOT NULL,
current_sponsor_registrar_id text NOT NULL,
deletion_time timestamp with time zone,
last_epp_update_registrar_id text,
last_epp_update_time timestamp with time zone,
statuses text[],
update_timestamp timestamp with time zone,
domain_repo_id text NOT NULL
);
--
-- Name: DomainHistoryHost; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."DomainHistoryHost" (
domain_history_history_revision_id bigint NOT NULL,
host_repo_id text
);
--
-- Name: DomainHost; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."DomainHost" (
domain_repo_id text NOT NULL,
ns_hosts text
host_repo_id text
);
@ -933,6 +1006,14 @@ ALTER TABLE ONLY public."Cursor"
ADD CONSTRAINT "Cursor_pkey" PRIMARY KEY (scope, type);
--
-- Name: DomainHistory DomainHistory_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainHistory"
ADD CONSTRAINT "DomainHistory_pkey" PRIMARY KEY (history_revision_id);
--
-- Name: Domain Domain_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -1131,6 +1212,13 @@ CREATE INDEX idx6py6ocrab0ivr76srcd2okpnq ON public."BillingEvent" USING btree (
CREATE INDEX idx6syykou4nkc7hqa5p8r92cpch ON public."BillingRecurrence" USING btree (event_time);
--
-- Name: idx6w3qbtgce93cal2orjg1tw7b7; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx6w3qbtgce93cal2orjg1tw7b7 ON public."DomainHistory" USING btree (history_modification_time);
--
-- Name: idx73l103vc5900ig3p4odf0cngt; Type: INDEX; Schema: public; Owner: -
--
@ -1166,6 +1254,13 @@ CREATE INDEX idx_registry_lock_registrar_id ON public."RegistryLock" USING btree
CREATE INDEX idx_registry_lock_verification_code ON public."RegistryLock" USING btree (verification_code);
--
-- Name: idxaro1omfuaxjwmotk3vo00trwm; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idxaro1omfuaxjwmotk3vo00trwm ON public."DomainHistory" USING btree (history_registrar_id);
--
-- Name: idxaydgox62uno9qx8cjlj5lauye; Type: INDEX; Schema: public; Owner: -
--
@ -1285,6 +1380,13 @@ CREATE INDEX idxplxf9v56p0wg8ws6qsvd082hk ON public."BillingEvent" USING btree (
CREATE INDEX idxqa3g92jc17e8dtiaviy4fet4x ON public."BillingCancellation" USING btree (billing_time);
--
-- Name: idxrh4xmrot9bd63o382ow9ltfig; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idxrh4xmrot9bd63o382ow9ltfig ON public."DomainHistory" USING btree (creation_time);
--
-- Name: idxrwl38wwkli1j7gkvtywi9jokq; Type: INDEX; Schema: public; Owner: -
--
@ -1292,6 +1394,13 @@ CREATE INDEX idxqa3g92jc17e8dtiaviy4fet4x ON public."BillingCancellation" USING
CREATE INDEX idxrwl38wwkli1j7gkvtywi9jokq ON public."Domain" USING btree (tld);
--
-- Name: idxsu1nam10cjes9keobapn5jvxj; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idxsu1nam10cjes9keobapn5jvxj ON public."DomainHistory" USING btree (history_type);
--
-- Name: idxsudwswtwqnfnx2o1hx4s0k0g5; Type: INDEX; Schema: public; Owner: -
--
@ -1395,6 +1504,14 @@ ALTER TABLE ONLY public."HostHistory"
ADD CONSTRAINT fk3d09knnmxrt6iniwnp8j2ykga FOREIGN KEY (history_registrar_id) REFERENCES public."Registrar"(registrar_id);
--
-- Name: DomainHistoryHost fk6b8eqdxwe3guc56tgpm89atx; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainHistoryHost"
ADD CONSTRAINT fk6b8eqdxwe3guc56tgpm89atx FOREIGN KEY (domain_history_history_revision_id) REFERENCES public."DomainHistory"(history_revision_id);
--
-- Name: ClaimsEntry fk6sc6at5hedffc0nhdcab6ivuq; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -1531,6 +1648,22 @@ ALTER TABLE ONLY public."Domain"
ADD CONSTRAINT fk_domain_deletion_poll_message_id FOREIGN KEY (deletion_poll_message_id) REFERENCES public."PollMessage"(poll_message_id);
--
-- Name: DomainHistory fk_domain_history_domain_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainHistory"
ADD CONSTRAINT fk_domain_history_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id);
--
-- Name: DomainHistory fk_domain_history_registrar_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainHistory"
ADD CONSTRAINT fk_domain_history_registrar_id FOREIGN KEY (history_registrar_id) REFERENCES public."Registrar"(registrar_id);
--
-- Name: Domain fk_domain_registrant_contact; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -1592,7 +1725,7 @@ ALTER TABLE ONLY public."Domain"
--
ALTER TABLE ONLY public."DomainHost"
ADD CONSTRAINT fk_domainhost_host_valid FOREIGN KEY (ns_hosts) REFERENCES public."HostResource"(repo_id);
ADD CONSTRAINT fk_domainhost_host_valid FOREIGN KEY (host_repo_id) REFERENCES public."HostResource"(repo_id);
--