From 7276ed0e5aa912c04fd6c7886c3b7b19a2abb25c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 18 Jul 2023 10:27:47 -0700 Subject: [PATCH] more files --- .../versions/0028_fix_reg_template_history.py | 22 ++++++-- migrations/versions/0041_email_template_.py | 39 +++++++------ .../versions/0057_change_email_template.py | 55 +++++++++---------- migrations/versions/d2db89558026.py | 21 ------- 4 files changed, 62 insertions(+), 75 deletions(-) delete mode 100644 migrations/versions/d2db89558026.py diff --git a/migrations/versions/0028_fix_reg_template_history.py b/migrations/versions/0028_fix_reg_template_history.py index 88faac00e..a0faec953 100644 --- a/migrations/versions/0028_fix_reg_template_history.py +++ b/migrations/versions/0028_fix_reg_template_history.py @@ -9,6 +9,8 @@ Create Date: 2016-06-13 11:04:15.888017 # revision identifiers, used by Alembic. from datetime import datetime +from sqlalchemy import text + revision = '0028_fix_reg_template_history' down_revision = '0027_update_provider_rates' @@ -25,14 +27,24 @@ def upgrade(): template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1) + VALUES (:id, :name, :type, :time_now, :content, False, :service_id, :subject, :user_id, 1) """ email_verification_content = \ """Hi ((name)),\n\nTo complete your registration for GOV.UK Notify please click the link below\n\n((url))""" - op.execute(template_history_insert.format('ece42649-22a8-4d06-b87f-d52d5d3f0a27', - 'Notify email verification code', 'email', - datetime.utcnow(), email_verification_content, service_id, - 'Confirm GOV.UK Notify registration', user_id)) + + input_params = { + "id": 'ece42649-22a8-4d06-b87f-d52d5d3f0a27', + "name": 'Notify email verification code', + "type": "email", + "time_now": datetime.utcnow(), + "content": email_verification_content, + "service_id": service_id, + "subject": 'Confirm GOV.UK Notify registration', + "user_id": user_id + } + conn = op.get_bind() + conn.execute(text(template_history_insert), input_params) + def downgrade(): ### commands auto generated by Alembic - please adjust! ### diff --git a/migrations/versions/0041_email_template_.py b/migrations/versions/0041_email_template_.py index c80c21ee7..57bdf6d31 100644 --- a/migrations/versions/0041_email_template_.py +++ b/migrations/versions/0041_email_template_.py @@ -9,6 +9,8 @@ Create Date: 2016-07-07 16:02:06.241769 # revision identifiers, used by Alembic. from datetime import datetime +from sqlalchemy import text + revision = '0041_email_template' down_revision = '0040_adjust_mmg_provider_rate' @@ -22,11 +24,13 @@ def upgrade(): template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1) + VALUES (:template_id, :template_name, :template_type, :time_now, + :content, False, :service_id, :subject, :user_id, 1) """ template_insert = """INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1) + VALUES (:template_id, :template_name, :template_type, :time_now, + :content, False, :service_id, :subject, :user_id, 1) """ content = """You already have a GOV.UK Notify account with this email address. @@ -37,25 +41,20 @@ If you’ve forgotten your password, you can reset it here: ((forgot_password_ur If you didn’t try to register for a GOV.UK Notify account recently, please let us know here: ((feedback_url))""" - op.get_bind() - op.execute(template_history_insert.format('0880fbb1-a0c6-46f0-9a8e-36c986381ceb', - 'Your GOV.UK Notify account', 'email', - datetime.utcnow(), content, service_id, - 'Your GOV.UK Notify account', user_id)) - op.execute( - template_insert.format('0880fbb1-a0c6-46f0-9a8e-36c986381ceb', 'Your GOV.UK Notify account', 'email', - datetime.utcnow(), content, service_id, - 'Your GOV.UK Notify account', user_id)) + input_params = { + "template_id": '0880fbb1-a0c6-46f0-9a8e-36c986381ceb', + "template_name": 'Your GOV.UK Notify account', + "template_type": 'email', + "time_now": datetime.utcnow(), + "content": content, + "service_id": service_id, + "subject": 'Your GOV.UK Notify account', + "user_id": user_id + } + conn = op.get_bind() -# If you are copying this migration, please remember about an insert to TemplateRedacted, -# which was not originally included here either by mistake or because it was before TemplateRedacted existed - # op.execute( - # """ - # INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id) - # VALUES ('0880fbb1-a0c6-46f0-9a8e-36c986381ceb', '{}', '{}', '{}') - # ; - # """.format(False, datetime.utcnow(), user_id) - # ) + conn.execute(text(template_history_insert), input_params) + conn.execute(text(template_insert), input_params) def downgrade(): diff --git a/migrations/versions/0057_change_email_template.py b/migrations/versions/0057_change_email_template.py index 31e4a55ef..c31cdae0b 100644 --- a/migrations/versions/0057_change_email_template.py +++ b/migrations/versions/0057_change_email_template.py @@ -9,6 +9,7 @@ Create Date: 2016-10-11 09:24:45.669018 # revision identifiers, used by Alembic. from datetime import datetime from alembic import op +from sqlalchemy import text revision = '0057_change_email_template' down_revision = '0056_minor_updates' @@ -22,11 +23,13 @@ def upgrade(): template_history_insert = """INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1) + VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, + :service_id, :subject, :user_id, 1) """ template_insert = """INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1) + VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, + :service_id, :subject, :user_id, 1) """ template_content = \ """Hi ((name)),\n\nClick this link to confirm your new email address: @@ -35,33 +38,27 @@ def upgrade(): \n\n((feedback_url))""" template_name = 'Confirm new email address' - op.execute(template_history_insert.format(template_id, - template_name, - 'email', - datetime.utcnow(), template_content, - service_id, - template_name, user_id)) - op.execute(template_insert.format(template_id, - template_name, - 'email', - datetime.utcnow(), - template_content, - service_id, - template_name, user_id)) - -# If you are copying this migration, please remember about an insert to TemplateRedacted, -# which was not originally included here either by mistake or because it was before TemplateRedacted existed - # op.execute( - # """ - # INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id) - # VALUES ('{}', '{}', '{}', '{}') - # ; - # """.format(template_id, False, datetime.utcnow(), user_id) - # ) + input_params = { + "template_id": template_id, + "template_name": template_name, + "template_type": 'email', + "time_now": datetime.utcnow(), + "content": template_content, + "service_id": service_id, + "subject": template_name, + "user_id": user_id + } + conn = op.get_bind() + conn.execute(text(template_history_insert), input_params) + conn.execute(text(template_insert), input_params) def downgrade(): - op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id)) - op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id)) - op.execute("delete from templates_history where id = '{}'".format(template_id)) - op.execute("delete from templates where id = '{}'".format(template_id)) + input_params = { + "template_id": template_id + } + conn = op.get_bind() + conn.execute(text("DELETE FROM notifications WHERE template_id = :template_id"), input_params) + conn.execute(text("DELETE FROM notification_history WHERE template_id = :template_id"), input_params) + conn.execute(text("delete from templates_history where id = :template_id"), input_params) + conn.execute(text("delete from templates where id = :template_id"), input_params) diff --git a/migrations/versions/d2db89558026.py b/migrations/versions/d2db89558026.py deleted file mode 100644 index 46ec36639..000000000 --- a/migrations/versions/d2db89558026.py +++ /dev/null @@ -1,21 +0,0 @@ -""" - -Revision ID: d2db89558026 -Revises: 0395_add_total_message_limit -Create Date: 2023-04-27 14:59:39.428607 - -""" -from alembic import op -import sqlalchemy as sa - - -revision = 'd2db89558026' -down_revision = '0397_rename_organisation_2' - - -def upgrade(): - pass - - -def downgrade(): - pass