mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Merge pull request #2113 from alphagov/fix-noti-migration
separate notification postage constraint into three separate commits
This commit is contained in:
@@ -1,44 +0,0 @@
|
|||||||
"""
|
|
||||||
|
|
||||||
Revision ID: 0230_noti_postage_constraint
|
|
||||||
Revises: 0229_new_letter_rates
|
|
||||||
Create Date: 2018-09-19 11:42:52.229430
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
|
|
||||||
|
|
||||||
revision = '0230_noti_postage_constraint'
|
|
||||||
down_revision = '0229_new_letter_rates'
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
op.execute("""
|
|
||||||
ALTER TABLE notifications ADD CONSTRAINT "chk_notifications_postage_null"
|
|
||||||
CHECK (
|
|
||||||
CASE WHEN notification_type = 'letter' THEN
|
|
||||||
postage is not null and postage in ('first', 'second')
|
|
||||||
ELSE
|
|
||||||
postage is null
|
|
||||||
END
|
|
||||||
)
|
|
||||||
NOT VALID
|
|
||||||
""")
|
|
||||||
op.execute("""
|
|
||||||
ALTER TABLE notification_history ADD CONSTRAINT "chk_notification_history_postage_null"
|
|
||||||
CHECK (
|
|
||||||
CASE WHEN notification_type = 'letter' THEN
|
|
||||||
postage is not null and postage in ('first', 'second')
|
|
||||||
ELSE
|
|
||||||
postage is null
|
|
||||||
END
|
|
||||||
)
|
|
||||||
NOT VALID
|
|
||||||
""")
|
|
||||||
op.execute('ALTER TABLE notifications VALIDATE CONSTRAINT "chk_notifications_postage_null"')
|
|
||||||
op.execute('ALTER TABLE notification_history VALIDATE CONSTRAINT "chk_notification_history_postage_null"')
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
op.drop_constraint('chk_notifications_postage_null', 'notifications', type_='check')
|
|
||||||
op.drop_constraint('chk_notification_history_postage_null', 'notification_history', type_='check')
|
|
||||||
30
migrations/versions/0230_noti_postage_constraint_1.py
Normal file
30
migrations/versions/0230_noti_postage_constraint_1.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0230_noti_postage_constraint_1
|
||||||
|
Revises: 0229_new_letter_rates
|
||||||
|
Create Date: 2018-09-19 11:42:52.229430
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0230_noti_postage_constraint_1'
|
||||||
|
down_revision = '0229_new_letter_rates'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.execute("""
|
||||||
|
ALTER TABLE notifications ADD CONSTRAINT "chk_notifications_postage_null"
|
||||||
|
CHECK (
|
||||||
|
CASE WHEN notification_type = 'letter' THEN
|
||||||
|
postage is not null and postage in ('first', 'second')
|
||||||
|
ELSE
|
||||||
|
postage is null
|
||||||
|
END
|
||||||
|
)
|
||||||
|
NOT VALID
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_constraint('chk_notifications_postage_null', 'notifications', type_='check')
|
||||||
30
migrations/versions/0231_noti_postage_constraint_2.py
Normal file
30
migrations/versions/0231_noti_postage_constraint_2.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0230_noti_postage_constraint_2
|
||||||
|
Revises: 0230_noti_postage_constraint_1
|
||||||
|
Create Date: 2018-09-19 11:42:52.229430
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0230_noti_postage_constraint_2'
|
||||||
|
down_revision = '0230_noti_postage_constraint_1'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.execute("""
|
||||||
|
ALTER TABLE notification_history ADD CONSTRAINT "chk_notification_history_postage_null"
|
||||||
|
CHECK (
|
||||||
|
CASE WHEN notification_type = 'letter' THEN
|
||||||
|
postage is not null and postage in ('first', 'second')
|
||||||
|
ELSE
|
||||||
|
postage is null
|
||||||
|
END
|
||||||
|
)
|
||||||
|
NOT VALID
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_constraint('chk_notification_history_postage_null', 'notification_history', type_='check')
|
||||||
21
migrations/versions/0232_noti_postage_constraint_3.py
Normal file
21
migrations/versions/0232_noti_postage_constraint_3.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
"""
|
||||||
|
|
||||||
|
Revision ID: 0230_noti_postage_constraint_3
|
||||||
|
Revises: 0230_noti_postage_constraint_2
|
||||||
|
Create Date: 2018-09-19 11:42:52.229430
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
|
||||||
|
revision = '0230_noti_postage_constraint_3'
|
||||||
|
down_revision = '0230_noti_postage_constraint_2'
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.execute('ALTER TABLE notifications VALIDATE CONSTRAINT "chk_notifications_postage_null"')
|
||||||
|
op.execute('ALTER TABLE notification_history VALIDATE CONSTRAINT "chk_notification_history_postage_null"')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user