Use composite primary key for DomainHistory (#767)

* Use composite primary key for DomainHistory

* Move History table's SequenceGenerator to orm.xml

* Rebase on HEAD and remove default value for key in History tables

* Use primitive type for id.

* Revert the cache change
This commit is contained in:
Shicong Huang 2020-09-03 10:21:23 -04:00 committed by GitHub
parent b177532d58
commit b34da92f42
10 changed files with 219 additions and 78 deletions

View file

@ -0,0 +1,34 @@
-- 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.
alter sequence "history_id_sequence" increment 50;
alter table "DomainHistory" alter column history_revision_id drop default;
alter table "ContactHistory" alter column history_revision_id drop default;
alter table "HostHistory" alter column history_revision_id drop default;
alter table if exists "DomainHistoryHost"
drop constraint fk6b8eqdxwe3guc56tgpm89atx;
alter table "DomainHistory" drop constraint "DomainHistory_pkey";
alter table "DomainHistory"
add constraint "DomainHistory_pkey" primary key (domain_repo_id, history_revision_id);
alter table "DomainHistoryHost" add column domain_history_domain_repo_id text not null;
alter table if exists "DomainHistoryHost"
add constraint FKa9woh3hu8gx5x0vly6bai327n
foreign key (domain_history_domain_repo_id, domain_history_history_revision_id)
references "DomainHistory";

View file

@ -11,7 +11,7 @@
-- 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 sequence history_id_sequence start 1 increment 1;
create sequence history_id_sequence start 1 increment 50;
create table "AllocationToken" (
token text not null,
@ -286,7 +286,8 @@ create sequence history_id_sequence start 1 increment 1;
);
create table "DomainHistory" (
history_revision_id int8 not null,
domain_repo_id text not null,
history_revision_id int8 not null,
history_by_superuser boolean not null,
history_registrar_id text,
history_modification_time timestamptz not null,
@ -341,12 +342,12 @@ create sequence history_id_sequence start 1 increment 1;
last_epp_update_time timestamptz,
statuses text[],
update_timestamp timestamptz,
domain_repo_id text not null,
primary key (history_revision_id)
primary key (domain_repo_id, history_revision_id)
);
create table "DomainHistoryHost" (
domain_history_history_revision_id int8 not null,
domain_history_domain_repo_id text not null,
domain_history_history_revision_id int8 not null,
host_repo_id text
);
@ -644,8 +645,8 @@ create index spec11threatmatch_check_date_idx on "Spec11ThreatMatch" (check_date
references "ClaimsList";
alter table if exists "DomainHistoryHost"
add constraint FK378h8v3j8qd8xtjn2e0bcmrtj
foreign key (domain_history_history_revision_id)
add constraint FKa9woh3hu8gx5x0vly6bai327n
foreign key (domain_history_domain_repo_id, domain_history_history_revision_id)
references "DomainHistory";
alter table if exists "DomainHost"

View file

@ -275,24 +275,12 @@ CREATE TABLE public."Contact" (
);
--
-- Name: history_id_sequence; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.history_id_sequence
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: ContactHistory; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."ContactHistory" (
history_revision_id bigint DEFAULT nextval('public.history_id_sequence'::regclass) NOT NULL,
history_revision_id bigint NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text,
history_modification_time timestamp with time zone NOT NULL,
@ -431,7 +419,7 @@ CREATE TABLE public."Domain" (
--
CREATE TABLE public."DomainHistory" (
history_revision_id bigint DEFAULT nextval('public.history_id_sequence'::regclass) NOT NULL,
history_revision_id bigint NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text,
history_modification_time timestamp with time zone NOT NULL,
@ -496,7 +484,8 @@ CREATE TABLE public."DomainHistory" (
CREATE TABLE public."DomainHistoryHost" (
domain_history_history_revision_id bigint NOT NULL,
host_repo_id text
host_repo_id text,
domain_history_domain_repo_id text NOT NULL
);
@ -549,7 +538,7 @@ ALTER SEQUENCE public."GracePeriod_id_seq" OWNED BY public."GracePeriod".id;
--
CREATE TABLE public."HostHistory" (
history_revision_id bigint DEFAULT nextval('public.history_id_sequence'::regclass) NOT NULL,
history_revision_id bigint NOT NULL,
history_by_superuser boolean NOT NULL,
history_registrar_id text NOT NULL,
history_modification_time timestamp with time zone NOT NULL,
@ -929,6 +918,18 @@ CREATE SEQUENCE public."Transaction_id_seq"
ALTER SEQUENCE public."Transaction_id_seq" OWNED BY public."Transaction".id;
--
-- Name: history_id_sequence; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.history_id_sequence
START WITH 1
INCREMENT BY 50
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: BillingCancellation billing_cancellation_id; Type: DEFAULT; Schema: public; Owner: -
--
@ -1083,7 +1084,7 @@ ALTER TABLE ONLY public."Cursor"
--
ALTER TABLE ONLY public."DomainHistory"
ADD CONSTRAINT "DomainHistory_pkey" PRIMARY KEY (history_revision_id);
ADD CONSTRAINT "DomainHistory_pkey" PRIMARY KEY (domain_repo_id, history_revision_id);
--
@ -1612,14 +1613,6 @@ 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: -
--
@ -1916,6 +1909,14 @@ ALTER TABLE ONLY public."PollMessage"
ADD CONSTRAINT fk_poll_message_transfer_response_losing_registrar_id FOREIGN KEY (transfer_response_losing_registrar_id) REFERENCES public."Registrar"(registrar_id);
--
-- Name: DomainHistoryHost fka9woh3hu8gx5x0vly6bai327n; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."DomainHistoryHost"
ADD CONSTRAINT fka9woh3hu8gx5x0vly6bai327n FOREIGN KEY (domain_history_domain_repo_id, domain_history_history_revision_id) REFERENCES public."DomainHistory"(domain_repo_id, history_revision_id);
--
-- Name: DomainHost fkfmi7bdink53swivs390m2btxg; Type: FK CONSTRAINT; Schema: public; Owner: -
--