Move provider restriction into broadcast settings

This means we will have a much easier way of knowing what the settings
are for a broadcast service.

Note, we can just move data directly into the newer table as there is
nothing on the API or admin app that is putting data in the
`service_broadcast_provider_restriction` table, this was being done
manually for the few services that needed it.
This commit is contained in:
David McDonald
2021-02-09 09:38:43 +00:00
parent e0ddb5a39e
commit b2213dad19
4 changed files with 50 additions and 19 deletions

View File

@@ -0,0 +1,39 @@
"""
Revision ID: 0344_move_broadcast_provider
Revises: 0343_org_billing_details
Create Date: 2021-02-09 09:19:07.957980
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0344_move_broadcast_provider'
down_revision = '0343_org_billing_details'
def upgrade():
op.add_column('service_broadcast_settings', sa.Column('provider', sa.String(), nullable=True))
sql = """
select service_id, provider
from service_broadcast_provider_restriction
where service_id NOT IN (select service_id from service_broadcast_settings)
"""
insert_sql = """
insert into service_broadcast_settings(service_id, channel, provider, created_at, updated_at)
values('{}', 'test', '{}', now(), null)
"""
conn = op.get_bind()
results = conn.execute(sql)
restrictions = results.fetchall()
for x in restrictions:
f = insert_sql.format(x.service_id, x.provider)
conn.execute(f)
def downgrade():
# Downgrade does not try and fully undo the upgrade, in particular it does not
# delete the rows added to the service_broadcast_settings table
op.drop_column('service_broadcast_settings', 'provider')