fd6ed1fd7d1a_add_hidden_by_column.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Add hidden_by column
  2. Revision ID: fd6ed1fd7d1a
  3. Revises: 63eabbb0e837
  4. Create Date: 2017-09-04 13:04:52.973752
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. # revision identifiers, used by Alembic.
  9. revision = 'fd6ed1fd7d1a'
  10. down_revision = '63eabbb0e837'
  11. branch_labels = ()
  12. depends_on = None
  13. def upgrade():
  14. # ### commands auto generated by Alembic - please adjust! ###
  15. with op.batch_alter_table('posts', schema=None) as batch_op:
  16. batch_op.add_column(sa.Column('hidden_by_id', sa.Integer(), nullable=True))
  17. batch_op.create_foreign_key('fk_Post_hidden_by', 'users', ['hidden_by_id'], ['id'])
  18. with op.batch_alter_table('topics', schema=None) as batch_op:
  19. batch_op.add_column(sa.Column('hidden_by_id', sa.Integer(), nullable=True))
  20. batch_op.create_foreign_key('fk_Topic_hidden_by', 'users', ['hidden_by_id'], ['id'])
  21. # ### end Alembic commands ###
  22. def downgrade():
  23. # ### commands auto generated by Alembic - please adjust! ###
  24. with op.batch_alter_table('topics', schema=None) as batch_op:
  25. batch_op.drop_constraint('fk_Topic_hidden_by', type_='foreignkey')
  26. batch_op.drop_column('hidden_by_id')
  27. with op.batch_alter_table('posts', schema=None) as batch_op:
  28. batch_op.drop_constraint('fk_Post_hidden_by', type_='foreignkey')
  29. batch_op.drop_column('hidden_by_id')
  30. # ### end Alembic commands ###