diff --git a/migrations/versions/0075_create_rates_table.py b/migrations/versions/0075_create_rates_table.py index 056330b79..5b05966ac 100644 --- a/migrations/versions/0075_create_rates_table.py +++ b/migrations/versions/0075_create_rates_table.py @@ -9,6 +9,8 @@ Create Date: 2017-04-24 15:12:18.907629 # revision identifiers, used by Alembic. import uuid +from sqlalchemy import text + revision = '0075_create_rates_table' down_revision = '0074_update_sms_rate' @@ -28,11 +30,17 @@ def upgrade(): op.create_index(op.f('ix_rates_notification_type'), 'rates', ['notification_type'], unique=False) - op.get_bind() - op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) " - "VALUES('{}', '2016-05-18 00:00:00', 1.65, 'sms')".format(uuid.uuid4())) - op.execute("INSERT INTO rates(id, valid_from, rate, notification_type) " - "VALUES('{}', '2017-04-01 00:00:00', 1.58, '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, '2016-05-18 00:00:00', 1.65, 'sms')"), input_params) + input_params = { + "id": uuid.uuid4() + } + conn.execute(text("INSERT INTO rates(id, valid_from, rate, notification_type) " + "VALUES(:id, '2017-04-01 00:00:00', 1.58, 'sms')"), input_params) def downgrade(): diff --git a/migrations/versions/0082_add_golive_template.py b/migrations/versions/0082_add_golive_template.py index 42fad4bee..137bfd7d3 100644 --- a/migrations/versions/0082_add_golive_template.py +++ b/migrations/versions/0082_add_golive_template.py @@ -13,6 +13,7 @@ from flask import current_app from alembic import op import sqlalchemy as sa +from sqlalchemy import text revision = '0082_add_go_live_template' down_revision = '0081_noti_status_as_enum' @@ -23,11 +24,11 @@ template_id = '618185c6-3636-49cd-b7d2-6f6f5eb3bdde' def upgrade(): template_insert = """ INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}') + VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1, :process_type) """ template_history_insert = """ INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}') + VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1, :process_type) """ template_content = """Hi ((name)), @@ -85,47 +86,33 @@ GOV.UK Notify team template_name = "Automated \"You''re now live\" message" template_subject = '((service name)) is now live on GOV.UK Notify' - op.execute( - template_history_insert.format( - template_id, - template_name, - 'email', - datetime.utcnow(), - template_content, - current_app.config['NOTIFY_SERVICE_ID'], - template_subject, - current_app.config['NOTIFY_USER_ID'], - 'normal' - ) + input_params = { + 'template_id': template_id, + 'template_name': template_name, + 'template_type': 'email', + 'time_now': datetime.utcnow(), + 'content': template_content, + 'notify_service_id': current_app.config['NOTIFY_SERVICE_ID'], + 'subject': template_subject, + 'user_id': current_app.config['NOTIFY_USER_ID'], + 'process_type': 'normal' + } + conn = op.get_bind() + conn.execute( + text(template_history_insert), input_params ) - op.execute( - template_insert.format( - template_id, - template_name, - 'email', - datetime.utcnow(), - template_content, - current_app.config['NOTIFY_SERVICE_ID'], - template_subject, - current_app.config['NOTIFY_USER_ID'], - 'normal' - ) + conn.execute( + text(template_insert), input_params ) -# 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(), current_app.config['NOTIFY_USER_ID']) - # ) - 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 = '{}'"), input_params) + conn.execute(text("DELETE FROM notification_history WHERE template_id = '{}'"), input_params) + conn.execute(text("DELETE FROM templates_history WHERE id = '{}'"), input_params) + conn.execute(text("DELETE FROM templates WHERE id = '{}'"), input_params) diff --git a/migrations/versions/0103_add_historical_redact.py b/migrations/versions/0103_add_historical_redact.py index 8d073bbd3..aa6b5e2c7 100644 --- a/migrations/versions/0103_add_historical_redact.py +++ b/migrations/versions/0103_add_historical_redact.py @@ -7,6 +7,8 @@ Create Date: 2017-06-29 12:44:16.815039 """ # revision identifiers, used by Alembic. +from sqlalchemy import text + revision = '0103_add_historical_redact' down_revision = 'db6d9d9f06bc' @@ -15,8 +17,14 @@ 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_id": current_app.config['NOTIFY_USER_ID'] + } + conn.execute( + text( """ INSERT INTO template_redacted ( @@ -29,12 +37,12 @@ def upgrade(): templates.id, false, now(), - '{notify_user}' + :notify_user_id 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/0134_add_email_2fa_template_.py b/migrations/versions/0134_add_email_2fa_template_.py index fcb51840f..3d1b2e8a0 100644 --- a/migrations/versions/0134_add_email_2fa_template_.py +++ b/migrations/versions/0134_add_email_2fa_template_.py @@ -9,7 +9,7 @@ from datetime import datetime from alembic import op from flask import current_app - +from sqlalchemy import text revision = '0134_add_email_2fa_template' down_revision = '0133_set_services_sms_prefix' @@ -20,11 +20,11 @@ template_id = '299726d2-dba6-42b8-8209-30e1d66ea164' def upgrade(): template_insert = """ INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}') + VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1,:process_type) """ template_history_insert = """ INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type) - VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}') + VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1,:process_type) """ template_content = '\n'.join([ @@ -37,48 +37,35 @@ def upgrade(): template_name = "Notify email verify code" template_subject = 'Sign in to GOV.UK Notify' - op.execute( - template_history_insert.format( - template_id, - template_name, - 'email', - datetime.utcnow(), - template_content, - current_app.config['NOTIFY_SERVICE_ID'], - template_subject, - current_app.config['NOTIFY_USER_ID'], - 'normal' - ) + input_params = { + 'template_id': template_id, + 'template_name': template_name, + 'template_type': 'email', + 'time_now': datetime.utcnow(), + 'content': template_content, + 'notify_service_id': current_app.config['NOTIFY_SERVICE_ID'], + 'subject': template_subject, + 'user_id': current_app.config['NOTIFY_USER_ID'], + 'process_type': 'normal' + } + conn = op.get_bind() + + conn.execute( + text(template_history_insert), input_params ) - op.execute( - template_insert.format( - template_id, - template_name, - 'email', - datetime.utcnow(), - template_content, - current_app.config['NOTIFY_SERVICE_ID'], - template_subject, - current_app.config['NOTIFY_USER_ID'], - 'normal' - ) + conn.execute( + text(template_insert), input_params ) -# 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(), current_app.config['NOTIFY_USER_ID']) - # ) - 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 template_redacted 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)) + conn = op.get_bind() + input_params = { + 'template_id': template_id + } + 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 template_redacted 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 new file mode 100644 index 000000000..46ec36639 --- /dev/null +++ b/migrations/versions/d2db89558026.py @@ -0,0 +1,21 @@ +""" + +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