Reorganize new schema changes (#1551)

* Reorganize new schema changes

Reorganized new schema changes and make each flyway script update a
single table.

Each flyway script is executed in a single database transaction so that
the script can be rolled back in one shot. It acquires a shared lock on
all tables touched by the script. This is deadlock-prone because in a
busy database, there may be user queries that attempt to lock the same
set of tables, but in different order. By limiting each script to one
table, we avoid the problem.

We should have some a presubmit check to enforce this rule.

All changes have been deployed to Sandbox out-of-band. When doing so,
we changed all CREATE INDEX statements to CREATE INDEX IF NOT EXISTS.

Future deployments should be able to proceed normally.
This commit is contained in:
Weimin Yu
2022-03-09 20:47:24 -05:00
committed by GitHub
parent bd49e8b238
commit 4b1f4f96e3
10 changed files with 106 additions and 39 deletions
@@ -0,0 +1,20 @@
-- 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 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 INDEX IF NOT EXISTS IDX3y3k7m2bkgahm9sixiohgyrga
ON "Domain" (transfer_billing_event_id);
CREATE INDEX IF NOT EXISTS IDXsfci08jgsymxy6ovh4k7r358c
ON "Domain" (billing_recurrence_id);
CREATE INDEX IF NOT EXISTS IDXcju58vqascbpve1t7fem53ctl
ON "Domain" (transfer_billing_recurrence_id);
@@ -1,27 +0,0 @@
-- 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 INDEX IDX3y3k7m2bkgahm9sixiohgyrga ON "Domain" (transfer_billing_event_id);
CREATE INDEX IDXsfci08jgsymxy6ovh4k7r358c ON "Domain" (billing_recurrence_id);
CREATE INDEX IDXcju58vqascbpve1t7fem53ctl ON "Domain" (transfer_billing_recurrence_id);
CREATE INDEX IDXjw3rwtfrexyq53x9vu7qghrdt ON "DomainHost" (host_repo_id);
CREATE INDEX IDXbgssjudpm428mrv0xfpvgifps ON "GracePeriod" (billing_event_id);
CREATE INDEX IDX5u5m6clpk3nktrvtyy5umacb6 ON "GracePeriod" (billing_recurrence_id);
CREATE INDEX IDX6ebt3nwk5ocvnremnhnlkl6ff ON "BillingEvent" (cancellation_matching_billing_recurrence_id);
CREATE INDEX IDX4ytbe5f3b39trsd4okx5ijhs4 ON "BillingCancellation" (billing_event_id);
CREATE INDEX IDXku0fopwyvd57ebo8bf0jg9xo2 ON "BillingCancellation" (billing_recurrence_id);
@@ -0,0 +1,18 @@
-- 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 INDEX IF NOT EXISTS IDX6ebt3nwk5ocvnremnhnlkl6ff
ON "BillingEvent" (cancellation_matching_billing_recurrence_id);
CREATE INDEX IF NOT EXISTS IDXbgfmveqa7e5hn689koikwn70r
ON "BillingEvent" (domain_repo_id);
@@ -12,7 +12,5 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
CREATE INDEX IDXbgfmveqa7e5hn689koikwn70r ON "BillingEvent" (domain_repo_id);
CREATE INDEX IDXoqttafcywwdn41um6kwlt0n8b ON "BillingRecurrence" (domain_repo_id);
CREATE INDEX IDXl8vobbecsd32k4ksavdfx8st6 ON "BillingCancellation" (domain_repo_id);
CREATE INDEX IF NOT EXISTS IDXjw3rwtfrexyq53x9vu7qghrdt
ON "DomainHost" (host_repo_id);
@@ -0,0 +1,18 @@
-- 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 INDEX IF NOT EXISTS IDXbgssjudpm428mrv0xfpvgifps
ON "GracePeriod" (billing_event_id);
CREATE INDEX IF NOT EXISTS IDX5u5m6clpk3nktrvtyy5umacb6
ON "GracePeriod" (billing_recurrence_id);
@@ -0,0 +1,20 @@
-- 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 INDEX IF NOT EXISTS IDX4ytbe5f3b39trsd4okx5ijhs4
ON "BillingCancellation" (billing_event_id);
CREATE INDEX IF NOT EXISTS IDXku0fopwyvd57ebo8bf0jg9xo2
ON "BillingCancellation" (billing_recurrence_id);
CREATE INDEX IF NOT EXISTS IDXl8vobbecsd32k4ksavdfx8st6
ON "BillingCancellation" (domain_repo_id);
@@ -0,0 +1,16 @@
-- 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 INDEX IF NOT EXISTS IDXoqttafcywwdn41um6kwlt0n8b
ON "BillingRecurrence" (domain_repo_id);