| """Add granularity to watching repos |
| |
| Revision ID: d4d2c5aa8a0 |
| Revises: 4255158a6913 |
| Create Date: 2017-04-28 14:39:09.746953 |
| |
| """ |
| |
| |
| revision = 'd4d2c5aa8a0' |
| down_revision = '4255158a6913' |
| |
| from alembic import op |
| import sqlalchemy as sa |
| |
| |
| |
| watcher_helper = sa.Table( |
| 'watchers', |
| sa.MetaData(), |
| sa.Column('id', sa.Integer, primary_key=True), |
| sa.Column('watch_issues', sa.Boolean), |
| sa.Column('watch_commits', sa.Boolean), |
| sa.Column('watch', sa.Boolean), |
| ) |
| |
| |
| def upgrade(): |
| op.add_column('watchers', sa.Column('watch_commits', sa.Boolean(), |
| nullable=True)) |
| op.add_column('watchers', sa.Column('watch_issues', sa.Boolean(), |
| nullable=True)) |
| |
| |
| connection = op.get_bind() |
| for watcher in connection.execute(watcher_helper.select()): |
| connection.execute( |
| watcher_helper.update().where( |
| watcher_helper.c.id == watcher.id |
| ).values( |
| watch_issues=watcher.watch, |
| watch_commits=False |
| ) |
| ) |
| |
| with op.batch_alter_table('watchers') as b: |
| |
| b.alter_column('watch_issues', nullable=False) |
| b.alter_column('watch_commits', nullable=False) |
| |
| b.drop_column('watch') |
| |
| |
| def downgrade(): |
| op.add_column('watchers', sa.Column('watch', sa.BOOLEAN(), nullable=True)) |
| |
| |
| |
| connection = op.get_bind() |
| for watcher in connection.execute(watcher_helper.select()): |
| connection.execute( |
| watcher_helper.update().where( |
| watcher_helper.c.id == watcher.id |
| ).values( |
| watch=watcher.watch_issues |
| ) |
| ) |
| |
| with op.batch_alter_table('watchers') as b: |
| |
| b.alter_column('watch', nullable=False) |
| |
| b.drop_column('watch_issues') |
| b.drop_column('watch_commits') |