merge from main

This commit is contained in:
Kenneth Kehl
2023-07-26 15:51:50 -07:00
100 changed files with 1319 additions and 1780 deletions

View File

@@ -8,6 +8,7 @@ Create Date: 2023-01-10 11:42:25.633265
import json
from alembic import op
import sqlalchemy as sa
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
from flask import current_app
@@ -16,38 +17,33 @@ down_revision = '0381_encrypted_column_types'
def upgrade():
update = """
UPDATE {} SET name = '{}', template_type = '{}', content = '{}', subject = '{}'
WHERE id = '{}'
update_t = """
UPDATE templates SET name = :name, template_type = :type, content = :content, subject = :subject
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:
data = json.load(f)
for d in data:
for table_name in 'templates', 'templates_history':
op.execute(
update.format(
table_name,
d['name'],
d['type'],
'\n'.join(d['content']),
d.get('subject'),
d['id']
)
)
input_params = {
'name': d['name'],
'type': d['type'],
'content': '\n'.join(d['content']),
'subject': d.get('subject'),
'id': d['id']
}
conn.execute(
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():
# with associated code changes, edits to templates should no longer be made via migration.