more files

This commit is contained in:
Kenneth Kehl
2023-07-17 15:04:22 -07:00
parent d11a797008
commit 9e2a6dafcf
2 changed files with 52 additions and 52 deletions

View File

@@ -10,6 +10,7 @@ Create Date: 2020-09-15 14:17:01.963181
from datetime import datetime from datetime import datetime
from alembic import op from alembic import op
from sqlalchemy import text
revision = '0330_broadcast_invite_email' revision = '0330_broadcast_invite_email'
down_revision = '0329_purge_broadcast_data' down_revision = '0329_purge_broadcast_data'
@@ -37,38 +38,41 @@ https://www.gov.uk/notify
def upgrade(): def upgrade():
insert_query = """ insert_query_t = """
INSERT INTO {} INSERT INTO templates
(id, name, template_type, created_at, content, archived, service_id, (id, name, template_type, created_at, content, archived, service_id,
subject, created_by_id, version, process_type, hidden) subject, created_by_id, version, process_type, hidden)
VALUES VALUES
('{}', '{}', 'email', '{}', '{}', False, '{}', '{}', '{}', 1, 'normal', False) (:template_id, :template_name, 'email', :time_now, :content, False, :service_id, :subject, :user_id, 1, 'normal', False)
""" """
op.execute(insert_query.format( insert_query_th = """
'templates_history', INSERT INTO templates_history
template_id, (id, name, template_type, created_at, content, archived, service_id,
broadcast_invitation_template_name, subject, created_by_id, version, process_type, hidden)
datetime.utcnow(), VALUES
broadcast_invitation_content, (:template_id, :template_name, 'email', :time_now, :content, False, :service_id, :subject, :user_id, 1, 'normal', False)
service_id, """
broadcast_invitation_subject, conn = op.get_bind()
user_id
))
op.execute(insert_query.format( input_params = {
'templates', "template_id": template_id,
template_id, "template_name": broadcast_invitation_template_name,
broadcast_invitation_template_name, "time_now": datetime.utcnow(),
datetime.utcnow(), "content": broadcast_invitation_content,
broadcast_invitation_content, "service_id": service_id,
service_id, "subject": broadcast_invitation_subject,
broadcast_invitation_subject, "user_id": user_id
user_id
)) }
conn.execute(text(insert_query_t), input_params)
conn.execute(text(insert_query_th), input_params)
def downgrade(): def downgrade():
op.get_bind() conn = op.get_bind()
op.execute("delete from templates where id = '{}'".format(template_id)) input_params = {
op.execute("delete from templates_history where id = '{}'".format(template_id)) "template_id": template_id
}
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)

View File

@@ -8,6 +8,7 @@ Create Date: 2023-01-10 11:42:25.633265
import json import json
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from flask import current_app from flask import current_app
@@ -16,38 +17,33 @@ down_revision = '0382_remove_old_providers'
def upgrade(): def upgrade():
update = """ update_t = """
UPDATE {} SET name = '{}', template_type = '{}', content = '{}', subject = '{}' UPDATE templates SET name = :name, template_type = :type, content = :content, subject = :subject
WHERE id = '{}' WHERE id = :id
""" """
update_th = """
UPDATE templates_history SET name = :name, template_type = :type, content = :content, subject = :subject
WHERE id = :id
"""
conn = op.get_bind()
with open(current_app.config['CONFIG_FILES'] + '/templates.json') as f: with open(current_app.config['CONFIG_FILES'] + '/templates.json') as f:
data = json.load(f) data = json.load(f)
for d in data: for d in data:
for table_name in 'templates', 'templates_history': input_params = {
op.execute( 'name': d['name'],
update.format( 'type': d['type'],
table_name, 'content': '\n'.join(d['content']),
d['name'], 'subject': d.get('subject'),
d['type'], 'id': d['id']
'\n'.join(d['content']), }
d.get('subject'), conn.execute(
d['id'] text(update_t), input_params
) )
) conn.execute(
text(update_th), input_params
)
# op.execute(
# """
# INSERT INTO template_redacted
# (
# template_id,
# redact_personalisation,
# updated_at,
# updated_by_id
# ) VALUES ( '{}', false, current_timestamp, '{}' )
# """.format(d['id'], current_app.config['NOTIFY_USER_ID'])
# )
def downgrade(): def downgrade():
# with associated code changes, edits to templates should no longer be made via migration. # with associated code changes, edits to templates should no longer be made via migration.