mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Make SMS prefix setting non-nullable
We have now: - defaulted new services to start with this column set to `true` - migrated all preexisting services[1] to have either `true` or `false` set for this column There is no way for a service to switch back from `true`/`false` to `null`. This means that we can safely enforce a non-nullable constraint on this column now. 1. There is a little gotcha: the GOV.UK Notify service still relies on the `sms_sender` column. It doesn’t have a row in the `service_sms_senders` table. This means the previous migration never changed this service’s value for `prefix_sms` from `null`. So this commit also changes its value to `False`, so that the rest of the migration, of the whole column, is possible.
This commit is contained in:
46
migrations/versions/0140_sms_prefix_non_nullable.py
Normal file
46
migrations/versions/0140_sms_prefix_non_nullable.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0140_sms_prefix_non_nullable
|
||||
Revises: 0139_migrate_sms_allowance_data
|
||||
Create Date: 2017-11-07 13:04:04.077142
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
from flask import current_app
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = '0140_sms_prefix_non_nullable'
|
||||
down_revision = '0139_migrate_sms_allowance_data'
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
op.execute("""
|
||||
update services
|
||||
set prefix_sms = false
|
||||
where id = '{}'
|
||||
""".format(current_app.config['NOTIFY_SERVICE_ID']))
|
||||
|
||||
op.alter_column(
|
||||
'services',
|
||||
'prefix_sms',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
op.alter_column(
|
||||
'services',
|
||||
'prefix_sms',
|
||||
existing_type=sa.BOOLEAN(),
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
op.execute("""
|
||||
update services
|
||||
set prefix_sms = null
|
||||
where id = '{}'
|
||||
""".format(current_app.config['NOTIFY_SERVICE_ID']))
|
||||
Reference in New Issue
Block a user