From b764c25a63eedfdb80769d15342baaf289fa267b Mon Sep 17 00:00:00 2001 From: Shicong Huang Date: Thu, 14 Jan 2021 13:16:24 -0500 Subject: [PATCH] Restore symmetric VKey referenced by BillingEvent.Cancellation (#928) --- .../registry/model/billing/BillingEvent.java | 14 +- .../model/billing/BillingEventTest.java | 18 +- .../google/registry/model/schema.txt | 4 +- .../sql/er_diagram/brief_er_diagram.html | 6 +- .../sql/er_diagram/full_er_diagram.html | 214 +++++++++++------- db/src/main/resources/sql/flyway.txt | 1 + ...d_vkey_columns_in_billing_cancellation.sql | 22 ++ .../sql/schema/db-schema.sql.generated | 4 + .../resources/sql/schema/nomulus.golden.sql | 6 +- 9 files changed, 181 insertions(+), 108 deletions(-) create mode 100644 db/src/main/resources/sql/flyway/V84__add_vkey_columns_in_billing_cancellation.sql diff --git a/core/src/main/java/google/registry/model/billing/BillingEvent.java b/core/src/main/java/google/registry/model/billing/BillingEvent.java index b09881966..21407f900 100644 --- a/core/src/main/java/google/registry/model/billing/BillingEvent.java +++ b/core/src/main/java/google/registry/model/billing/BillingEvent.java @@ -46,6 +46,8 @@ import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.token.AllocationToken; import google.registry.model.reporting.HistoryEntry; import google.registry.model.transfer.TransferData.TransferServerApproveEntity; +import google.registry.persistence.BillingVKey.BillingEventVKey; +import google.registry.persistence.BillingVKey.BillingRecurrenceVKey; import google.registry.persistence.VKey; import google.registry.persistence.WithLongVKey; import google.registry.schema.replay.DatastoreAndSqlEntity; @@ -572,8 +574,7 @@ public abstract class BillingEvent extends ImmutableObject *

Although the type is {@link Key} the name "ref" is preserved for historical reasons. */ @IgnoreSave(IfNull.class) - @Column(name = "billing_event_id") - VKey refOneTime = null; + BillingEventVKey refOneTime = null; /** * The recurring billing event to cancel, or null for non-autorenew cancellations. @@ -581,15 +582,14 @@ public abstract class BillingEvent extends ImmutableObject *

Although the type is {@link Key} the name "ref" is preserved for historical reasons. */ @IgnoreSave(IfNull.class) - @Column(name = "billing_recurrence_id") - VKey refRecurring = null; + BillingRecurrenceVKey refRecurring = null; public DateTime getBillingTime() { return billingTime; } public VKey getEventKey() { - return firstNonNull(refOneTime, refRecurring); + return firstNonNull(refOneTime, refRecurring).createVKey(); } /** The mapping from billable grace period types to originating billing event reasons. */ @@ -656,12 +656,12 @@ public abstract class BillingEvent extends ImmutableObject } public Builder setOneTimeEventKey(VKey eventKey) { - getInstance().refOneTime = eventKey; + getInstance().refOneTime = BillingEventVKey.create(eventKey); return this; } public Builder setRecurringEventKey(VKey eventKey) { - getInstance().refRecurring = eventKey; + getInstance().refRecurring = BillingRecurrenceVKey.create(eventKey); return this; } diff --git a/core/src/test/java/google/registry/model/billing/BillingEventTest.java b/core/src/test/java/google/registry/model/billing/BillingEventTest.java index d3c5be9d4..36ff24718 100644 --- a/core/src/test/java/google/registry/model/billing/BillingEventTest.java +++ b/core/src/test/java/google/registry/model/billing/BillingEventTest.java @@ -318,13 +318,8 @@ public class BillingEventTest extends EntityTestCase { historyEntry2, "foo.tld"); // Set ID to be the same to ignore for the purposes of comparison. - newCancellation = newCancellation.asBuilder().setId(cancellationOneTime.getId()).build(); - - // TODO(b/168537779): Remove setRecurringEventKey after symmetric VKey can be reconstructed - // correctly. - assertThat(newCancellation) - .isEqualTo( - cancellationOneTime.asBuilder().setOneTimeEventKey(oneTime.createVKey()).build()); + assertThat(newCancellation.asBuilder().setId(cancellationOneTime.getId()).build()) + .isEqualTo(cancellationOneTime); } @TestOfyAndSql @@ -340,13 +335,8 @@ public class BillingEventTest extends EntityTestCase { historyEntry2, "foo.tld"); // Set ID to be the same to ignore for the purposes of comparison. - newCancellation = newCancellation.asBuilder().setId(cancellationRecurring.getId()).build(); - - // TODO(b/168537779): Remove setRecurringEventKey after symmetric VKey can be reconstructed - // correctly. - assertThat(newCancellation) - .isEqualTo( - cancellationRecurring.asBuilder().setRecurringEventKey(recurring.createVKey()).build()); + assertThat(newCancellation.asBuilder().setId(cancellationRecurring.getId()).build()) + .isEqualTo(cancellationRecurring); } @TestOfyAndSql diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt index 41e0f89b3..7cfc32b50 100644 --- a/core/src/test/resources/google/registry/model/schema.txt +++ b/core/src/test/resources/google/registry/model/schema.txt @@ -8,8 +8,8 @@ class google.registry.model.billing.BillingEvent$Cancellation { @Id java.lang.Long id; @Parent com.googlecode.objectify.Key parent; google.registry.model.billing.BillingEvent$Reason reason; - google.registry.persistence.VKey refOneTime; - google.registry.persistence.VKey refRecurring; + google.registry.persistence.BillingVKey$BillingEventVKey refOneTime; + google.registry.persistence.BillingVKey$BillingRecurrenceVKey refRecurring; java.lang.String clientId; java.lang.String targetId; java.util.Set flags; 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 672b07563..35bd2983a 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-12-21 17:41:59.495189 + 2021-01-14 16:15:22.842637 last flyway file - V83__add_indexes_on_domainhost.sql + V84__add_vkey_columns_in_billing_cancellation.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-12-21 17:41:59.495189 + 2021-01-14 16:15:22.842637 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 4072ca681..c8697154c 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-12-21 17:41:57.553769 + 2021-01-14 16:15:20.755734 last flyway file - V83__add_indexes_on_domainhost.sql + V84__add_vkey_columns_in_billing_cancellation.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-12-21 17:41:57.553769 + 2021-01-14 16:15:20.755734 @@ -1585,122 +1585,154 @@ td.section { billingevent_a57d1815:w->registrar_6e1503e3:e - + - - - - + + + + fk_billing_event_registrar_id billingcancellation_6eedf614 - - + + public.BillingCancellation - - + + [table] - + billing_cancellation_id - + - + int8 not null - + registrar_id - + - + text not null - + domain_history_revision_id - + - + int8 not null - + domain_repo_id - + - + text not null - + event_time - + - + timestamptz not null - + flags - + - + _text - + reason - + - + text not null - + domain_name - + - + text not null - + billing_time - + - + timestamptz - + billing_event_id - + - + int8 - + billing_recurrence_id - + - + int8 - + + billing_event_history_id + + + + + int8 + + + billing_event_domain_repo_id + + + + + text + + + billing_recurrence_history_id + + + + + int8 + + + billing_recurrence_domain_repo_id + + + + + text + + billingcancellation_6eedf614:w->billingevent_a57d1815:e - - - + + + @@ -1711,9 +1743,9 @@ td.section { billingcancellation_6eedf614:w->billingrecurrence_5fa2cb01:e - - - + + + @@ -1724,40 +1756,40 @@ td.section { billingcancellation_6eedf614:w->domainhistory_a54cc226:e - - - + + + - + fk_billing_cancellation_domain_history billingcancellation_6eedf614:w->domainhistory_a54cc226:e - - - + + + - + fk_billing_cancellation_domain_history billingcancellation_6eedf614:w->registrar_6e1503e3:e - - - - - - - - + + + + + + + + fk_billing_cancellation_registrar_id @@ -2204,13 +2236,13 @@ td.section { domain_6c51cffa:w->billingcancellation_6eedf614:e - + - - - - + + + + fk_domain_transfer_billing_cancellation_id @@ -4871,14 +4903,14 @@ td.section { domainhistory_a54cc226:w->registrar_6e1503e3:e - - - - - - - - + + + + + + + + fk_domain_history_registrar_id @@ -6543,6 +6575,26 @@ td.section { billing_recurrence_id int8 + + + billing_event_history_id + int8 + + + + billing_event_domain_repo_id + text + + + + billing_recurrence_history_id + int8 + + + + billing_recurrence_domain_repo_id + text + diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt index 5fb661992..72ca9686b 100644 --- a/db/src/main/resources/sql/flyway.txt +++ b/db/src/main/resources/sql/flyway.txt @@ -81,3 +81,4 @@ V80__defer_bill_event_key.sql V81__drop_spec11_fkeys.sql V82__add_columns_to_restore_symmetric_billing_vkey.sql V83__add_indexes_on_domainhost.sql +V84__add_vkey_columns_in_billing_cancellation.sql diff --git a/db/src/main/resources/sql/flyway/V84__add_vkey_columns_in_billing_cancellation.sql b/db/src/main/resources/sql/flyway/V84__add_vkey_columns_in_billing_cancellation.sql new file mode 100644 index 000000000..88bd4308d --- /dev/null +++ b/db/src/main/resources/sql/flyway/V84__add_vkey_columns_in_billing_cancellation.sql @@ -0,0 +1,22 @@ +-- Copyright 2021 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 "BillingCancellation" + add column if not exists "billing_event_history_id" int8; +alter table "BillingCancellation" + add column if not exists "billing_event_domain_repo_id" text; +alter table "BillingCancellation" + add column if not exists "billing_recurrence_history_id" int8; +alter table "BillingCancellation" + add column if not exists "billing_recurrence_domain_repo_id" text; 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 d2f7e642d..d3e8bf2e3 100644 --- a/db/src/main/resources/sql/schema/db-schema.sql.generated +++ b/db/src/main/resources/sql/schema/db-schema.sql.generated @@ -40,7 +40,11 @@ domain_name text not null, billing_time timestamptz, billing_event_id int8, + billing_event_history_id int8, + billing_event_domain_repo_id text, billing_recurrence_id int8, + billing_recurrence_history_id int8, + billing_recurrence_domain_repo_id text, primary key (billing_cancellation_id) ); diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index f80c02c15..5a3854ec7 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -70,7 +70,11 @@ CREATE TABLE public."BillingCancellation" ( domain_name text NOT NULL, billing_time timestamp with time zone, billing_event_id bigint, - billing_recurrence_id bigint + billing_recurrence_id bigint, + billing_event_history_id bigint, + billing_event_domain_repo_id text, + billing_recurrence_history_id bigint, + billing_recurrence_domain_repo_id text );