more files

This commit is contained in:
Kenneth Kehl
2023-07-18 08:28:48 -07:00
parent 9e2a6dafcf
commit 1aaaf6235a
5 changed files with 197 additions and 220 deletions

View File

@@ -9,7 +9,7 @@ from datetime import datetime
from alembic import op
from flask import current_app
from sqlalchemy import text
revision = '0294_add_verify_reply_to'
down_revision = '0293_drop_complaint_fk'
@@ -21,12 +21,15 @@ def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false)
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
:subject, :user_id, 1, :process_type, false)
"""
email_template_content = '\n'.join([
@@ -48,48 +51,35 @@ def upgrade():
email_template_name = "Verify email reply-to address for a service"
email_template_subject = 'Your GOV.UK Notify reply-to email address'
op.execute(
template_history_insert.format(
email_template_id,
email_template_name,
'email',
datetime.utcnow(),
email_template_content,
current_app.config['NOTIFY_SERVICE_ID'],
email_template_subject,
current_app.config['NOTIFY_USER_ID'],
'normal'
)
input_params = {
"template_id": email_template_id,
"template_name": email_template_name,
"template_type": 'email',
"time_now": datetime.utcnow(),
"content": email_template_content,
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
"subject": email_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(
email_template_id,
email_template_name,
'email',
datetime.utcnow(),
email_template_content,
current_app.config['NOTIFY_SERVICE_ID'],
email_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(email_template_id, False, datetime.utcnow(), current_app.config['NOTIFY_USER_ID'])
# )
)
def downgrade():
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(email_template_id))
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(email_template_id))
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(email_template_id))
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(email_template_id))
op.execute("DELETE FROM templates WHERE id = '{}'".format(email_template_id))
conn = op.get_bind()
input_params = {
"template_id": email_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)