Files
notifications-api/migrations/versions/0347_add_dvla_volumes_template.py

97 lines
3.3 KiB
Python
Raw Normal View History

"""
Revision ID: 0347_add_dvla_volumes_template
Revises: 0346_notify_number_sms_sender
Create Date: 2021-02-15 15:36:34.654275
"""
2024-04-01 15:12:33 -07:00
import os
from datetime import datetime
from alembic import op
from flask import current_app
2023-07-18 08:28:48 -07:00
from sqlalchemy import text
from app.utils import utc_now
2023-08-29 14:54:30 -07:00
revision = "0347_add_dvla_volumes_template"
down_revision = "0346_notify_number_sms_sender"
email_template_id = "11fad854-fd38-4a7c-bd17-805fb13dfc12"
2023-08-29 14:54:30 -07:00
environment = os.environ["NOTIFY_ENVIRONMENT"]
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)
2023-11-17 09:47:32 -05:00
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
2023-07-18 08:28:48 -07:00
: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)
2023-11-17 09:47:32 -05:00
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id,
2023-07-18 08:28:48 -07:00
:subject, :user_id, 1, :process_type, false)
2023-11-17 09:47:32 -05:00
"""
2023-08-29 14:54:30 -07:00
email_template_content = "\n".join(
[
"((total_volume)) letters (((total_sheets)) sheets) sent via Notify are coming in today''s batch. These include: ",
"",
"((first_class_volume)) first class letters (((first_class_sheets)) sheets).",
"((second_class_volume)) second class letters (((second_class_sheets)) sheets).",
"((international_volume)) international letters (((international_sheets)) sheets).",
"",
"Thanks",
"",
"GOV.UK Notify team",
"https://www.gov.uk/notify",
]
)
email_template_name = "Notify daily letter volumes"
email_template_subject = "Notify letter volume for ((date)): ((total_volume)) letters, ((total_sheets)) sheets"
2023-07-18 08:28:48 -07:00
input_params = {
"template_id": email_template_id,
"template_name": email_template_name,
2023-08-29 14:54:30 -07:00
"template_type": "email",
"time_now": utc_now(),
2023-07-18 08:28:48 -07:00
"content": email_template_content,
2023-08-29 14:54:30 -07:00
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
2023-07-18 08:28:48 -07:00
"subject": email_template_subject,
2023-08-29 14:54:30 -07:00
"user_id": current_app.config["NOTIFY_USER_ID"],
"process_type": "normal",
2023-07-18 08:28:48 -07:00
}
conn = op.get_bind()
2023-08-29 14:54:30 -07:00
conn.execute(text(template_history_insert), input_params)
2023-08-29 14:54:30 -07:00
conn.execute(text(template_insert), input_params)
def downgrade():
2023-07-18 08:28:48 -07:00
conn = op.get_bind()
2023-08-29 14:54:30 -07:00
input_params = {"template_id": email_template_id}
if environment not in ["live", "production"]:
2023-08-29 14:54:30 -07:00
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
)