more files

This commit is contained in:
Kenneth Kehl
2023-07-17 13:16:50 -07:00
parent cefb8a281f
commit e750e96117
13 changed files with 110 additions and 86 deletions

View File

@@ -7,6 +7,8 @@ Create Date: 2016-06-08 01:00:00.000000
"""
# revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0027_update_provider_rates'
down_revision = '0026_rename_notify_service'
@@ -18,13 +20,17 @@ import uuid
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.get_bind()
op.execute((
"INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES ('{}', '{}', 1.8, "
"(SELECT id FROM provider_details WHERE identifier = 'mmg'))").format(uuid.uuid4(), datetime.utcnow()))
op.execute((
"INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES ('{}', '{}', 2.5, "
"(SELECT id FROM provider_details WHERE identifier = 'firetext'))").format(uuid.uuid4(), datetime.utcnow()))
conn = op.get_bind()
input_params = {
"id": uuid.uuid4(),
"time_now": datetime.utcnow()
}
conn.execute(text(
"INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES (:id, :time_now, 1.8, "
"(SELECT id FROM provider_details WHERE identifier = 'mmg'))"), input_params)
conn.execute(text(
"INSERT INTO provider_rates (id, valid_from, rate, provider_id) VALUES (:id, :time_now, 2.5, "
"(SELECT id FROM provider_details WHERE identifier = 'firetext'))"), input_params)
### end Alembic commands ###

View File

@@ -7,6 +7,7 @@ Create Date: 2017-06-26 11:43:30.374723
"""
from alembic import op
from sqlalchemy import text
revision = '0101_een_logo'
down_revision = '0100_notification_created_by'
@@ -16,15 +17,23 @@ ENTERPRISE_EUROPE_NETWORK_ID = '89ce468b-fb29-4d5d-bd3f-d468fb6f7c36'
def upgrade():
op.execute("""INSERT INTO organisation VALUES (
'{}',
input_params = {
"network_id": ENTERPRISE_EUROPE_NETWORK_ID
}
conn = op.get_bind()
conn.execute(text("""INSERT INTO organisation VALUES (
:network_id,
'',
'een_x2.png',
'een'
)""".format(ENTERPRISE_EUROPE_NETWORK_ID))
)"""), input_params)
def downgrade():
op.execute("""
DELETE FROM organisation WHERE "id" = '{}'
""".format(ENTERPRISE_EUROPE_NETWORK_ID))
input_params = {
"network_id": ENTERPRISE_EUROPE_NETWORK_ID
}
conn = op.get_bind()
conn.execute(text("""
DELETE FROM organisation WHERE "id" = :network_id
"""), input_params)

View File

@@ -1,4 +1,7 @@
import os
from sqlalchemy import text
from app import config
"""
@@ -20,20 +23,24 @@ default_sms_sender = config.FROM_NUMBER
def upgrade():
op.execute("""
conn = op.get_bind()
input_params = {
"default_sms_sender": default_sms_sender
}
conn.execute(text("""
update services set prefix_sms = True
where id in (
select service_id from service_sms_senders
where is_default = True and sms_sender = '{}'
where is_default = True and sms_sender = :default_sms_sender
)
""".format(default_sms_sender))
op.execute("""
"""), input_params)
conn.execute(text("""
update services set prefix_sms = False
where id in (
select service_id from service_sms_senders
where is_default = True and sms_sender != '{}'
where is_default = True and sms_sender != :default_sms_sender
)
""".format(default_sms_sender))
"""), input_params)
def downgrade():

View File

@@ -8,6 +8,7 @@ Create Date: 2017-11-07 13:04:04.077142
from alembic import op
from flask import current_app
import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
revision = '0140_sms_prefix_non_nullable'
@@ -15,12 +16,15 @@ down_revision = '0139_migrate_sms_allowance_data'
def upgrade():
op.execute("""
conn = op.get_bind()
input_params = {
"id": current_app.config['NOTIFY_SERVICE_ID']
}
conn.execute(text("""
update services
set prefix_sms = false
where id = '{}'
""".format(current_app.config['NOTIFY_SERVICE_ID']))
where id = :id
"""), input_params)
op.alter_column(
'services',
@@ -39,8 +43,12 @@ def downgrade():
nullable=True,
)
op.execute("""
conn = op.get_bind()
input_params = {
"id": current_app.config['NOTIFY_SERVICE_ID']
}
conn.execute(text("""
update services
set prefix_sms = null
where id = '{}'
""".format(current_app.config['NOTIFY_SERVICE_ID']))
where id = :id
"""), input_params)

View File

@@ -7,6 +7,8 @@ Create Date: 2018-02-21 12:05:00
"""
# revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0198_add_caseworking_permission'
down_revision = '0197_service_contact_link'
@@ -16,11 +18,17 @@ PERMISSION_NAME = "caseworking"
def upgrade():
op.get_bind()
op.execute("insert into service_permission_types values('{}')".format(PERMISSION_NAME))
conn = op.get_bind()
input_params = {
"permission_name": PERMISSION_NAME
}
conn.execute(text("insert into service_permission_types values(:permission_name)"), input_params)
def downgrade():
op.get_bind()
op.execute("delete from service_permissions where permission = '{}'".format(PERMISSION_NAME))
op.execute("delete from service_permission_types where name = '{}'".format(PERMISSION_NAME))
conn = op.get_bind()
input_params = {
"permission_name": PERMISSION_NAME
}
conn.execute(text("delete from service_permissions where permission = :permission_name"), input_params)
conn.execute(text("delete from service_permission_types where name = :permission_name"), input_params)

View File

@@ -11,13 +11,11 @@ from alembic import op
revision = '0212_remove_caseworking'
down_revision = '0211_email_branding_update'
PERMISSION_NAME = "caseworking"
def upgrade():
op.execute("delete from service_permissions where permission = '{}'".format(PERMISSION_NAME))
op.execute("delete from service_permission_types where name = '{}'".format(PERMISSION_NAME))
op.execute("delete from service_permissions where permission = 'caseworking'")
op.execute("delete from service_permission_types where name = 'caseworking'")
def downgrade():
op.execute("insert into service_permission_types values('{}')".format(PERMISSION_NAME))
op.execute("insert into service_permission_types values('caseworking')")

View File

@@ -4,7 +4,6 @@ Revises: 0216_remove_colours
Create Date: 2018-08-24 13:36:49.346156
"""
from alembic import op
from app.models import BRANDING_ORG
revision = '0217_default_email_branding'
down_revision = '0216_remove_colours'
@@ -15,10 +14,10 @@ def upgrade():
update
email_branding
set
brand_type = '{}'
brand_type = 'org'
where
brand_type = null
""".format(BRANDING_ORG))
""")
def downgrade():

View File

@@ -4,6 +4,8 @@ Revises: 0217_default_email_branding
Create Date: 2018-08-24 13:36:49.346156
"""
from alembic import op
from sqlalchemy import text
from app.models import BRANDING_ORG
revision = '0219_default_email_branding'
@@ -11,14 +13,18 @@ down_revision = '0217_default_email_branding'
def upgrade():
op.execute("""
conn = op.get_bind()
input_params = {
"branding_org": BRANDING_ORG
}
conn.execute(text("""
update
email_branding
set
brand_type = '{}'
brand_type = :branding_org
where
brand_type is null
""".format(BRANDING_ORG))
"""), input_params)
def downgrade():

View File

@@ -4,7 +4,6 @@ Revises: 0220_email_brand_type_non_null
Create Date: 2018-08-24 13:36:49.346156
"""
from alembic import op
from app.models import BRANDING_ORG, BRANDING_GOVUK
revision = '0221_nullable_service_branding'
@@ -25,17 +24,17 @@ def upgrade():
update
email_branding
set
brand_type = '{}'
brand_type = 'org'
where
brand_type = '{}'
""".format(BRANDING_ORG, BRANDING_GOVUK))
brand_type = 'govuk'
""")
op.execute("""
delete from
branding_type
where
name = '{}'
""".format(BRANDING_GOVUK))
name = 'govuk'
""")
def downgrade():
@@ -53,5 +52,5 @@ def downgrade():
branding_type
(name)
values
('{}')
""".format(BRANDING_GOVUK))
('govuk')
""")

View File

@@ -15,8 +15,7 @@ down_revision = '0260_remove_dvla_organisation'
TABLES = ['services', 'services_history']
CHANNELS = ['volume_{}'.format(channel) for channel in ('email', 'letter', 'sms')]
CHANNELS = ['volume_email', 'volume_letter', 'volume_sms']
def upgrade():
for table in TABLES:

View File

@@ -14,34 +14,18 @@ from alembic import op
import sqlalchemy as sa
BRANDING_TABLES = ('email_branding', 'letter_branding')
def upgrade():
for branding in BRANDING_TABLES:
op.execute("""
UPDATE
organisation
SET
{branding}_id = {branding}.id
FROM
{branding}
WHERE
{branding}.domain in (
SELECT
domain
FROM
domain
WHERE
domain.organisation_id = organisation.id
)
""".format(branding=branding))
op.execute("""UPDATE organisation SET email_branding_id = email_branding.id
FROM email_branding
WHERE email_branding.domain in (SELECT domain FROM domain WHERE domain.organisation_id = organisation.id)
""")
op.execute("""UPDATE organisation SET letter_branding_id = letter_branding.id
FROM letter_branding
WHERE letter_branding.domain in (SELECT domain FROM domain WHERE domain.organisation_id = organisation.id)
""")
def downgrade():
for branding in BRANDING_TABLES:
op.execute("""
UPDATE
organisation
SET
{branding}_id = null
""".format(branding=branding))
op.execute("""UPDATE organisation SET email_branding_id = null""")
op.execute("""UPDATE organisation SET letter_branding_id = null""")

View File

@@ -56,4 +56,4 @@ def downgrade():
"""
conn.execute(text(insert_sql), service_id=str(x.id), organisation_id=str(x.organisation_id))
else:
raise Exception("should only have 1 row. Service_id {}, orgid: {}".format(x.id, x.organisation_id))
raise Exception(f"should only have 1 row. Service_id {x.id}, orgid: {x.organisation_id}")

View File

@@ -19,7 +19,10 @@ down_revision = '0366_letter_rates_2022'
def upgrade():
conn = op.get_bind()
conn.execute(
input_params = {
"id": uuid.uuid4()
}
conn.execute(text(
"""
INSERT INTO provider_details (
id,
@@ -32,7 +35,7 @@ def upgrade():
created_by_id
)
VALUES (
'{}',
:id,
'Reach',
'reach',
0,
@@ -41,9 +44,7 @@ def upgrade():
1,
null
)
""".format(
str(uuid.uuid4()),
)
"""), input_params
)