mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Update default templates and add update command (#166)
This commit adds config_files for default data and, using that, creates a new way to update our default templates without needing to hardcode a migration. --------- Co-authored-by: Ryan Ahearn <ryan.ahearn@gsa.gov>
This commit is contained in:
55
migrations/versions/0383_update_default_templates.py
Normal file
55
migrations/versions/0383_update_default_templates.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
|
||||
Revision ID: 0383_update_default_templates.py
|
||||
Revises: 0382_remove_old_providers
|
||||
Create Date: 2023-01-10 11:42:25.633265
|
||||
|
||||
"""
|
||||
import json
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from flask import current_app
|
||||
|
||||
revision = '0383_update_default_templates.py'
|
||||
down_revision = '0382_remove_old_providers'
|
||||
|
||||
|
||||
def upgrade():
|
||||
update = """
|
||||
UPDATE {} SET name = '{}', template_type = '{}', content = '{}', subject = '{}'
|
||||
WHERE id = '{}'
|
||||
"""
|
||||
|
||||
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']
|
||||
)
|
||||
)
|
||||
|
||||
# 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.
|
||||
# instead, update the fixture and run the flask command to update.
|
||||
pass
|
||||
Reference in New Issue
Block a user