Files
notifications-api/migrations/versions/0383_update_default_templates.py

52 lines
1.5 KiB
Python
Raw Normal View History

"""
Revision ID: 0383_update_default_templates.py
2023-07-19 15:11:51 -07:00
Revises: 0381_encrypted_column_types
Create Date: 2023-01-10 11:42:25.633265
"""
import json
from alembic import op
import sqlalchemy as sa
2023-07-17 15:04:22 -07:00
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
from flask import current_app
revision = '0383_update_default_templates.py'
2023-07-19 15:11:51 -07:00
down_revision = '0381_encrypted_column_types'
def upgrade():
2023-07-17 15:04:22 -07:00
update_t = """
UPDATE templates SET name = :name, template_type = :type, content = :content, subject = :subject
WHERE id = :id
"""
2023-07-17 15:04:22 -07:00
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:
2023-07-17 15:04:22 -07:00
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
)
def downgrade():
# with associated code changes, edits to templates should no longer be made via migration.
# instead, update the fixture and run the flask command to update.
pass