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:
Katie Smith
2021-05-05 15:24:49 +01:00
parent 46fe3fca23
commit aec631f208
3 changed files with 41 additions and 2 deletions

View File

@@ -2553,7 +2553,7 @@ class ServiceBroadcastSettings(db.Model):
channel = db.Column(
db.String(255), db.ForeignKey('broadcast_channel_types.name'), nullable=False
)
provider = db.Column(db.String, nullable=True)
provider = db.Column(db.String, db.ForeignKey('broadcast_provider_types.name'), nullable=True)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
updated_at = db.Column(db.DateTime, nullable=True, onupdate=datetime.datetime.utcnow)
@@ -2564,6 +2564,12 @@ class BroadcastChannelTypes(db.Model):
name = db.Column(db.String(255), primary_key=True)
class BroadcastProviderTypes(db.Model):
__tablename__ = 'broadcast_provider_types'
name = db.Column(db.String(255), primary_key=True)
class ServiceBroadcastProviderRestriction(db.Model):
"""
TODO: Drop this table as no longer used

View 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')

View File

@@ -120,7 +120,8 @@ def notify_db_session(notify_db, sms_providers):
"broadcast_status_type",
"invite_status_type",
"service_callback_type",
"broadcast_channel_types"]:
"broadcast_channel_types",
"broadcast_provider_types"]:
notify_db.engine.execute(tbl.delete())
notify_db.session.commit()