"""add table warnings

Revision ID: 3a40f1143ab4
Revises: 31f9e65aef35
Create Date: 2020-06-01 17:02:20.321207

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "3a40f1143ab4"
down_revision = "31f9e65aef35"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "data_table_warnings",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("table_id", sa.Integer(), nullable=False),
        sa.Column("message", sa.String(length=5000), nullable=True),
        sa.Column(
            "severity",
            sa.Enum("WARNING", "ERROR", name="datatablewarningseverity"),
            nullable=False,
        ),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("created_by", sa.Integer(), nullable=True),
        sa.Column("updated_by", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["created_by"],
            ["user.id"],
            name="data_table_warnings_ibfk_1",
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["table_id"],
            ["data_table.id"],
            name="data_table_warnings_ibfk_2",
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["updated_by"],
            ["user.id"],
            name="data_table_warnings_ibfk_3",
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("data_table_warnings")
    # ### end Alembic commands ###
    conn = op.get_bind()
    if conn.dialect.name == "postgresql":
        op.execute("DROP TYPE datatablewarningseverity")
