6119fbbcc8e9_migrate_current_flag.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Migrate current flag
  2. Revision ID: 6119fbbcc8e9
  3. Revises: 2b626a16542e
  4. Create Date: 2017-11-16 15:11:28.199971
  5. """
  6. # revision identifiers, used by Alembic.
  7. revision = '6119fbbcc8e9'
  8. down_revision = '2b626a16542e'
  9. from alembic import op
  10. import sqlalchemy as sa
  11. def upgrade():
  12. """ Add the status column to pull_request_flags and migrate the data.
  13. """
  14. op.add_column(
  15. 'pull_request_flags',
  16. sa.Column('status', sa.String(32), nullable=True)
  17. )
  18. op.execute(
  19. 'UPDATE pull_request_flags SET status=\'success\' '
  20. 'WHERE percent in (100, \'100\')')
  21. op.execute(
  22. 'UPDATE pull_request_flags SET status=\'failure\' '
  23. 'WHERE percent not in (100, \'100\')')
  24. op.alter_column(
  25. 'pull_request_flags', 'status',
  26. nullable=False, existing_nullable=True)
  27. def downgrade():
  28. """ Drop the status column in pull_request_flags.
  29. We can't undo the change to the status column since it may now
  30. contain empty rows.
  31. """
  32. op.drop_column('pull_request_flags', 'status')