Blame alembic/versions/6119fbbcc8e9_migrate_current_flag.py
|
Pierre-Yves Chibon |
abcbf7 |
"""Migrate current flag
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
Revision ID: 6119fbbcc8e9
|
|
Pierre-Yves Chibon |
abcbf7 |
Revises: 2b626a16542e
|
|
Pierre-Yves Chibon |
abcbf7 |
Create Date: 2017-11-16 15:11:28.199971
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
"""
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
# revision identifiers, used by Alembic.
|
|
Pierre-Yves Chibon |
abcbf7 |
revision = '6119fbbcc8e9'
|
|
Pierre-Yves Chibon |
abcbf7 |
down_revision = '2b626a16542e'
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
from alembic import op
|
|
Pierre-Yves Chibon |
abcbf7 |
import sqlalchemy as sa
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
def upgrade():
|
|
Pierre-Yves Chibon |
abcbf7 |
""" Add the status column to pull_request_flags and migrate the data.
|
|
Pierre-Yves Chibon |
abcbf7 |
"""
|
|
Pierre-Yves Chibon |
abcbf7 |
op.add_column(
|
|
Pierre-Yves Chibon |
abcbf7 |
'pull_request_flags',
|
|
Pierre-Yves Chibon |
abcbf7 |
sa.Column('status', sa.String(32), nullable=True)
|
|
Pierre-Yves Chibon |
abcbf7 |
)
|
|
Pierre-Yves Chibon |
abcbf7 |
op.execute(
|
|
Pierre-Yves Chibon |
abcbf7 |
'UPDATE pull_request_flags SET status=\'success\' '
|
|
Pierre-Yves Chibon |
abcbf7 |
'WHERE percent in (100, \'100\')')
|
|
Pierre-Yves Chibon |
abcbf7 |
op.execute(
|
|
Pierre-Yves Chibon |
abcbf7 |
'UPDATE pull_request_flags SET status=\'failure\' '
|
|
Pierre-Yves Chibon |
abcbf7 |
'WHERE percent not in (100, \'100\')')
|
|
Pierre-Yves Chibon |
abcbf7 |
op.alter_column(
|
|
Pierre-Yves Chibon |
abcbf7 |
'pull_request_flags', 'status',
|
|
Pierre-Yves Chibon |
abcbf7 |
nullable=False, existing_nullable=True)
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
def downgrade():
|
|
Pierre-Yves Chibon |
abcbf7 |
""" Drop the status column in pull_request_flags.
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
We can't undo the change to the status column since it may now
|
|
Pierre-Yves Chibon |
abcbf7 |
contain empty rows.
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
abcbf7 |
"""
|
|
Pierre-Yves Chibon |
abcbf7 |
op.drop_column('pull_request_flags', 'status')
|