more files

This commit is contained in:
Kenneth Kehl
2023-07-17 07:45:54 -07:00
parent 4d090ed9ef
commit de4812efee
11 changed files with 90 additions and 48 deletions

View File

@@ -33,6 +33,7 @@ new_type = sa.Enum(*new_options, name=enum_name)
alter_str = 'ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type ' alter_str = 'ALTER TABLE {table} ALTER COLUMN status TYPE {enum} USING status::text::notify_status_type '
def upgrade(): def upgrade():
op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name)) op.execute('ALTER TYPE {enum} RENAME TO {tmp_name}'.format(enum=enum_name, tmp_name=tmp_name))

View File

@@ -8,6 +8,8 @@ Create Date: 2017-07-12 13:35:45.636618
from datetime import datetime from datetime import datetime
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import text
from app.dao.date_util import get_month_start_and_end_date_in_utc from app.dao.date_util import get_month_start_and_end_date_in_utc
down_revision = '0111_drop_old_service_flags' down_revision = '0111_drop_old_service_flags'
@@ -26,9 +28,13 @@ def upgrade():
for x in res: for x in res:
start_date, end_date = get_month_start_and_end_date_in_utc( start_date, end_date = get_month_start_and_end_date_in_utc(
datetime(int(x.year), datetime.strptime(x.month, '%B').month, 1)) datetime(int(x.year), datetime.strptime(x.month, '%B').month, 1))
conn.execute("update monthly_billing set start_date = '{}', end_date = '{}' where id = '{}'".format(start_date, input_params = {
end_date, "start_date": start_date,
x.id)) "end_date": end_date,
"x_id": x.id
}
conn.execute(text("update monthly_billing set start_date = :start_date, end_date = :end_date where id = :x_id"),
input_params)
op.alter_column('monthly_billing', 'start_date', nullable=False) op.alter_column('monthly_billing', 'start_date', nullable=False)
op.alter_column('monthly_billing', 'end_date', nullable=False) op.alter_column('monthly_billing', 'end_date', nullable=False)
op.create_index(op.f('uix_monthly_billing'), 'monthly_billing', ['service_id', 'start_date', 'notification_type'], op.create_index(op.f('uix_monthly_billing'), 'monthly_billing', ['service_id', 'start_date', 'notification_type'],

View File

@@ -18,13 +18,13 @@ def upgrade():
op.get_bind() op.get_bind()
op.execute(""" op.execute("""
update templates update templates
set process_type = '{}' set process_type = 'normal'
where templates.id in ( where templates.id in (
select templates.id from templates select templates.id from templates
join templates_history on templates.id=templates_history.id join templates_history on templates.id=templates_history.id
where templates_history.name = 'Example text message template' where templates_history.name = 'Example text message template'
) )
""".format(NORMAL)) """)
def downgrade(): def downgrade():

View File

@@ -7,6 +7,8 @@ Create Date: 2017-06-29 12:44:16.815039
""" """
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0180_another_letter_org' revision = '0180_another_letter_org'
down_revision = '0179_billing_primary_const' down_revision = '0179_billing_primary_const'
@@ -19,18 +21,19 @@ NEW_ORGANISATIONS = [
def upgrade(): def upgrade():
conn = op.get_bind()
for numeric_id, name in NEW_ORGANISATIONS: for numeric_id, name in NEW_ORGANISATIONS:
op.execute(""" input_params = {
INSERT "numeric_id": numeric_id,
INTO dvla_organisation "name": name
VALUES ('{}', '{}') }
""".format(numeric_id, name)) conn.execute(text("INSERT INTO dvla_organisation VALUES (:numeric_id, :name)"), input_params)
def downgrade(): def downgrade():
conn = op.get_bind()
for numeric_id, _ in NEW_ORGANISATIONS: for numeric_id, _ in NEW_ORGANISATIONS:
op.execute(""" input_params = {
DELETE "numeric_id": numeric_id
FROM dvla_organisation }
WHERE id = '{}' conn.execute(text("DELETE FROM dvla_organisation WHERE id = :numeric_id"), input_params)
""".format(numeric_id))

View File

@@ -6,6 +6,8 @@ Revises: 0213_brand_colour_domain_
""" """
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0214_another_letter_org' revision = '0214_another_letter_org'
down_revision = '0213_brand_colour_domain' down_revision = '0213_brand_colour_domain'
@@ -18,18 +20,20 @@ NEW_ORGANISATIONS = [
def upgrade(): def upgrade():
conn = op.get_bind()
for numeric_id, name in NEW_ORGANISATIONS: for numeric_id, name in NEW_ORGANISATIONS:
op.execute(""" input_params = {
INSERT "numeric_id": numeric_id,
INTO dvla_organisation "name": name
VALUES ('{}', '{}') }
""".format(numeric_id, name))
conn.execute(text("INSERT INTO dvla_organisation VALUES (:numeric_id, :name)"), input_params)
def downgrade(): def downgrade():
conn = op.get_bind()
for numeric_id, _ in NEW_ORGANISATIONS: for numeric_id, _ in NEW_ORGANISATIONS:
op.execute(""" input_params = {
DELETE "numeric_id": numeric_id
FROM dvla_organisation }
WHERE id = '{}' conn.execute(text("DELETE FROM dvla_organisation WHERE id = :numeric_id"), input_params)
""".format(numeric_id))

View File

@@ -17,7 +17,7 @@ def upgrade():
INSERT INTO INSERT INTO
service_permissions (service_id, permission, created_at) service_permissions (service_id, permission, created_at)
SELECT SELECT
id, '{permission}', now() id, 'edit_folders', now()
FROM FROM
services services
WHERE WHERE
@@ -27,11 +27,9 @@ def upgrade():
service_permissions service_permissions
WHERE WHERE
service_id = services.id and service_id = services.id and
permission = '{permission}'
)
""".format(
permission = 'edit_folders' permission = 'edit_folders'
)) )
""")
def downgrade(): def downgrade():

View File

@@ -7,6 +7,8 @@ Create Date: 2016-10-25 17:37:27.660723
""" """
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
from sqlalchemy import text
revision = '0283_platform_admin_not_live' revision = '0283_platform_admin_not_live'
down_revision = '0282_add_count_as_live' down_revision = '0282_add_count_as_live'
@@ -18,7 +20,7 @@ STATEMENT = """
UPDATE UPDATE
services services
SET SET
count_as_live = {count_as_live} count_as_live = :count_as_live
FROM FROM
users users
WHERE WHERE
@@ -29,7 +31,16 @@ STATEMENT = """
def upgrade(): def upgrade():
op.execute(STATEMENT.format(count_as_live='false')) conn = op.get_bind()
input_params = {
"count_as_live": "false"
}
conn.execute(text(STATEMENT), input_params)
def downgrade(): def downgrade():
op.execute(STATEMENT.format(count_as_live='true')) conn = op.get_bind()
input_params = {
"count_as_live": "true"
}
conn.execute(text(STATEMENT), input_params)

View File

@@ -6,6 +6,7 @@ Create Date: 2019-12-09 12:13:49.432993
""" """
from alembic import op from alembic import op
from sqlalchemy import text
revision = '0312_populate_returned_letters' revision = '0312_populate_returned_letters'
down_revision = '0311_add_inbound_sms_history' down_revision = '0311_add_inbound_sms_history'
@@ -20,14 +21,18 @@ def upgrade():
and notification_status = 'returned-letter'""" and notification_status = 'returned-letter'"""
insert_sql = """ insert_sql = """
insert into returned_letters(id, reported_at, service_id, notification_id, created_at, updated_at) insert into returned_letters(id, reported_at, service_id, notification_id, created_at, updated_at)
values(uuid_in(md5(random()::text)::cstring), '{}', '{}', '{}', now(), null) values(uuid_in(md5(random()::text)::cstring), :updated_at, :service_id, :id, now(), null)
""" """
results = conn.execute(sql) results = conn.execute(sql)
returned_letters = results.fetchall() returned_letters = results.fetchall()
for x in returned_letters: for x in returned_letters:
f = insert_sql.format(x.updated_at.date(), x.service_id, x.id) input_params = {
conn.execute(f) "updated_at": x.updated_at.date(),
"service_id": x.service_id,
"id": x.id
}
conn.execute(text(insert_sql), input_params)
def downgrade(): def downgrade():

View File

@@ -7,6 +7,7 @@ Create Date: 2021-02-09 09:19:07.957980
""" """
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
revision = '0345_move_broadcast_provider' revision = '0345_move_broadcast_provider'
@@ -23,14 +24,17 @@ def upgrade():
""" """
insert_sql = """ insert_sql = """
insert into service_broadcast_settings(service_id, channel, provider, created_at, updated_at) insert into service_broadcast_settings(service_id, channel, provider, created_at, updated_at)
values('{}', 'test', '{}', now(), null) values(:service_id, 'test', :provider, now(), null)
""" """
conn = op.get_bind() conn = op.get_bind()
results = conn.execute(sql) results = conn.execute(sql)
restrictions = results.fetchall() restrictions = results.fetchall()
for x in restrictions: for x in restrictions:
f = insert_sql.format(x.service_id, x.provider) input_params = {
conn.execute(f) "service_id": x.service_id,
"provider": x.provider
}
conn.execute(text(insert_sql), input_params)
def downgrade(): def downgrade():

View File

@@ -24,7 +24,11 @@ def upgrade():
def downgrade(): def downgrade():
conn = op.get_bind() conn = op.get_bind()
input_params = {
"id": str(uuid.uuid4()),
}
conn.execute( conn.execute(
text(
""" """
INSERT INTO provider_details ( INSERT INTO provider_details (
id, id,
@@ -37,7 +41,7 @@ def downgrade():
created_by_id created_by_id
) )
VALUES ( VALUES (
'{}', :id,
'Reach', 'Reach',
'reach', 'reach',
0, 0,
@@ -46,7 +50,4 @@ def downgrade():
1, 1,
null null
) )
""".format( """), input_params)
str(uuid.uuid4()),
)
)

View File

@@ -5,8 +5,11 @@ Revises: 0389_no_more_letters.py
Create Date: 2023-02-28 14:25:50.751952 Create Date: 2023-02-28 14:25:50.751952
""" """
import uuid
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
revision = '0390_drop_dvla_provider.py' revision = '0390_drop_dvla_provider.py'
@@ -23,10 +26,16 @@ def upgrade():
def downgrade(): def downgrade():
# migration 0066 in reverse # migration 0066 in reverse
provider_id = str(uuid.uuid4()) provider_id = str(uuid.uuid4())
op.execute( input_params = {
"INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id) "provider_id": provider_id
}
conn = op.get_bind()
conn.execute(
text("INSERT INTO provider_details (id, display_name, identifier, priority, notification_type, active, version) values (:provider_id, 'DVLA', 'dvla', 50, 'letter', true, 1)"),
input_params
) )
op.execute( conn.execute(
"INSERT INTO provider_details_history (id, display_name, identifier, priority, notification_type, active, version) values ('{}', 'DVLA', 'dvla', 50, 'letter', true, 1)".format(provider_id) text("INSERT INTO provider_details_history (id, display_name, identifier, priority, notification_type, active, version) values (:provider_id, 'DVLA', 'dvla', 50, 'letter', true, 1)"),
input_params
) )
# ### end Alembic commands ### # ### end Alembic commands ###