"""Add hidden fields and permission Revision ID: 05da2ac3bd49 Revises: 331500ad355b Create Date: 2017-09-03 21:48:30.850960 """ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision = '05da2ac3bd49' down_revision = '331500ad355b' branch_labels = () depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('groups', schema=None) as batch_op: batch_op.add_column( sa.Column('viewhidden', sa.Boolean(), nullable=True) ) with op.batch_alter_table('groups', schema=None) as batch_op: groups = sa.sql.table( 'groups', sa.sql.column('viewhidden'), sa.sql.column('admin'), sa.sql.column('super_mod'), sa.sql.column('mod') ) batch_op.execute( groups.update().where( sa.or_( groups.c.admin == True, groups.c.mod == True, groups.c.super_mod == True ) ).values(viewhidden=True) ) batch_op.execute( groups.update().where(sa.and_( groups.c.admin != True, groups.c.mod != True, groups.c.super_mod != True )).values(viewhidden=False) ) batch_op.alter_column('viewhidden', existing_type=sa.Boolean(), nullable=False) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### with op.batch_alter_table('groups', schema=None) as batch_op: batch_op.drop_column('viewhidden') # ### end Alembic commands ###