mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
reformat
This commit is contained in:
@@ -10,22 +10,22 @@ import sqlalchemy as sa
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = '0348_migrate_broadcast_settings'
|
||||
down_revision = '0347_add_dvla_volumes_template'
|
||||
revision = "0348_migrate_broadcast_settings"
|
||||
down_revision = "0347_add_dvla_volumes_template"
|
||||
|
||||
|
||||
def upgrade():
|
||||
# For every service that has the broadcast permission we want it to have
|
||||
# a row in the broadcast_service_settings table
|
||||
#
|
||||
# If it doesnt have a row already, then:
|
||||
# - if the service is in trial mode, add a row and set the channel as 'severe'
|
||||
# - if the service is in live mode, add a row and set the channel as 'test'
|
||||
#
|
||||
# If it does have a row already no action needed
|
||||
conn = op.get_bind()
|
||||
# For every service that has the broadcast permission we want it to have
|
||||
# a row in the broadcast_service_settings table
|
||||
#
|
||||
# If it doesnt have a row already, then:
|
||||
# - if the service is in trial mode, add a row and set the channel as 'severe'
|
||||
# - if the service is in live mode, add a row and set the channel as 'test'
|
||||
#
|
||||
# If it does have a row already no action needed
|
||||
conn = op.get_bind()
|
||||
|
||||
find_services_sql = """
|
||||
find_services_sql = """
|
||||
SELECT services.id, services.restricted
|
||||
FROM services
|
||||
LEFT JOIN service_permissions
|
||||
@@ -33,24 +33,32 @@ def upgrade():
|
||||
WHERE service_permissions.permission = 'broadcast'
|
||||
"""
|
||||
|
||||
services = conn.execute(find_services_sql)
|
||||
for service in services:
|
||||
input_params = {"service_id": service.id}
|
||||
setting = conn.execute(
|
||||
text("SELECT service_id, channel, provider FROM service_broadcast_settings WHERE service_id=:service_id;"),
|
||||
input_params).first()
|
||||
if setting:
|
||||
print(f"Service {service.id} already has service_broadcast_settings. No action required")
|
||||
else:
|
||||
channel = "severe" if service.restricted else "test"
|
||||
print(f"Service {service.id} does not have service_broadcast_settings. Will insert one with channel {channel}")
|
||||
input_params = {
|
||||
"service_id": service.id,
|
||||
"channel": channel
|
||||
}
|
||||
conn.execute(text("INSERT INTO service_broadcast_settings (service_id, channel, created_at) "
|
||||
"VALUES (:service_id, :channel, now());"),
|
||||
input_params)
|
||||
services = conn.execute(find_services_sql)
|
||||
for service in services:
|
||||
input_params = {"service_id": service.id}
|
||||
setting = conn.execute(
|
||||
text(
|
||||
"SELECT service_id, channel, provider FROM service_broadcast_settings WHERE service_id=:service_id;"
|
||||
),
|
||||
input_params,
|
||||
).first()
|
||||
if setting:
|
||||
print(
|
||||
f"Service {service.id} already has service_broadcast_settings. No action required"
|
||||
)
|
||||
else:
|
||||
channel = "severe" if service.restricted else "test"
|
||||
print(
|
||||
f"Service {service.id} does not have service_broadcast_settings. Will insert one with channel {channel}"
|
||||
)
|
||||
input_params = {"service_id": service.id, "channel": channel}
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO service_broadcast_settings (service_id, channel, created_at) "
|
||||
"VALUES (:service_id, :channel, now());"
|
||||
),
|
||||
input_params,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
Reference in New Issue
Block a user