mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
more files
This commit is contained in:
@@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
revision = '0171_add_org_invite_template'
|
revision = '0171_add_org_invite_template'
|
||||||
down_revision = '0170_hidden_non_nullable'
|
down_revision = '0170_hidden_non_nullable'
|
||||||
@@ -22,12 +22,14 @@ def upgrade():
|
|||||||
template_insert = """
|
template_insert = """
|
||||||
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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 = """
|
template_history_insert = """
|
||||||
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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_content = '\n'.join([
|
template_content = '\n'.join([
|
||||||
@@ -44,52 +46,39 @@ def upgrade():
|
|||||||
template_name = "Notify organisation invitation email"
|
template_name = "Notify organisation invitation email"
|
||||||
template_subject = '((user_name)) has invited you to collaborate on ((organisation_name)) on GOV.UK Notify'
|
template_subject = '((user_name)) has invited you to collaborate on ((organisation_name)) on GOV.UK Notify'
|
||||||
|
|
||||||
op.execute(
|
input_params = {
|
||||||
template_history_insert.format(
|
"template_id": template_id,
|
||||||
template_id,
|
"template_name": template_name,
|
||||||
template_name,
|
"template_type": 'email',
|
||||||
'email',
|
"time_now": datetime.utcnow(),
|
||||||
datetime.utcnow(),
|
"content": template_content,
|
||||||
template_content,
|
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
"subject": template_subject,
|
||||||
template_subject,
|
"user_id": current_app.config['NOTIFY_USER_ID'],
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
"process_type": 'normal'
|
||||||
'normal'
|
}
|
||||||
)
|
conn = op.get_bind()
|
||||||
|
conn.execute(
|
||||||
|
text(template_history_insert), input_params
|
||||||
)
|
)
|
||||||
|
|
||||||
op.execute(
|
conn.execute(
|
||||||
template_insert.format(
|
text(template_insert), input_params
|
||||||
template_id,
|
|
||||||
template_name,
|
|
||||||
'email',
|
|
||||||
datetime.utcnow(),
|
|
||||||
template_content,
|
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
|
||||||
template_subject,
|
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
|
||||||
'normal'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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'])
|
|
||||||
# )
|
|
||||||
|
|
||||||
# clean up constraints on org_to_service - service_id-org_id constraint is redundant
|
# clean up constraints on org_to_service - service_id-org_id constraint is redundant
|
||||||
op.drop_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', type_='unique')
|
op.drop_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', type_='unique')
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id))
|
input_params = {
|
||||||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id))
|
'template_id': 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))
|
conn = op.get_bind()
|
||||||
op.execute("DELETE FROM templates WHERE id = '{}'".format(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)
|
||||||
op.create_unique_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', ['service_id', 'organisation_id'])
|
op.create_unique_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', ['service_id', 'organisation_id'])
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
revision = '0265_add_confirm_edit_templates'
|
revision = '0265_add_confirm_edit_templates'
|
||||||
down_revision = '0264_add_folder_permissions_perm'
|
down_revision = '0264_add_folder_permissions_perm'
|
||||||
@@ -22,12 +22,14 @@ def upgrade():
|
|||||||
template_insert = """
|
template_insert = """
|
||||||
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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 = """
|
template_history_insert = """
|
||||||
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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([
|
email_template_content = '\n'.join([
|
||||||
@@ -48,94 +50,69 @@ def upgrade():
|
|||||||
email_template_name = "Email address changed by service manager"
|
email_template_name = "Email address changed by service manager"
|
||||||
email_template_subject = 'Your GOV.UK Notify email address has changed'
|
email_template_subject = 'Your GOV.UK Notify email address has changed'
|
||||||
|
|
||||||
op.execute(
|
input_params = {
|
||||||
template_history_insert.format(
|
"template_id": email_template_id,
|
||||||
email_template_id,
|
"template_name": email_template_name,
|
||||||
email_template_name,
|
"template_type": 'email',
|
||||||
'email',
|
"time_now": datetime.utcnow(),
|
||||||
datetime.utcnow(),
|
"content": email_template_content,
|
||||||
email_template_content,
|
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
"subject": email_template_subject,
|
||||||
email_template_subject,
|
"user_id": current_app.config['NOTIFY_USER_ID'],
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
"process_type": 'normal'
|
||||||
'normal'
|
}
|
||||||
)
|
conn = op.get_bind()
|
||||||
|
|
||||||
|
conn.execute(
|
||||||
|
text(template_history_insert), input_params
|
||||||
)
|
)
|
||||||
|
|
||||||
op.execute(
|
conn.execute(
|
||||||
template_insert.format(
|
text(template_insert), input_params
|
||||||
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'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
mobile_template_content = """Your mobile number was changed by ((servicemanagername)). Next time you sign in, your US Notify authentication code will be sent to this phone."""
|
mobile_template_content = """Your mobile number was changed by ((servicemanagername)). Next time you sign in, your US Notify authentication code will be sent to this phone."""
|
||||||
|
|
||||||
mobile_template_name = "Phone number changed by service manager"
|
mobile_template_name = "Phone number changed by service manager"
|
||||||
|
|
||||||
op.execute(
|
input_params = {
|
||||||
template_history_insert.format(
|
"template_id": mobile_template_id,
|
||||||
mobile_template_id,
|
"template_name": mobile_template_name,
|
||||||
mobile_template_name,
|
"template_type": 'sms',
|
||||||
'sms',
|
"time_now": datetime.utcnow(),
|
||||||
datetime.utcnow(),
|
"content": mobile_template_content,
|
||||||
mobile_template_content,
|
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
"subject": None,
|
||||||
None,
|
"user_id": current_app.config['NOTIFY_USER_ID'],
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
"process_type": 'normal'
|
||||||
'normal'
|
}
|
||||||
)
|
|
||||||
|
conn.execute(
|
||||||
|
text(template_history_insert), input_params
|
||||||
)
|
)
|
||||||
|
|
||||||
op.execute(
|
conn.execute(
|
||||||
template_insert.format(
|
text(template_insert), input_params
|
||||||
mobile_template_id,
|
|
||||||
mobile_template_name,
|
|
||||||
'sms',
|
|
||||||
datetime.utcnow(),
|
|
||||||
mobile_template_content,
|
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
|
||||||
None,
|
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
|
||||||
'normal'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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'])
|
|
||||||
# )
|
|
||||||
|
|
||||||
# op.execute(
|
|
||||||
# """
|
|
||||||
# INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id)
|
|
||||||
# VALUES ('{}', '{}', '{}', '{}')
|
|
||||||
# ;
|
|
||||||
# """.format(mobile_template_id, False, datetime.utcnow(), current_app.config['NOTIFY_USER_ID'])
|
|
||||||
# )
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(email_template_id))
|
input_params = {
|
||||||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(email_template_id))
|
"template_id": 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))
|
conn = op.get_bind()
|
||||||
op.execute("DELETE FROM templates WHERE id = '{}'".format(email_template_id))
|
|
||||||
|
|
||||||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(mobile_template_id))
|
conn.execute(text("DELETE FROM notifications WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(mobile_template_id))
|
conn.execute(text("DELETE FROM notification_history WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(mobile_template_id))
|
conn.execute(text("DELETE FROM template_redacted WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(mobile_template_id))
|
conn.execute(text("DELETE FROM templates_history WHERE id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM templates WHERE id = '{}'".format(mobile_template_id))
|
conn.execute(text("DELETE FROM templates WHERE id = :template_id"), input_params)
|
||||||
|
|
||||||
|
input_params = {
|
||||||
|
"template_id": mobile_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)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
revision = '0294_add_verify_reply_to'
|
revision = '0294_add_verify_reply_to'
|
||||||
down_revision = '0293_drop_complaint_fk'
|
down_revision = '0293_drop_complaint_fk'
|
||||||
@@ -21,12 +21,15 @@ def upgrade():
|
|||||||
template_insert = """
|
template_insert = """
|
||||||
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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 = """
|
template_history_insert = """
|
||||||
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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([
|
email_template_content = '\n'.join([
|
||||||
@@ -48,48 +51,35 @@ def upgrade():
|
|||||||
email_template_name = "Verify email reply-to address for a service"
|
email_template_name = "Verify email reply-to address for a service"
|
||||||
email_template_subject = 'Your GOV.UK Notify reply-to email address'
|
email_template_subject = 'Your GOV.UK Notify reply-to email address'
|
||||||
|
|
||||||
op.execute(
|
input_params = {
|
||||||
template_history_insert.format(
|
"template_id": email_template_id,
|
||||||
email_template_id,
|
"template_name": email_template_name,
|
||||||
email_template_name,
|
"template_type": 'email',
|
||||||
'email',
|
"time_now": datetime.utcnow(),
|
||||||
datetime.utcnow(),
|
"content": email_template_content,
|
||||||
email_template_content,
|
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
"subject": email_template_subject,
|
||||||
email_template_subject,
|
"user_id": current_app.config['NOTIFY_USER_ID'],
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
"process_type": 'normal'
|
||||||
'normal'
|
}
|
||||||
)
|
conn = op.get_bind()
|
||||||
|
conn.execute(
|
||||||
|
text(template_history_insert), input_params
|
||||||
)
|
)
|
||||||
|
|
||||||
op.execute(
|
conn.execute(
|
||||||
template_insert.format(
|
text(template_insert), input_params
|
||||||
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'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# 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():
|
def downgrade():
|
||||||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(email_template_id))
|
conn = op.get_bind()
|
||||||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(email_template_id))
|
input_params = {
|
||||||
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(email_template_id))
|
"template_id": 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.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)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Create Date: 2019-05-22 16:58:52.929661
|
|||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
revision = '0298_add_mou_signed_receipt'
|
revision = '0298_add_mou_signed_receipt'
|
||||||
down_revision = '0297_template_redacted_fix'
|
down_revision = '0297_template_redacted_fix'
|
||||||
@@ -102,45 +102,66 @@ templates = [
|
|||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
insert = """
|
insert_t = """
|
||||||
INSERT INTO {} (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
created_by_id, version, process_type, hidden)
|
||||||
VALUES ('{}', '{}', '{}', current_timestamp, '{}', False, '{}', '{}', '{}', 1, '{}', false)
|
VALUES (:template_id, :template_name, :template_type, current_timestamp,
|
||||||
|
:content, False, :notify_service_id, :subject, :user_id, 1, :process_type, false)
|
||||||
"""
|
"""
|
||||||
|
insert_th = """
|
||||||
|
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
|
created_by_id, version, process_type, hidden)
|
||||||
|
VALUES (:template_id, :template_name, :template_type, current_timestamp,
|
||||||
|
:content, False, :notify_service_id, :subject, :user_id, 1, :process_type, false)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
for template in templates:
|
for template in templates:
|
||||||
for table_name in 'templates', 'templates_history':
|
input_params = {
|
||||||
op.execute(
|
"template_id": template['id'],
|
||||||
insert.format(
|
"template_name": template['name'],
|
||||||
table_name,
|
"template_type": template['type'],
|
||||||
template['id'],
|
"content": '\n'.join(template['content_lines']),
|
||||||
template['name'],
|
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
template['type'],
|
"subject": template.get('subject'),
|
||||||
'\n'.join(template['content_lines']),
|
"user_id": current_app.config['NOTIFY_USER_ID'],
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
"process_type": 'normal'
|
||||||
template.get('subject'),
|
}
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
conn = op.get_bind()
|
||||||
'normal'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
op.execute(
|
conn.execute(
|
||||||
"""
|
text(insert_t), input_params
|
||||||
|
)
|
||||||
|
|
||||||
|
conn.execute(
|
||||||
|
text(insert_th), input_params
|
||||||
|
)
|
||||||
|
|
||||||
|
input_params = {
|
||||||
|
"template_id": template['id'],
|
||||||
|
"user_id": current_app.config['NOTIFY_USER_ID']
|
||||||
|
}
|
||||||
|
conn.execute(
|
||||||
|
text("""
|
||||||
INSERT INTO template_redacted
|
INSERT INTO template_redacted
|
||||||
(
|
(
|
||||||
template_id,
|
template_id,
|
||||||
redact_personalisation,
|
redact_personalisation,
|
||||||
updated_at,
|
updated_at,
|
||||||
updated_by_id
|
updated_by_id
|
||||||
) VALUES ( '{}', false, current_timestamp, '{}' )
|
) VALUES ( :template_id, false, current_timestamp, :user_id )
|
||||||
""".format(template['id'], current_app.config['NOTIFY_USER_ID'])
|
"""), input_params
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
conn = op.get_bind()
|
||||||
for template in templates:
|
for template in templates:
|
||||||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template['id']))
|
input_params = {
|
||||||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template['id']))
|
"template_id": template['id']
|
||||||
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(template['id']))
|
}
|
||||||
op.execute("DELETE FROM templates WHERE id = '{}'".format(template['id']))
|
conn.execute(text("DELETE FROM notifications WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template['id']))
|
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 WHERE id = :template_id"), input_params)
|
||||||
|
conn.execute(text("DELETE FROM templates_history WHERE id = :template_id"), input_params)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
revision = '0347_add_dvla_volumes_template'
|
revision = '0347_add_dvla_volumes_template'
|
||||||
down_revision = '0346_notify_number_sms_sender'
|
down_revision = '0346_notify_number_sms_sender'
|
||||||
@@ -22,12 +23,15 @@ def upgrade():
|
|||||||
template_insert = """
|
template_insert = """
|
||||||
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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 = """
|
template_history_insert = """
|
||||||
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
|
||||||
created_by_id, version, process_type, hidden)
|
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([
|
email_template_content = '\n'.join([
|
||||||
@@ -46,39 +50,35 @@ def upgrade():
|
|||||||
email_template_name = "Notify daily letter volumes"
|
email_template_name = "Notify daily letter volumes"
|
||||||
email_template_subject = "Notify letter volume for ((date)): ((total_volume)) letters, ((total_sheets)) sheets"
|
email_template_subject = "Notify letter volume for ((date)): ((total_volume)) letters, ((total_sheets)) sheets"
|
||||||
|
|
||||||
op.execute(
|
input_params = {
|
||||||
template_history_insert.format(
|
"template_id": email_template_id,
|
||||||
email_template_id,
|
"template_name": email_template_name,
|
||||||
email_template_name,
|
"template_type": 'email',
|
||||||
'email',
|
"time_now": datetime.utcnow(),
|
||||||
datetime.utcnow(),
|
"content": email_template_content,
|
||||||
email_template_content,
|
"notify_service_id": current_app.config['NOTIFY_SERVICE_ID'],
|
||||||
current_app.config['NOTIFY_SERVICE_ID'],
|
"subject": email_template_subject,
|
||||||
email_template_subject,
|
"user_id": current_app.config['NOTIFY_USER_ID'],
|
||||||
current_app.config['NOTIFY_USER_ID'],
|
"process_type": 'normal'
|
||||||
'normal'
|
}
|
||||||
)
|
conn = op.get_bind()
|
||||||
|
conn.execute(
|
||||||
|
text(template_history_insert), input_params
|
||||||
)
|
)
|
||||||
|
|
||||||
op.execute(
|
conn.execute(
|
||||||
template_insert.format(
|
text(template_insert), input_params
|
||||||
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'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
conn = op.get_bind()
|
||||||
|
input_params = {
|
||||||
|
"template_id": email_template_id
|
||||||
|
}
|
||||||
if environment not in ["live", "production"]:
|
if environment not in ["live", "production"]:
|
||||||
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(email_template_id))
|
conn.execute(text("DELETE FROM notifications WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(email_template_id))
|
conn.execute(text("DELETE FROM notification_history WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(email_template_id))
|
conn.execute(text("DELETE FROM template_redacted WHERE template_id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(email_template_id))
|
conn.execute(text("DELETE FROM templates_history WHERE id = :template_id"), input_params)
|
||||||
op.execute("DELETE FROM templates WHERE id = '{}'".format(email_template_id))
|
conn.execute(text("DELETE FROM templates WHERE id = :template_id"), input_params)
|
||||||
|
|||||||
Reference in New Issue
Block a user