"""rename request creator

Revision ID: 05d6272bdb43
Revises: 77b065750596
Create Date: 2018-08-07 20:21:22.559283

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '05d6272bdb43'
down_revision = '77b065750596'
branch_labels = None
depends_on = None


def upgrade():
    db = op.get_bind()

    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('requests', sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=True))
    op.create_foreign_key('requests_user_id_fk', 'requests', 'users', ['user_id'], ['id'])
    # ### end Alembic commands ###

    db.execute("UPDATE requests SET user_id = creator")

    op.alter_column('requests', 'user_id', nullable=False)
    op.drop_column('requests', 'creator')



def downgrade():
    db = op.get_bind()

    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('requests', sa.Column('creator', postgresql.UUID(), autoincrement=False, nullable=True))
    op.drop_constraint('requests_user_id_fk', 'requests', type_='foreignkey')
    # ### end Alembic commands ###

    db.execute("UPDATE requests SET creator = user_id")
    op.drop_column('requests', 'user_id')
