From c24edcf38825c694fdc14e5a8e3888f136650506 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 29 Jun 2017 12:54:48 +0100 Subject: [PATCH] add historical redaction data every current template gets a row in the template_redacted table - this inserts one for any template that doesn't already have a row, with redact set to false, the user set to NOTIFY_USER since it was just a script, and the updated_at set to the time the script is run --- .../versions/0103_add_historical_redact.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 migrations/versions/0103_add_historical_redact.py diff --git a/migrations/versions/0103_add_historical_redact.py b/migrations/versions/0103_add_historical_redact.py new file mode 100644 index 000000000..8d073bbd3 --- /dev/null +++ b/migrations/versions/0103_add_historical_redact.py @@ -0,0 +1,43 @@ +"""empty message + +Revision ID: 0103_add_historical_redact +Revises: db6d9d9f06bc +Create Date: 2017-06-29 12:44:16.815039 + +""" + +# revision identifiers, used by Alembic. +revision = '0103_add_historical_redact' +down_revision = 'db6d9d9f06bc' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql +from flask import current_app + +def upgrade(): + op.execute( + """ + INSERT INTO template_redacted + ( + template_id, + redact_personalisation, + updated_at, + updated_by_id + ) + SELECT + templates.id, + false, + now(), + '{notify_user}' + FROM + templates + LEFT JOIN template_redacted on template_redacted.template_id = templates.id + WHERE template_redacted.template_id IS NULL + """.format(notify_user=current_app.config['NOTIFY_USER_ID']) + ) + + +def downgrade(): + # data migration, no downloads + pass