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
This commit is contained in:
gbrodman 2022-08-31 16:09:07 -04:00 committed by GitHub
parent 06a1fc0022
commit ddc4a615db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 165 additions and 58 deletions

View file

@ -261,19 +261,19 @@ td.section {
</tr>
<tr>
<td class="property_name">generated on</td>
<td class="property_value">2022-08-20 00:16:00.917251</td>
<td class="property_value">2022-08-30 20:29:57.165769</td>
</tr>
<tr>
<td class="property_name">last flyway file</td>
<td id="lastFlywayFile" class="property_value">V126__drop_autorenew_poll_message_history_id_column_in_domain_table.sql</td>
<td id="lastFlywayFile" class="property_value">V127__fix_user.sql</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<svg viewbox="0.00 0.00 4029.00 3065.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="erDiagram" style="overflow: hidden; width: 100%; height: 800px"><g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 3061)">
<svg viewbox="0.00 0.00 4029.00 3084.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="erDiagram" style="overflow: hidden; width: 100%; height: 800px"><g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 3080.5)">
<title>SchemaCrawler_Diagram</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-3061 4025,-3061 4025,4 -4,4" />
<polygon fill="white" stroke="transparent" points="-4,4 -4,-3080.5 4025,-3080.5 4025,4 -4,4" />
<text text-anchor="start" x="3752.5" y="-29.8" font-family="Helvetica,sans-Serif" font-size="14.00">
generated by
</text>
@ -284,7 +284,7 @@ td.section {
generated on
</text>
<text text-anchor="start" x="3835.5" y="-10.8" font-family="Helvetica,sans-Serif" font-size="14.00">
2022-08-20 00:16:00.917251
2022-08-30 20:29:57.165769
</text>
<polygon fill="none" stroke="#888888" points="3748,-4 3748,-44 4013,-44 4013,-4 3748,-4" /> <!-- allocationtoken_a08ccbef -->
<g id="node1" class="node">
@ -3164,39 +3164,44 @@ td.section {
</g> <!-- user_f2216f01 -->
<g id="node39" class="node">
<title>user_f2216f01</title>
<polygon fill="#ebcef2" stroke="transparent" points="3738.5,-3033 3738.5,-3052 3839.5,-3052 3839.5,-3033 3738.5,-3033" />
<text text-anchor="start" x="3740.5" y="-3039.8" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
<polygon fill="#ebcef2" stroke="transparent" points="3720.5,-3052 3720.5,-3071 3821.5,-3071 3821.5,-3052 3720.5,-3052" />
<text text-anchor="start" x="3722.5" y="-3058.8" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
public."User"
</text>
<polygon fill="#ebcef2" stroke="transparent" points="3839.5,-3033 3839.5,-3052 3913.5,-3052 3913.5,-3033 3839.5,-3033" />
<text text-anchor="start" x="3874.5" y="-3038.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<polygon fill="#ebcef2" stroke="transparent" points="3821.5,-3052 3821.5,-3071 3931.5,-3071 3931.5,-3052 3821.5,-3052" />
<text text-anchor="start" x="3892.5" y="-3057.8" font-family="Helvetica,sans-Serif" font-size="14.00">
[table]
</text>
<text text-anchor="start" x="3740.5" y="-3020.8" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
<text text-anchor="start" x="3722.5" y="-3039.8" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
id
</text>
<text text-anchor="start" x="3833.5" y="-3019.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3815.5" y="-3038.8" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="3841.5" y="-3019.8" font-family="Helvetica,sans-Serif" font-size="14.00">
int8 not null
<text text-anchor="start" x="3823.5" y="-3038.8" font-family="Helvetica,sans-Serif" font-size="14.00">
bigserial not null
</text>
<text text-anchor="start" x="3740.5" y="-3000.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3815.5" y="-3019.8" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="3823.5" y="-3019.8" font-family="Helvetica,sans-Serif" font-size="14.00">
auto-incremented
</text>
<text text-anchor="start" x="3722.5" y="-3000.8" font-family="Helvetica,sans-Serif" font-size="14.00">
email_address
</text>
<text text-anchor="start" x="3833.5" y="-3000.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3815.5" y="-3000.8" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="3841.5" y="-3000.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3823.5" y="-3000.8" font-family="Helvetica,sans-Serif" font-size="14.00">
text not null
</text>
<text text-anchor="start" x="3740.5" y="-2981.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3722.5" y="-2981.8" font-family="Helvetica,sans-Serif" font-size="14.00">
gaia_id
</text>
<text text-anchor="start" x="3833.5" y="-2981.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3815.5" y="-2981.8" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="3841.5" y="-2981.8" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="3823.5" y="-2981.8" font-family="Helvetica,sans-Serif" font-size="14.00">
text not null
</text>
<polygon fill="none" stroke="#888888" points="3737,-2975 3737,-3053 3914,-3053 3914,-2975 3737,-2975" />
<polygon fill="none" stroke="#888888" points="3719,-2975.5 3719,-3072.5 3932,-3072.5 3932,-2975.5 3719,-2975.5" />
</g>
</g>
</svg>
@ -7011,7 +7016,12 @@ td.section {
<tr>
<td class="spacer"></td>
<td class="minwidth"><b><i>id</i></b></td>
<td class="minwidth">int8 not null</td>
<td class="minwidth">bigserial not null</td>
</tr>
<tr>
<td class="spacer"></td>
<td class="minwidth"></td>
<td class="minwidth">auto-incremented</td>
</tr>
<tr>
<td class="spacer"></td>

View file

@ -261,19 +261,19 @@ td.section {
</tr>
<tr>
<td class="property_name">generated on</td>
<td class="property_value">2022-08-20 00:15:58.476902</td>
<td class="property_value">2022-08-30 20:29:55.057361</td>
</tr>
<tr>
<td class="property_name">last flyway file</td>
<td id="lastFlywayFile" class="property_value">V126__drop_autorenew_poll_message_history_id_column_in_domain_table.sql</td>
<td id="lastFlywayFile" class="property_value">V127__fix_user.sql</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<svg viewbox="0.00 0.00 4713.00 7133.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="erDiagram" style="overflow: hidden; width: 100%; height: 800px"><g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 7129)">
<svg viewbox="0.00 0.00 4713.00 7171.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="erDiagram" style="overflow: hidden; width: 100%; height: 800px"><g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 7167)">
<title>SchemaCrawler_Diagram</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-7129 4709,-7129 4709,4 -4,4" />
<polygon fill="white" stroke="transparent" points="-4,4 -4,-7167 4709,-7167 4709,4 -4,4" />
<text text-anchor="start" x="4436.5" y="-29.8" font-family="Helvetica,sans-Serif" font-size="14.00">
generated by
</text>
@ -284,7 +284,7 @@ td.section {
generated on
</text>
<text text-anchor="start" x="4519.5" y="-10.8" font-family="Helvetica,sans-Serif" font-size="14.00">
2022-08-20 00:15:58.476902
2022-08-30 20:29:55.057361
</text>
<polygon fill="none" stroke="#888888" points="4432,-4 4432,-44 4697,-44 4697,-4 4432,-4" /> <!-- allocationtoken_a08ccbef -->
<g id="node1" class="node">
@ -6484,79 +6484,92 @@ td.section {
</g> <!-- user_f2216f01 -->
<g id="node39" class="node">
<title>user_f2216f01</title>
<polygon fill="#ebcef2" stroke="transparent" points="4323,-7100.5 4323,-7119.5 4513,-7119.5 4513,-7100.5 4323,-7100.5" />
<text text-anchor="start" x="4325" y="-7107.3" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
<polygon fill="#ebcef2" stroke="transparent" points="4318,-7138.5 4318,-7157.5 4508,-7157.5 4508,-7138.5 4318,-7138.5" />
<text text-anchor="start" x="4320" y="-7145.3" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
public."User"
</text>
<polygon fill="#ebcef2" stroke="transparent" points="4513,-7100.5 4513,-7119.5 4613,-7119.5 4613,-7100.5 4513,-7100.5" />
<text text-anchor="start" x="4574" y="-7106.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<polygon fill="#ebcef2" stroke="transparent" points="4508,-7138.5 4508,-7157.5 4618,-7157.5 4618,-7138.5 4508,-7138.5" />
<text text-anchor="start" x="4579" y="-7144.3" font-family="Helvetica,sans-Serif" font-size="14.00">
[table]
</text>
<text text-anchor="start" x="4325" y="-7088.3" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
<text text-anchor="start" x="4320" y="-7126.3" font-family="Helvetica,sans-Serif" font-weight="bold" font-style="italic" font-size="14.00">
id
</text>
<text text-anchor="start" x="4507" y="-7087.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7125.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-7087.3" font-family="Helvetica,sans-Serif" font-size="14.00">
int8 not null
<text text-anchor="start" x="4510" y="-7125.3" font-family="Helvetica,sans-Serif" font-size="14.00">
bigserial not null
</text>
<text text-anchor="start" x="4325" y="-7068.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7106.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4510" y="-7106.3" font-family="Helvetica,sans-Serif" font-size="14.00">
auto-incremented
</text>
<text text-anchor="start" x="4320" y="-7087.3" font-family="Helvetica,sans-Serif" font-size="14.00">
email_address
</text>
<text text-anchor="start" x="4507" y="-7068.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7087.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-7068.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-7087.3" font-family="Helvetica,sans-Serif" font-size="14.00">
text not null
</text>
<text text-anchor="start" x="4325" y="-7049.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4320" y="-7068.3" font-family="Helvetica,sans-Serif" font-size="14.00">
gaia_id
</text>
<text text-anchor="start" x="4507" y="-7049.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7068.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-7049.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-7068.3" font-family="Helvetica,sans-Serif" font-size="14.00">
text not null
</text>
<text text-anchor="start" x="4325" y="-7030.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4320" y="-7049.3" font-family="Helvetica,sans-Serif" font-size="14.00">
registry_lock_password_hash
</text>
<text text-anchor="start" x="4507" y="-7030.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7049.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-7030.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-7049.3" font-family="Helvetica,sans-Serif" font-size="14.00">
text
</text>
<text text-anchor="start" x="4325" y="-7011.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4320" y="-7030.3" font-family="Helvetica,sans-Serif" font-size="14.00">
registry_lock_password_salt
</text>
<text text-anchor="start" x="4507" y="-7011.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7030.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-7011.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-7030.3" font-family="Helvetica,sans-Serif" font-size="14.00">
text
</text>
<text text-anchor="start" x="4325" y="-6992.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4320" y="-7011.3" font-family="Helvetica,sans-Serif" font-size="14.00">
global_role
</text>
<text text-anchor="start" x="4507" y="-6992.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-7011.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-6992.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-7011.3" font-family="Helvetica,sans-Serif" font-size="14.00">
text not null
</text>
<text text-anchor="start" x="4325" y="-6973.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4320" y="-6992.3" font-family="Helvetica,sans-Serif" font-size="14.00">
is_admin
</text>
<text text-anchor="start" x="4507" y="-6973.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-6992.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-6973.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-6992.3" font-family="Helvetica,sans-Serif" font-size="14.00">
bool not null
</text>
<text text-anchor="start" x="4325" y="-6954.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4320" y="-6973.3" font-family="Helvetica,sans-Serif" font-size="14.00">
registrar_roles
</text>
<text text-anchor="start" x="4507" y="-6954.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4502" y="-6973.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4515" y="-6954.3" font-family="Helvetica,sans-Serif" font-size="14.00">
<text text-anchor="start" x="4510" y="-6973.3" font-family="Helvetica,sans-Serif" font-size="14.00">
"hstore" not null
</text>
<polygon fill="none" stroke="#888888" points="4322,-6948 4322,-7121 4614,-7121 4614,-6948 4322,-6948" />
<text text-anchor="start" x="4320" y="-6954.3" font-family="Helvetica,sans-Serif" font-size="14.00">
update_timestamp
</text>
<text text-anchor="start" x="4502" y="-6954.3" font-family="Helvetica,sans-Serif" font-size="14.00">
</text>
<text text-anchor="start" x="4510" y="-6954.3" font-family="Helvetica,sans-Serif" font-size="14.00">
timestamptz
</text>
<polygon fill="none" stroke="#888888" points="4317,-6948 4317,-7159 4619,-7159 4619,-6948 4317,-6948" />
</g>
</g>
</svg>
@ -14224,7 +14237,12 @@ td.section {
<tr>
<td class="spacer"></td>
<td class="minwidth"><b><i>id</i></b></td>
<td class="minwidth">int8 not null</td>
<td class="minwidth">bigserial not null</td>
</tr>
<tr>
<td class="spacer"></td>
<td class="minwidth"></td>
<td class="minwidth">auto-incremented</td>
</tr>
<tr>
<td class="spacer"></td>
@ -14261,6 +14279,11 @@ td.section {
<td class="minwidth">registrar_roles</td>
<td class="minwidth">"hstore" not null</td>
</tr>
<tr>
<td class="spacer"></td>
<td class="minwidth">update_timestamp</td>
<td class="minwidth">timestamptz</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
@ -14300,6 +14323,18 @@ td.section {
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="2" class="name">user_unique_email</td>
<td class="description right">[unique index]</td>
</tr>
<tr>
<td class="spacer"></td>
<td class="minwidth">email_address</td>
<td class="minwidth">ascending</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="2" class="name">user_email_address_idx</td>
<td class="description right">[non-unique index]</td>

View file

@ -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

View file

@ -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);

View file

@ -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: -
--