mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-09 06:32:11 -05:00
To avoid any table locks and contention on the production database we
are going to add the unique index concurrently. This only works if we execute a commit first.
This commit is contained in:
@@ -5,16 +5,28 @@ Revises: 0350_update_rates
|
|||||||
Create Date: 2021-04-12 09:02:45.098875
|
Create Date: 2021-04-12 09:02:45.098875
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
revision = '0351_unique_key_annual_billing'
|
revision = '0351_unique_key_annual_billing'
|
||||||
down_revision = '0350_update_rates'
|
down_revision = '0350_update_rates'
|
||||||
|
|
||||||
|
environment = os.environ['NOTIFY_ENVIRONMENT']
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.create_unique_constraint(
|
index = """
|
||||||
'uix_service_id_financial_year_start', 'annual_billing', ['service_id', 'financial_year_start']
|
CREATE UNIQUE INDEX CONCURRENTLY uix_service_id_financial_year_start
|
||||||
)
|
ON annual_billing (service_id, financial_year_start)
|
||||||
|
"""
|
||||||
|
constraint = """
|
||||||
|
ALTER TABLE annual_BILLING add constraint uix_service_id_financial_year_start
|
||||||
|
UNIQUE USING INDEX uix_service_id_financial_year_start
|
||||||
|
"""
|
||||||
|
op.execute('COMMIT')
|
||||||
|
op.execute(index)
|
||||||
|
op.execute(constraint)
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|||||||
Reference in New Issue
Block a user