Add comment reminder to add template redacted when creating a template

through a migration.
Also fix the downgrades so they delete everything that needs deleting.
This commit is contained in:
Pea Tyczynska
2019-06-26 18:33:24 +01:00
parent bd3594b2a9
commit 9782b08982
7 changed files with 105 additions and 10 deletions

View File

@@ -20,12 +20,12 @@ template_id = '203566f0-d835-47c5-aa06-932439c86573'
def upgrade():
template_insert = """
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false)
"""
template_history_insert = """
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
created_by_id, version, process_type, hidden)
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false)
"""
@@ -72,11 +72,24 @@ def upgrade():
)
)
# If you are copying this migration, please remember about an insert to TemplateRedacted,
# which was not originally included here either by mistake or because it was before TemplateRedacted existed
# op.execute(
# """
# INSERT INTO template_redacted (template_id, redact_personalisation, updated_at, updated_by_id)
# VALUES ('{}', '{}', '{}', '{}')
# ;
# """.format(template_id, False, datetime.utcnow(), current_app.config['NOTIFY_USER_ID'])
# )
# clean up constraints on org_to_service - service_id-org_id constraint is redundant
op.drop_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', type_='unique')
def downgrade():
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id))
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id))
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template_id))
op.execute("DELETE FROM templates WHERE id = '{}'".format(template_id))
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(template_id))
op.create_unique_constraint('organisation_to_service_service_id_organisation_id_key', 'organisation_to_service', ['service_id', 'organisation_id'])