Create a Java entity to store ThreatMatch objects in SQL (#617)

* Squash everything together
Create SafeBrowsing_Threats table

Create LocalDateConverter and add indexes to SafeBrowsingThreats

Add indexes to SafeBrowsingThreats and make small style changes

Pass in DateTimeFormatter

Delete LocalDateConverterTest.java

Rebase

Make changes to ThreatType comments

Create LocalDateConverterTest

Add review changes

Add SafeBrowsingThreatTest

Rename repoId, refactor LocalDateConverterTest/SafeBrowsingThreatTest, add foreign keys

Change imports

Add foreign keys and rename version number

Add new generated db-schema file

Clean up null test cases

Add changes

Add foreign keys into SafeBrowsingThreatTeat and apply style checks

Add SafeBrowsingThreatTest into SqlIntegrationTestSuite and change golden file

Make small changes to SafeBrowsingThreatTest

Add tests for ForeignKeyViolations and remove setId in SafeBrowsingThreat

* Change V35 -> V36

* Add a foreign key test for a reference to Registrar

* Move some variables around
This commit is contained in:
Legina Chen 2020-06-22 12:07:59 -07:00 committed by GitHub
parent 2c243a7d5f
commit ec09226baa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 588 additions and 2 deletions

View file

@ -0,0 +1,38 @@
-- 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 "SafeBrowsingThreat" (
id bigserial not null,
check_date text not null,
domain_name text not null,
domain_repo_id text not null,
registrar_id text not null,
threat_type text not null,
tld text not null,
primary key (id)
);
create index safebrowsing_threat_registrar_id_idx on "SafeBrowsingThreat" (registrar_id);
create index safebrowsing_threat_tld_idx on "SafeBrowsingThreat" (tld);
create index safebrowsing_threat_check_date_idx on "SafeBrowsingThreat" (check_date);
alter table if exists "SafeBrowsingThreat"
add constraint fk_safebrowsing_threat_registrar_id
foreign key (registrar_id)
references "Registrar";
alter table if exists "SafeBrowsingThreat"
add constraint fk_safebrowsing_threat_domain_repo_id
foreign key (domain_repo_id)
references "Domain";

View file

@ -407,6 +407,17 @@ create sequence history_id_sequence start 1 increment 1;
should_publish boolean not null,
primary key (revision_id)
);
create table "SafeBrowsingThreat" (
id bigserial not null,
check_date text not null,
domain_name text not null,
domain_repo_id text not null,
registrar_id text not null,
threat_type text not null,
tld text not null,
primary key (id)
);
create index IDXih4b2tea127p5rb61gje6e1y2 on "BillingCancellation" (registrar_id);
create index IDX2exdfbx6oiiwnhr8j6gjpqt2j on "BillingCancellation" (event_time);
create index IDXqa3g92jc17e8dtiaviy4fet4x on "BillingCancellation" (billing_time);
@ -448,6 +459,9 @@ create index idx_registry_lock_registrar_id on "RegistryLock" (registrar_id);
alter table if exists "RegistryLock"
add constraint idx_registry_lock_repo_id_revision_id unique (repo_id, revision_id);
create index reservedlist_name_idx on "ReservedList" (name);
create index safebrowsing_threat_registrar_id_idx on "SafeBrowsingThreat" (registrar_id);
create index safebrowsing_threat_tld_idx on "SafeBrowsingThreat" (tld);
create index safebrowsing_threat_check_date_idx on "SafeBrowsingThreat" (check_date);
alter table if exists "ClaimsEntry"
add constraint FK6sc6at5hedffc0nhdcab6ivuq

View file

@ -656,6 +656,40 @@ CREATE SEQUENCE public."ReservedList_revision_id_seq"
ALTER SEQUENCE public."ReservedList_revision_id_seq" OWNED BY public."ReservedList".revision_id;
--
-- Name: SafeBrowsingThreat; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."SafeBrowsingThreat" (
id bigint NOT NULL,
check_date text NOT NULL,
domain_name text NOT NULL,
domain_repo_id text NOT NULL,
registrar_id text NOT NULL,
threat_type text NOT NULL,
tld text NOT NULL
);
--
-- Name: SafeBrowsingThreat_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public."SafeBrowsingThreat_id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: SafeBrowsingThreat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public."SafeBrowsingThreat_id_seq" OWNED BY public."SafeBrowsingThreat".id;
--
-- Name: BillingCancellation billing_cancellation_id; Type: DEFAULT; Schema: public; Owner: -
--
@ -712,6 +746,13 @@ ALTER TABLE ONLY public."RegistryLock" ALTER COLUMN revision_id SET DEFAULT next
ALTER TABLE ONLY public."ReservedList" ALTER COLUMN revision_id SET DEFAULT nextval('public."ReservedList_revision_id_seq"'::regclass);
--
-- Name: SafeBrowsingThreat id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat" ALTER COLUMN id SET DEFAULT nextval('public."SafeBrowsingThreat_id_seq"'::regclass);
--
-- Name: BillingCancellation BillingCancellation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -864,6 +905,14 @@ ALTER TABLE ONLY public."ReservedList"
ADD CONSTRAINT "ReservedList_pkey" PRIMARY KEY (revision_id);
--
-- Name: SafeBrowsingThreat SafeBrowsingThreat_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat"
ADD CONSTRAINT "SafeBrowsingThreat_pkey" PRIMARY KEY (id);
--
-- Name: RegistryLock idx_registry_lock_repo_id_revision_id; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -1125,6 +1174,27 @@ CREATE INDEX registrarpoc_gae_user_id_idx ON public."RegistrarPoc" USING btree (
CREATE INDEX reservedlist_name_idx ON public."ReservedList" USING btree (name);
--
-- Name: safebrowsing_threat_check_date_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX safebrowsing_threat_check_date_idx ON public."SafeBrowsingThreat" USING btree (check_date);
--
-- Name: safebrowsing_threat_registrar_id_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX safebrowsing_threat_registrar_id_idx ON public."SafeBrowsingThreat" USING btree (registrar_id);
--
-- Name: safebrowsing_threat_tld_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX safebrowsing_threat_tld_idx ON public."SafeBrowsingThreat" USING btree (tld);
--
-- Name: Contact fk1sfyj7o7954prbn1exk7lpnoe; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -1389,6 +1459,22 @@ 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: SafeBrowsingThreat fk_safebrowsing_threat_domain_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat"
ADD CONSTRAINT fk_safebrowsing_threat_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id);
--
-- Name: SafeBrowsingThreat fk_safebrowsing_threat_registrar_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat"
ADD CONSTRAINT fk_safebrowsing_threat_registrar_id FOREIGN KEY (registrar_id) REFERENCES public."Registrar"(registrar_id);
--
-- Name: DomainHost fkfmi7bdink53swivs390m2btxg; Type: FK CONSTRAINT; Schema: public; Owner: -
--