mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Add a type table for broadcast providers
This adds a type table for broadcast providers, which is the pattern we follow with our models (e.g. we have a `broadcast_channel_types` table). As well as the four providers, the migration populates it with `all` which is the value that will replace `null` in a later change. It should be safe to add the foreign key constraint to the `service_broadcast_settings` in the same migration since the column is still nullable and we don't have data in that column that is not in the types table.
This commit is contained in:
32
migrations/versions/0352_broadcast_provider_types.py
Normal file
32
migrations/versions/0352_broadcast_provider_types.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0352_broadcast_provider_types
|
||||
Revises: 0351_unique_key_annual_billing
|
||||
Create Date: 2021-05-05 15:07:22.146657
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = '0352_broadcast_provider_types'
|
||||
down_revision = '0351_unique_key_annual_billing'
|
||||
|
||||
PROVIDER_TYPES = ('ee', 'three', 'vodafone', 'o2', 'all')
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table('broadcast_provider_types',
|
||||
sa.Column('name', sa.String(length=255), nullable=False),
|
||||
sa.PrimaryKeyConstraint('name'))
|
||||
for provider in PROVIDER_TYPES:
|
||||
op.execute(f"INSERT INTO broadcast_provider_types VALUES ('{provider}')")
|
||||
op.create_foreign_key('service_broadcast_settings_provider_fkey',
|
||||
'service_broadcast_settings',
|
||||
'broadcast_provider_types',
|
||||
['provider'],
|
||||
['name'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_constraint('service_broadcast_settings_provider_fkey', 'service_broadcast_settings', type_='foreignkey')
|
||||
op.drop_table('broadcast_provider_types')
|
||||
Reference in New Issue
Block a user