Browse Source

Patch migration script to backfill hidden to False

Alec Nikolas Reiter 7 years ago
parent
commit
e9e9350f4f
1 changed files with 17 additions and 3 deletions
  1. 17 3
      migrations/d0ffadc3ea48_add_hidden_columns.py

+ 17 - 3
migrations/d0ffadc3ea48_add_hidden_columns.py

@@ -20,8 +20,8 @@ depends_on = None
 def upgrade():
 def upgrade():
     # ### commands auto generated by Alembic - please adjust! ###
     # ### commands auto generated by Alembic - please adjust! ###
     with op.batch_alter_table('groups', schema=None) as batch_op:
     with op.batch_alter_table('groups', schema=None) as batch_op:
-        batch_op.add_column(sa.Column('makehidden', sa.Boolean(), nullable=True))
-        batch_op.add_column(sa.Column('viewhidden', sa.Boolean(), nullable=True))
+        batch_op.add_column(sa.Column('makehidden', sa.Boolean(), nullable=True, default=False))
+        batch_op.add_column(sa.Column('viewhidden', sa.Boolean(), nullable=True, default=False))
 
 
     with op.batch_alter_table('groups', schema=None) as batch_op:
     with op.batch_alter_table('groups', schema=None) as batch_op:
         groups = sa.sql.table(
         groups = sa.sql.table(
@@ -50,17 +50,31 @@ def upgrade():
         batch_op.alter_column('makehidden', existing_type=sa.Boolean(), nullable=False)
         batch_op.alter_column('makehidden', existing_type=sa.Boolean(), nullable=False)
 
 
     with op.batch_alter_table('posts', schema=None) as batch_op:
     with op.batch_alter_table('posts', schema=None) as batch_op:
-        batch_op.add_column(sa.Column('hidden', sa.Boolean(), nullable=True))
+        batch_op.add_column(sa.Column('hidden', sa.Boolean(), nullable=True, default=False))
         batch_op.add_column(sa.Column('hidden_at', flaskbb.utils.database.UTCDateTime(timezone=True), nullable=True))
         batch_op.add_column(sa.Column('hidden_at', flaskbb.utils.database.UTCDateTime(timezone=True), nullable=True))
         batch_op.add_column(sa.Column('hidden_by_id', sa.Integer(), nullable=True))
         batch_op.add_column(sa.Column('hidden_by_id', sa.Integer(), nullable=True))
         batch_op.create_foreign_key('fk_Post_hidden_by', 'users', ['hidden_by_id'], ['id'])
         batch_op.create_foreign_key('fk_Post_hidden_by', 'users', ['hidden_by_id'], ['id'])
 
 
+    with op.batch_alter_table('posts', schema=None) as batch_op:
+        posts = sa.sql.table('posts', sa.sql.column('hidden'))
+        batch_op.execute(
+            posts.update().values(hidden=False)
+        )
+        batch_op.alter_column('hidden', existing_type=sa.Boolean(), nullable=False)
+
     with op.batch_alter_table('topics', schema=None) as batch_op:
     with op.batch_alter_table('topics', schema=None) as batch_op:
         batch_op.add_column(sa.Column('hidden', sa.Boolean(), nullable=True))
         batch_op.add_column(sa.Column('hidden', sa.Boolean(), nullable=True))
         batch_op.add_column(sa.Column('hidden_at', flaskbb.utils.database.UTCDateTime(timezone=True), nullable=True))
         batch_op.add_column(sa.Column('hidden_at', flaskbb.utils.database.UTCDateTime(timezone=True), nullable=True))
         batch_op.add_column(sa.Column('hidden_by_id', sa.Integer(), nullable=True))
         batch_op.add_column(sa.Column('hidden_by_id', sa.Integer(), nullable=True))
         batch_op.create_foreign_key('fk_Topic_hidden_by', 'users', ['hidden_by_id'], ['id'])
         batch_op.create_foreign_key('fk_Topic_hidden_by', 'users', ['hidden_by_id'], ['id'])
 
 
+    with op.batch_alter_table('topics', schema=None) as batch_op:
+        topics = sa.sql.table('topics', sa.sql.column('hidden'))
+        batch_op.execute(
+            topics.update().values(hidden=False)
+        )
+        batch_op.alter_column('hidden', existing_type=sa.Boolean(), nullable=False)
+
     # ### end Alembic commands ###
     # ### end Alembic commands ###