From ddc4a615dba321819f2cdcfed0f3905ef21e5e3a Mon Sep 17 00:00:00 2001 From: gbrodman Date: Wed, 31 Aug 2022 16:09:07 -0400 Subject: [PATCH] Fix a few DB issues with the User class (#1766) - Create a sequence to generate IDs for the user (this allows us to have Long ID types so that Hibernate can autogenerate IDs) - Add an update timestamp column so we can extend BackupGroupRoot - Add a restriction that there can't be multiple users with the same email address --- .../sql/er_diagram/brief_er_diagram.html | 52 +++++---- .../sql/er_diagram/full_er_diagram.html | 107 ++++++++++++------ db/src/main/resources/sql/flyway.txt | 1 + .../resources/sql/flyway/V127__fix_user.sql | 26 +++++ .../resources/sql/schema/nomulus.golden.sql | 37 +++++- 5 files changed, 165 insertions(+), 58 deletions(-) create mode 100644 db/src/main/resources/sql/flyway/V127__fix_user.sql 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 4bf33d7fc..550d21a9e 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,19 +261,19 @@ td.section { generated on - 2022-08-20 00:16:00.917251 + 2022-08-30 20:29:57.165769 last flyway file - V126__drop_autorenew_poll_message_history_id_column_in_domain_table.sql + V127__fix_user.sql

 

 

- + SchemaCrawler_Diagram - + generated by @@ -284,7 +284,7 @@ td.section { generated on - 2022-08-20 00:16:00.917251 + 2022-08-30 20:29:57.165769 @@ -3164,39 +3164,44 @@ td.section { user_f2216f01 - - + + public."User" - - + + [table] - + id - + - - int8 not null + + bigserial not null - + + + + auto-incremented + + email_address - + - + text not null - + gaia_id - + - + text not null - + @@ -7011,7 +7016,12 @@ td.section {
id - int8 not null + bigserial not null + + + + + auto-incremented 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 265379578..c06c4d31f 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,19 +261,19 @@ td.section { generated on - 2022-08-20 00:15:58.476902 + 2022-08-30 20:29:55.057361 last flyway file - V126__drop_autorenew_poll_message_history_id_column_in_domain_table.sql + V127__fix_user.sql

 

 

- + SchemaCrawler_Diagram - + generated by @@ -284,7 +284,7 @@ td.section { generated on - 2022-08-20 00:15:58.476902 + 2022-08-30 20:29:55.057361 @@ -6484,79 +6484,92 @@ td.section { user_f2216f01 - - + + public."User" - - + + [table] - + id - + - - int8 not null + + bigserial not null - + + + + auto-incremented + + email_address - + - + text not null - + gaia_id - + - + text not null - + registry_lock_password_hash - + - + text - + registry_lock_password_salt - + - + text - + global_role - + - + text not null - + is_admin - + - + bool not null - + registrar_roles - + - + "hstore" not null - + + update_timestamp + + + + + timestamptz + + @@ -14224,7 +14237,12 @@ td.section {
id - int8 not null + bigserial not null + + + + + auto-incremented @@ -14261,6 +14279,11 @@ td.section { registrar_roles "hstore" not null + + + update_timestamp + timestamptz + @@ -14300,6 +14323,18 @@ td.section { + + user_unique_email + [unique index] + + + + email_address + ascending + + + + user_email_address_idx [non-unique index] diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt index b6b4347cd..dab96b9c4 100644 --- a/db/src/main/resources/sql/flyway.txt +++ b/db/src/main/resources/sql/flyway.txt @@ -124,3 +124,4 @@ V123__drop_unused_columns_in_billing_cancellation_table.sql V124__add_console_user.sql V125__create_package_promotion.sql V126__drop_autorenew_poll_message_history_id_column_in_domain_table.sql +V127__fix_user.sql diff --git a/db/src/main/resources/sql/flyway/V127__fix_user.sql b/db/src/main/resources/sql/flyway/V127__fix_user.sql new file mode 100644 index 000000000..e81ee38e2 --- /dev/null +++ b/db/src/main/resources/sql/flyway/V127__fix_user.sql @@ -0,0 +1,26 @@ +-- Copyright 2022 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 SEQUENCE "User_id_seq" + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER SEQUENCE "User_id_seq" OWNED BY "User".id; +ALTER TABLE "User" ALTER COLUMN id SET DEFAULT nextval('"User_id_seq"'::regclass); + +ALTER TABLE "User" ADD COLUMN update_timestamp timestamptz; + +ALTER TABLE "User" ADD CONSTRAINT user_unique_email UNIQUE(email_address); diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index 63cacb079..1d0f5a8b5 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -1066,10 +1066,30 @@ CREATE TABLE public."User" ( registry_lock_password_salt text, global_role text NOT NULL, is_admin boolean NOT NULL, - registrar_roles public.hstore NOT NULL + registrar_roles public.hstore NOT NULL, + update_timestamp timestamp with time zone ); +-- +-- Name: User_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public."User_id_seq" + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: User_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public."User_id_seq" OWNED BY public."User".id; + + -- -- Name: ClaimsList revision_id; Type: DEFAULT; Schema: public; Owner: - -- @@ -1119,6 +1139,13 @@ ALTER TABLE ONLY public."SignedMarkRevocationList" ALTER COLUMN revision_id SET ALTER TABLE ONLY public."Spec11ThreatMatch" ALTER COLUMN id SET DEFAULT nextval('public."SafeBrowsingThreat_id_seq"'::regclass); +-- +-- Name: User id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" ALTER COLUMN id SET DEFAULT nextval('public."User_id_seq"'::regclass); + + -- -- Name: AllocationToken AllocationToken_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -1439,6 +1466,14 @@ ALTER TABLE ONLY public."DomainHistoryHost" ADD CONSTRAINT ukt2e7ae3t8gcsxd13wjx2ka7ij UNIQUE (domain_history_history_revision_id, domain_history_domain_repo_id, host_repo_id); +-- +-- Name: User user_unique_email; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT user_unique_email UNIQUE (email_address); + + -- -- Name: allocation_token_domain_name_idx; Type: INDEX; Schema: public; Owner: - --