From 51942fcaad7b7066fb11c6d39c18e96056b2e649 Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Fri, 13 Nov 2020 15:25:54 -0500 Subject: [PATCH] Make some columns nullable in History tables (#873) * Make some columns nullable in History tables xmlBytes is made nullable in all history tables since changes performed by backend actions would not have it. In addition, epp requests are not saved to ContactHistory since data may contain PII. requestedByRegistrar in all history tables are made nullable. This property is set from metadata in epp requests. Null means not provided. --- .../model/reporting/HistoryEntry.java | 10 +++++-- .../sql/er_diagram/brief_er_diagram.html | 6 ++-- .../sql/er_diagram/full_er_diagram.html | 30 +++++++++---------- db/src/main/resources/sql/flyway.txt | 1 + .../V76__change_history_nullability.sql | 25 ++++++++++++++++ .../sql/schema/db-schema.sql.generated | 12 ++++---- .../resources/sql/schema/nomulus.golden.sql | 12 ++++---- 7 files changed, 63 insertions(+), 33 deletions(-) create mode 100644 db/src/main/resources/sql/flyway/V76__change_history_nullability.sql diff --git a/core/src/main/java/google/registry/model/reporting/HistoryEntry.java b/core/src/main/java/google/registry/model/reporting/HistoryEntry.java index f8a95da33..07861ab26 100644 --- a/core/src/main/java/google/registry/model/reporting/HistoryEntry.java +++ b/core/src/main/java/google/registry/model/reporting/HistoryEntry.java @@ -137,8 +137,12 @@ public class HistoryEntry extends ImmutableObject implements Buildable, Datastor @Transient // domain-specific Period period; - /** The actual EPP xml of the command, stored as bytes to be agnostic of encoding. */ - @Column(nullable = false, name = "historyXmlBytes") + /** + * The actual EPP xml of the command, stored as bytes to be agnostic of encoding. + * + *

Changes performed by backend actions would not have EPP requests to store. + */ + @Column(name = "historyXmlBytes") byte[] xmlBytes; /** The time the command occurred, represented by the ofy transaction time. */ @@ -182,7 +186,7 @@ public class HistoryEntry extends ImmutableObject implements Buildable, Datastor String reason; /** Whether this change was requested by a registrar. */ - @Column(nullable = false, name = "historyRequestedByRegistrar") + @Column(name = "historyRequestedByRegistrar") Boolean requestedByRegistrar; /** 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 8ee39313c..5ccee4c97 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,11 +261,11 @@ td.section { generated on - 2020-11-12 02:22:52.212444 + 2020-11-13 19:34:54.398919 last flyway file - V75__add_grace_period_history.sql + V76__change_history_nullability.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-11-12 02:22:52.212444 + 2020-11-13 19:34:54.398919 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 3e63ad727..6b3ada54f 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,11 +261,11 @@ td.section { generated on - 2020-11-12 02:22:50.323783 + 2020-11-13 19:34:52.404634 last flyway file - V75__add_grace_period_history.sql + V76__change_history_nullability.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-11-12 02:22:50.323783 + 2020-11-13 19:34:52.404634 @@ -701,7 +701,7 @@ td.section { - bool not null + bool history_client_transaction_id @@ -733,7 +733,7 @@ td.section { - bytea not null + bytea admin_contact @@ -3789,7 +3789,7 @@ td.section { - bool not null + bool history_client_transaction_id @@ -3821,7 +3821,7 @@ td.section { - bytea not null + bytea auth_info_repo_id @@ -4562,7 +4562,7 @@ td.section { - bool not null + bool history_client_transaction_id @@ -4594,7 +4594,7 @@ td.section { - bytea not null + bytea host_name @@ -7983,7 +7983,7 @@ td.section { history_requested_by_registrar - bool not null + bool @@ -8003,7 +8003,7 @@ td.section { history_xml_bytes - bytea not null + bytea @@ -9425,7 +9425,7 @@ td.section { history_requested_by_registrar - bool not null + bool @@ -9445,7 +9445,7 @@ td.section { history_xml_bytes - bytea not null + bytea @@ -10717,7 +10717,7 @@ td.section { history_requested_by_registrar - bool not null + bool @@ -10737,7 +10737,7 @@ td.section { history_xml_bytes - bytea not null + bytea diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt index c830604b9..ab8ef0821 100644 --- a/db/src/main/resources/sql/flyway.txt +++ b/db/src/main/resources/sql/flyway.txt @@ -73,3 +73,4 @@ V72__add_missing_foreign_keys.sql V73__singleton_entities.sql V74__sql_replay_checkpoint.sql V75__add_grace_period_history.sql +V76__change_history_nullability.sql diff --git a/db/src/main/resources/sql/flyway/V76__change_history_nullability.sql b/db/src/main/resources/sql/flyway/V76__change_history_nullability.sql new file mode 100644 index 000000000..d4d409fbb --- /dev/null +++ b/db/src/main/resources/sql/flyway/V76__change_history_nullability.sql @@ -0,0 +1,25 @@ +-- 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 table "ContactHistory" + ALTER column history_xml_bytes DROP NOT NULL, + ALTER column history_requested_by_registrar DROP NOT NULL; + +ALTER table "DomainHistory" + ALTER column history_xml_bytes DROP NOT NULL, + ALTER column history_requested_by_registrar DROP NOT NULL; + +ALTER table "HostHistory" + ALTER column history_xml_bytes DROP NOT NULL, + ALTER column history_requested_by_registrar DROP NOT NULL; diff --git a/db/src/main/resources/sql/schema/db-schema.sql.generated b/db/src/main/resources/sql/schema/db-schema.sql.generated index df5e373f2..54a316071 100644 --- a/db/src/main/resources/sql/schema/db-schema.sql.generated +++ b/db/src/main/resources/sql/schema/db-schema.sql.generated @@ -156,11 +156,11 @@ history_registrar_id text, history_modification_time timestamptz not null, history_reason text, - history_requested_by_registrar boolean not null, + history_requested_by_registrar boolean, history_client_transaction_id text, history_server_transaction_id text, history_type text not null, - history_xml_bytes bytea not null, + history_xml_bytes bytea, auth_info_repo_id text, auth_info_value text, contact_id text, @@ -309,11 +309,11 @@ history_registrar_id text, history_modification_time timestamptz not null, history_reason text, - history_requested_by_registrar boolean not null, + history_requested_by_registrar boolean, history_client_transaction_id text, history_server_transaction_id text, history_type text not null, - history_xml_bytes bytea not null, + history_xml_bytes bytea, admin_contact text, auth_info_repo_id text, auth_info_value text, @@ -446,11 +446,11 @@ history_registrar_id text, history_modification_time timestamptz not null, history_reason text, - history_requested_by_registrar boolean not null, + history_requested_by_registrar boolean, history_client_transaction_id text, history_server_transaction_id text, history_type text not null, - history_xml_bytes bytea not null, + history_xml_bytes bytea, host_name text, inet_addresses text[], last_superordinate_change timestamptz, diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index 138d476a4..05de4c4d4 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -228,11 +228,11 @@ CREATE TABLE public."ContactHistory" ( history_registrar_id text, history_modification_time timestamp with time zone NOT NULL, history_reason text, - history_requested_by_registrar boolean NOT NULL, + history_requested_by_registrar boolean, history_client_transaction_id text, history_server_transaction_id text, history_type text NOT NULL, - history_xml_bytes bytea NOT NULL, + history_xml_bytes bytea, auth_info_repo_id text, auth_info_value text, contact_id text, @@ -401,11 +401,11 @@ CREATE TABLE public."DomainHistory" ( history_registrar_id text, history_modification_time timestamp with time zone NOT NULL, history_reason text, - history_requested_by_registrar boolean NOT NULL, + history_requested_by_registrar boolean, history_client_transaction_id text, history_server_transaction_id text, history_type text NOT NULL, - history_xml_bytes bytea NOT NULL, + history_xml_bytes bytea, admin_contact text, auth_info_repo_id text, auth_info_value text, @@ -587,11 +587,11 @@ CREATE TABLE public."HostHistory" ( history_registrar_id text NOT NULL, history_modification_time timestamp with time zone NOT NULL, history_reason text, - history_requested_by_registrar boolean NOT NULL, + history_requested_by_registrar boolean, history_client_transaction_id text, history_server_transaction_id text, history_type text NOT NULL, - history_xml_bytes bytea NOT NULL, + history_xml_bytes bytea, host_name text, inet_addresses text[], last_superordinate_change timestamp with time zone,