Blame alembic/versions/1cd0a853c697_add_closed_at_field_in_pr.py

Pierre-Yves Chibon bf8489
"""Add closed_at field in PR
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
Revision ID: 1cd0a853c697
Pierre-Yves Chibon bf8489
Revises: 6190226bed0
Pierre-Yves Chibon bf8489
Create Date: 2015-10-02 09:32:15.370676
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
"""
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
# revision identifiers, used by Alembic.
Pierre-Yves Chibon bf8489
revision = '1cd0a853c697'
Pierre-Yves Chibon bf8489
down_revision = '6190226bed0'
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
from alembic import op
Pierre-Yves Chibon bf8489
import sqlalchemy as sa
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
def upgrade():
Pierre-Yves Chibon bf8489
    ''' Add the column closed_at to the table pull_requests.
Pierre-Yves Chibon bf8489
    '''
Pierre-Yves Chibon bf8489
    op.add_column(
Pierre-Yves Chibon bf8489
        'pull_requests',
Pierre-Yves Chibon bf8489
        sa.Column(
Pierre-Yves Chibon bf8489
            'closed_at',
Pierre-Yves Chibon bf8489
            sa.DateTime,
Pierre-Yves Chibon bf8489
            nullable=True,
Pierre-Yves Chibon bf8489
        )
Pierre-Yves Chibon bf8489
    )
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon 940ed3
    op.execute('''UPDATE "pull_requests" SET closed_at=date_created '''
Pierre-Yves Chibon 940ed3
               '''WHERE STATUS != 'Open';''')
Pierre-Yves Chibon 940ed3
Pierre-Yves Chibon bf8489
Pierre-Yves Chibon bf8489
def downgrade():
Pierre-Yves Chibon bf8489
    ''' Remove the column closed_at from the table pull_requests.
Pierre-Yves Chibon bf8489
    '''
Pierre-Yves Chibon bf8489
    op.drop_column('pull_requests', 'closed_at')