From 6d1439e39a2970eaa7c98cb0ee69b9b954fd1c16 Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Thu, 22 Feb 2018 11:55:27 +0000 Subject: [PATCH] Add a DB migration to create Templates.hidden column Creates the column as nullable, sets the value to false for all existing templates and template versions and then applies a not-nullable constraint. All future Templates are created with `False` as the default set in SQLAlchemy. --- migrations/versions/0168_hidden_templates.py | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 migrations/versions/0168_hidden_templates.py diff --git a/migrations/versions/0168_hidden_templates.py b/migrations/versions/0168_hidden_templates.py new file mode 100644 index 000000000..23baa5f54 --- /dev/null +++ b/migrations/versions/0168_hidden_templates.py @@ -0,0 +1,29 @@ +""" + +Revision ID: 0168_hidden_templates +Revises: 0167_add_precomp_letter_svc_perm +Create Date: 2018-02-21 14:05:04.448977 + +""" +from alembic import op +import sqlalchemy as sa + + +revision = '0168_hidden_templates' +down_revision = '0167_add_precomp_letter_svc_perm' + + +def upgrade(): + op.add_column('templates', sa.Column('hidden', sa.Boolean(), nullable=True)) + op.add_column('templates_history', sa.Column('hidden', sa.Boolean(), nullable=True)) + + op.execute('UPDATE templates SET hidden=false') + op.execute('UPDATE templates_history SET hidden=false') + + op.alter_column('templates', 'hidden', nullable=False) + op.alter_column('templates_history', 'hidden', nullable=False) + + +def downgrade(): + op.drop_column('templates_history', 'hidden') + op.drop_column('templates', 'hidden')