"""requests

Revision ID: b5b17d465166
Revises: ff1c9c02fa61
Create Date: 2018-07-23 14:58:05.044456

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

# revision identifiers, used by Alembic.
revision = 'b5b17d465166'
down_revision = 'ff1c9c02fa61'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('requests',
    sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
    sa.Column('creator', postgresql.UUID(as_uuid=True), nullable=True),
    sa.Column('time_created', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('body', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('request_status_events',
    sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('uuid_generate_v4()'), nullable=False),
    sa.Column('new_status', sa.String(), nullable=True),
    sa.Column('time_created', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('request_id', postgresql.UUID(as_uuid=True), nullable=True),
    sa.Column('sequence', sa.BigInteger(), nullable=False),
    sa.ForeignKeyConstraint(['request_id'], ['requests.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###

    db = op.get_bind()
    db.execute("CREATE SEQUENCE request_status_events_sequence_seq OWNED BY request_status_events.sequence;")


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('request_status_events')
    op.drop_table('requests')
    # ### end Alembic commands ###
