From cefb8a281f3d8e112a732b85694ca53b1dde24c3 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 17 Jul 2023 11:29:08 -0700 Subject: [PATCH] more files --- migrations/versions/0029_fix_email_from.py | 13 +++-- migrations/versions/0091_letter_billing.py | 37 ++++++++++---- migrations/versions/0099_tfl_dar.py | 22 +++++--- .../0130_service_email_reply_to_row.py | 23 ++++++--- .../versions/0151_refactor_letter_rates.py | 51 ++++++++++++------- .../versions/0159_add_historical_redact.py | 13 +++-- .../versions/0202_new_letter_pricing.py | 15 ++++-- .../versions/0262_remove_edit_folders.py | 16 +++--- .../versions/0289_precompiled_for_all.py | 17 ++++--- migrations/versions/0305_add_gp_org_type.py | 12 ++--- migrations/versions/0350_update_rates.py | 10 ++-- 11 files changed, 158 insertions(+), 71 deletions(-) diff --git a/migrations/versions/0029_fix_email_from.py b/migrations/versions/0029_fix_email_from.py index a2bb3f50c..4def70321 100644 --- a/migrations/versions/0029_fix_email_from.py +++ b/migrations/versions/0029_fix_email_from.py @@ -7,6 +7,8 @@ Create Date: 2016-06-13 15:15:34.035984 """ # revision identifiers, used by Alembic. +from sqlalchemy import text + revision = '0029_fix_email_from' down_revision = '0028_fix_reg_template_history' @@ -14,10 +16,15 @@ from alembic import op import sqlalchemy as sa service_id = 'd6aa2c68-a2d9-4437-ab19-3ae8eb202553' + + def upgrade(): - op.get_bind() - op.execute("update services set email_from = 'testsender' where id = '{}'".format(service_id)) - op.execute("update services_history set email_from = 'testsender' where id = '{}'".format(service_id)) + conn = op.get_bind() + input_params = { + "service_id": service_id + } + conn.execute(text("update services set email_from = 'testsender' where id = :service_id"), input_params) + conn.execute(text("update services_history set email_from = 'testsender' where id = :service_id"), input_params) def downgrade(): diff --git a/migrations/versions/0091_letter_billing.py b/migrations/versions/0091_letter_billing.py index 7dda9bb70..82cd867d5 100644 --- a/migrations/versions/0091_letter_billing.py +++ b/migrations/versions/0091_letter_billing.py @@ -8,6 +8,7 @@ Create Date: 2017-05-31 11:43:55.744631 import uuid from alembic import op import sqlalchemy as sa +from sqlalchemy import text from sqlalchemy.dialects import postgresql revision = '0091_letter_billing' @@ -31,16 +32,34 @@ def upgrade(): op.create_index(op.f('ix_letter_rate_details_letter_rate_id'), 'letter_rate_details', ['letter_rate_id'], unique=False) - op.get_bind() + conn = op.get_bind() letter_id = uuid.uuid4() - op.execute("insert into letter_rates(id, valid_from) values('{}', '2017-03-31 23:00:00')".format(letter_id)) - insert_details = "insert into letter_rate_details(id, letter_rate_id, page_total, rate) values('{}', '{}', {}, {})" - op.execute( - insert_details.format(uuid.uuid4(), letter_id, 1, 29.3)) - op.execute( - insert_details.format(uuid.uuid4(), letter_id, 2, 32)) - op.execute( - insert_details.format(uuid.uuid4(), letter_id, 3, 35)) + input_params = { + "letter_id": letter_id + } + conn.execute(text("insert into letter_rates(id, valid_from) values(:letter_id, '2017-03-31 23:00:00')"), input_params) + insert_details = "insert into letter_rate_details(id, letter_rate_id, page_total, rate) values(:id, :letter_id, :page_total, :rate)" + input_params = { + "id": uuid.uuid4(), + "letter_id": letter_id, + "page_total": 1, + "rate": 29.3 + } + conn.execute(text(insert_details), input_params) + input_params = { + "id": uuid.uuid4(), + "letter_id": letter_id, + "page_total": 2, + "rate": 32 + } + conn.execute(text(insert_details), input_params) + input_params = { + "id": uuid.uuid4(), + "letter_id": letter_id, + "page_total": 3, + "rate": 35 + } + conn.execute(text(insert_details), input_params) def downgrade(): diff --git a/migrations/versions/0099_tfl_dar.py b/migrations/versions/0099_tfl_dar.py index 63016dbde..55c0349ee 100644 --- a/migrations/versions/0099_tfl_dar.py +++ b/migrations/versions/0099_tfl_dar.py @@ -7,6 +7,8 @@ Create Date: 2017-06-05 16:15:17.744908 """ # revision identifiers, used by Alembic. +from sqlalchemy import text + revision = '0099_tfl_dar' down_revision = '0098_service_inbound_api' @@ -18,15 +20,23 @@ TFL_DAR_ID = '1d70f564-919b-4c68-8bdf-b8520d92516e' def upgrade(): - op.execute("""INSERT INTO organisation VALUES ( - '{}', + conn = op.get_bind() + input_params = { + "tfl_dar_id": TFL_DAR_ID + } + conn.execute(text("""INSERT INTO organisation VALUES ( + :tfl_dar_id, '', 'tfl_dar_x2.png', 'tfl' - )""".format(TFL_DAR_ID)) + )"""), input_params) def downgrade(): - op.execute(""" - DELETE FROM organisation WHERE "id" = '{}' - """.format(TFL_DAR_ID)) + conn = op.get_bind() + input_params = { + "tfl_dar_id": TFL_DAR_ID + } + conn.execute(text(""" + DELETE FROM organisation WHERE "id" = :tfl_dar_id + """), input_params) diff --git a/migrations/versions/0130_service_email_reply_to_row.py b/migrations/versions/0130_service_email_reply_to_row.py index 6d0a75254..ab9876303 100644 --- a/migrations/versions/0130_service_email_reply_to_row.py +++ b/migrations/versions/0130_service_email_reply_to_row.py @@ -7,6 +7,8 @@ Create Date: 2017-08-29 14:09:41.042061 """ # revision identifiers, used by Alembic. +from sqlalchemy import text + revision = '0130_service_email_reply_to_row' down_revision = '0129_add_email_auth_permission' @@ -18,16 +20,25 @@ EMAIL_REPLY_TO_ID = 'b3a58d57-2337-662a-4cba-40792a9322f2' def upgrade(): - op.execute(""" + conn = op.get_bind() + input_params = { + "email_reply_to": EMAIL_REPLY_TO_ID, + "notify_service_id": NOTIFY_SERVICE_ID + } + conn.execute(text(""" INSERT INTO service_email_reply_to (id, service_id, email_address, is_default, created_at) VALUES - ('{}','{}', 'testsender@dispostable.com', 'f', NOW()) - """.format(EMAIL_REPLY_TO_ID, NOTIFY_SERVICE_ID)) + (:email_reply_to, :notify_service_id, 'testsender@dispostable.com', 'f', NOW()) + """), input_params) def downgrade(): - op.execute(""" + conn = op.get_bind() + input_params = { + "email_reply_to": EMAIL_REPLY_TO_ID, + } + conn.execute(text(""" DELETE FROM service_email_reply_to - WHERE id = '{}' - """.format(EMAIL_REPLY_TO_ID)) + WHERE id = :email_reply_to + """), input_params) diff --git a/migrations/versions/0151_refactor_letter_rates.py b/migrations/versions/0151_refactor_letter_rates.py index bb118fe5d..29d1b718b 100644 --- a/migrations/versions/0151_refactor_letter_rates.py +++ b/migrations/versions/0151_refactor_letter_rates.py @@ -10,6 +10,7 @@ from datetime import datetime from alembic import op import sqlalchemy as sa +from sqlalchemy import text from sqlalchemy.dialects import postgresql revision = '0151_refactor_letter_rates' @@ -31,25 +32,39 @@ def upgrade(): ) start_date = datetime(2016, 3, 31, 23, 00, 00) - op.execute("insert into letter_rates values('{}', '{}', null, 1, 0.30, True, 'second')".format( - str(uuid.uuid4()), start_date) - ) - op.execute("insert into letter_rates values('{}', '{}', null, 2, 0.33, True, 'second')".format( - str(uuid.uuid4()), start_date) - ) - op.execute("insert into letter_rates values('{}', '{}', null, 3, 0.36, True, 'second')".format( - str(uuid.uuid4()), start_date) - ) - op.execute("insert into letter_rates values('{}', '{}', null, 1, 0.33, False, 'second')".format( - str(uuid.uuid4()), start_date) - ) - op.execute("insert into letter_rates values('{}', '{}', null, 2, 0.39, False, 'second')".format( - str(uuid.uuid4()), start_date) - ) - op.execute("insert into letter_rates values('{}', '{}', null, 3, 0.45, False, 'second')".format( - str(uuid.uuid4()), start_date) - ) + conn = op.get_bind() + input_params = { + "id": uuid.uuid4(), + "start_date": start_date + } + conn.execute(text("insert into letter_rates values(:id, :start_date, null, 1, 0.30, True, 'second')"), input_params) + input_params = { + "id": uuid.uuid4(), + "start_date": start_date + } + conn.execute(text("insert into letter_rates values(:id, :start_date, null, 2, 0.33, True, 'second')"), input_params) + input_params = { + "id": uuid.uuid4(), + "start_date": start_date + } + conn.execute(text("insert into letter_rates values(:id, :start_date, null, 3, 0.36, True, 'second')"), input_params) + + input_params = { + "id": uuid.uuid4(), + "start_date": start_date + } + conn.execute(text("insert into letter_rates values(:id, :start_date, null, 1, 0.33, False, 'second')"), input_params) + input_params = { + "id": uuid.uuid4(), + "start_date": start_date + } + conn.execute(text("insert into letter_rates values(:id, :start_date, null, 2, 0.39, False, 'second')"), input_params) + input_params = { + "id": uuid.uuid4(), + "start_date": start_date + } + conn.execute(text("insert into letter_rates values(:id, :start_date, null, 3, 0.45, False, 'second')"), input_params) def downgrade(): diff --git a/migrations/versions/0159_add_historical_redact.py b/migrations/versions/0159_add_historical_redact.py index 16ea747ab..c9dde821f 100644 --- a/migrations/versions/0159_add_historical_redact.py +++ b/migrations/versions/0159_add_historical_redact.py @@ -7,6 +7,8 @@ Create Date: 2017-01-17 15:00:00.000000 """ # revision identifiers, used by Alembic. +from sqlalchemy import text + revision = '0159_add_historical_redact' down_revision = '0158_remove_rate_limit_default' @@ -15,8 +17,13 @@ import sqlalchemy as sa from sqlalchemy.dialects import postgresql from flask import current_app + def upgrade(): - op.execute( + conn = op.get_bind() + input_params = { + "notify_user": current_app.config['NOTIFY_USER_ID'] + } + conn.execute(text( """ INSERT INTO template_redacted ( @@ -29,12 +36,12 @@ def upgrade(): templates.id, false, now(), - '{notify_user}' + :notify_user FROM templates LEFT JOIN template_redacted on template_redacted.template_id = templates.id WHERE template_redacted.template_id IS NULL - """.format(notify_user=current_app.config['NOTIFY_USER_ID']) + """), input_params ) diff --git a/migrations/versions/0202_new_letter_pricing.py b/migrations/versions/0202_new_letter_pricing.py index d42714b75..dd04bd68c 100644 --- a/migrations/versions/0202_new_letter_pricing.py +++ b/migrations/versions/0202_new_letter_pricing.py @@ -5,6 +5,7 @@ Revises: 0198_add_caseworking_permission Create Date: 2017-07-09 12:44:16.815039 """ +from sqlalchemy import text revision = '0202_new_letter_pricing' down_revision = '0198_add_caseworking_permission' @@ -27,10 +28,18 @@ NEW_RATES = [ def upgrade(): conn = op.get_bind() for id, start_date, sheet_count, rate, crown, post_class in NEW_RATES: - conn.execute(""" + input_params = { + "id": id, + "start_date": start_date, + "sheet_count": sheet_count, + "rate": rate, + "crown": crown, + "post_class": post_class + } + conn.execute(text(""" INSERT INTO letter_rates (id, start_date, sheet_count, rate, crown, post_class) - VALUES ('{}', '{}', '{}', '{}', '{}', '{}') - """.format(id, start_date, sheet_count, rate, crown, post_class)) + VALUES (:id, :start_date, :sheet_count, :rate, :crown, :post_class) + """), input_params) def downgrade(): diff --git a/migrations/versions/0262_remove_edit_folders.py b/migrations/versions/0262_remove_edit_folders.py index afbb853e8..efc5e6d31 100644 --- a/migrations/versions/0262_remove_edit_folders.py +++ b/migrations/versions/0262_remove_edit_folders.py @@ -6,7 +6,7 @@ Create Date: 2019-02-15 11:20:25.812823 """ from alembic import op - +from sqlalchemy import text revision = '0262_remove_edit_folders' down_revision = '0261_service_volumes' @@ -17,11 +17,15 @@ def upgrade(): def downgrade(): - op.execute(""" + conn = op.get_bind() + input_params = { + "permission": "edit_folders" + } + conn.execute(text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT - id, '{permission}', now() + id, :permission, now() FROM services WHERE @@ -31,8 +35,6 @@ def downgrade(): service_permissions WHERE service_id = services.id and - permission = '{permission}' + permission = :permission ) - """.format( - permission='edit_folders' - )) + """), input_params) diff --git a/migrations/versions/0289_precompiled_for_all.py b/migrations/versions/0289_precompiled_for_all.py index 7f884e8a5..d7c6f43ab 100644 --- a/migrations/versions/0289_precompiled_for_all.py +++ b/migrations/versions/0289_precompiled_for_all.py @@ -6,7 +6,7 @@ Create Date: 2019-05-13 10:44:51.867661 """ from alembic import op - +from sqlalchemy import text revision = '0289_precompiled_for_all' down_revision = '0288_add_go_live_user' @@ -18,12 +18,16 @@ def upgrade(): def downgrade(): + conn = op.get_bind() op.execute("INSERT INTO service_permission_types values('precompiled_letter')") - op.execute(""" + input_params = { + "permission": "precompiled_letter" + } + conn.execute(text(""" INSERT INTO service_permissions (service_id, permission, created_at) SELECT - id, '{permission}', now() + id, :permission, now() FROM services WHERE @@ -33,8 +37,7 @@ def downgrade(): service_permissions WHERE service_id = services.id and - permission = '{permission}' + permission = :permission ) - """.format( - permission='precompiled_letter' - )) + """), input_params + ) diff --git a/migrations/versions/0305_add_gp_org_type.py b/migrations/versions/0305_add_gp_org_type.py index 3e1d11564..da10e479d 100644 --- a/migrations/versions/0305_add_gp_org_type.py +++ b/migrations/versions/0305_add_gp_org_type.py @@ -21,8 +21,8 @@ def upgrade(): organisation_types (name, is_crown, annual_free_sms_fragment_limit) VALUES - ('{}', false, 25000) - """.format(GP_ORG_TYPE_NAME)) + ('nhs_gp', false, 25000) + """) def downgrade(): @@ -32,11 +32,11 @@ def downgrade(): SET organisation_type = 'nhs_local' WHERE - organisation_type = '{}' - """.format(GP_ORG_TYPE_NAME)) + organisation_type = 'nhs_gp' + """) op.execute(""" DELETE FROM organisation_types WHERE - name = '{}' - """.format(GP_ORG_TYPE_NAME)) + name = 'nhs_gp' + """) diff --git a/migrations/versions/0350_update_rates.py b/migrations/versions/0350_update_rates.py index fb5bcfabe..6158210dc 100644 --- a/migrations/versions/0350_update_rates.py +++ b/migrations/versions/0350_update_rates.py @@ -8,15 +8,19 @@ Create Date: 2021-04-01 08:00:24.775338 import uuid from alembic import op +from sqlalchemy import text revision = '0350_update_rates' down_revision = '0349_add_ft_processing_time' def upgrade(): - op.get_bind() - op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) " - "VALUES('{}', '2021-03-31 23:00:00', 0.0160, 'sms')".format(uuid.uuid4())) + conn = op.get_bind() + input_params = { + "id": uuid.uuid4() + } + conn.execute(text("INSERT INTO rates(id, valid_from, rate, notification_type) " + "VALUES(:id, '2021-03-31 23:00:00', 0.0160, 'sms')"), input_params) def downgrade():