"""initial revision

Revision ID: 7d9871ef8afa
Revises:
Create Date: 2019-04-03 15:07:45.770716

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

# revision identifiers, used by Alembic.
revision = '7d9871ef8afa'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("CREATE SCHEMA IF NOT EXISTS dpo")
    op.create_table('data_pipeline_execution',
                    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('created_on', sa.DateTime(timezone=True),
                              server_default=sa.text('now()'), nullable=False),
                    sa.Column('last_updated_on', sa.DateTime(timezone=True),
                              server_default=sa.text('now()'), nullable=False),
                    sa.Column('execution_time_ms', sa.Integer(), nullable=True),
                    sa.Column('status', sa.String(length=50), server_default='INITIALISED', nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    schema='dpo'
                    )
    op.create_table('model_checksum',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('execution_id', postgresql.UUID(as_uuid=True), nullable=False),
                    sa.Column('created_on', sa.DateTime(timezone=True),
                              server_default=sa.text('now()'), nullable=False),
                    sa.Column('last_updated_on', sa.DateTime(timezone=True),
                              server_default=sa.text('now()'), nullable=False),
                    sa.Column('type', sa.String(length=100), nullable=False),
                    sa.Column('name', sa.String(length=250), nullable=False),
                    sa.Column('checksum', sa.String(length=100), nullable=False),
                    sa.ForeignKeyConstraint(['execution_id'], ['dpo.data_pipeline_execution.id'], ),
                    sa.PrimaryKeyConstraint('id'),
                    schema='dpo'
                    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('model_checksum', schema='dpo')
    op.drop_table('data_pipeline_execution', schema='dpo')
    # ### end Alembic commands ###
