2023-02-03 10:11:21 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Revision ID: 0383_update_default_templates.py
|
2023-07-19 15:11:51 -07:00
|
|
|
Revises: 0381_encrypted_column_types
|
2023-02-03 10:11:21 -05:00
|
|
|
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
|
2023-02-03 10:11:21 -05:00
|
|
|
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'
|
2023-02-03 10:11:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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-02-03 10:11:21 -05:00
|
|
|
"""
|
|
|
|
|
|
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()
|
2023-02-03 10:11:21 -05:00
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
2023-02-03 10:11:21 -05:00
|
|
|
|
|
|
|
|
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
|