<reponame>delta-reporter/delta-core<filename>migrations/versions/636c5796f80a_.py
"""empty message

Revision ID: 636c5796f80a
Revises:
Create Date: 2020-03-25 16:39:34.344107

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import orm
import models


# revision identifiers, used by Alembic.
revision = "<KEY>"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "launch_status",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "project_status",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "test_resolution",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "test_run_status",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "test_status",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "test_suite_status",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "project",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("project_status_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["project_status_id"], ["project_status.id"],),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "launch",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("launch_status_id", sa.Integer(), nullable=False),
        sa.Column("project_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["launch_status_id"], ["launch_status.id"],),
        sa.ForeignKeyConstraint(["project_id"], ["project.id"],),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "test_suite",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("test_type", sa.String(length=50), nullable=False),
        sa.Column("project_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["project_id"], ["project.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "test",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=300), nullable=False),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("test_suite_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["test_suite_id"], ["test_suite.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "test_run",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("start_datetime", sa.DateTime(), nullable=True),
        sa.Column("end_datetime", sa.DateTime(), nullable=True),
        sa.Column("test_type", sa.String(length=100), nullable=False),
        sa.Column("test_run_status_id", sa.Integer(), nullable=False),
        sa.Column("launch_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["launch_id"], ["launch.id"],),
        sa.ForeignKeyConstraint(["test_run_status_id"], ["test_run_status.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "test_suite_history",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("data", sa.JSON(), nullable=True),
        sa.Column("start_datetime", sa.DateTime(), nullable=True),
        sa.Column("end_datetime", sa.DateTime(), nullable=True),
        sa.Column("test_suite_status_id", sa.Integer(), nullable=False),
        sa.Column("test_run_id", sa.Integer(), nullable=False),
        sa.Column("test_suite_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["test_run_id"], ["test_run.id"],),
        sa.ForeignKeyConstraint(["test_suite_id"], ["test_suite.id"],),
        sa.ForeignKeyConstraint(["test_suite_status_id"], ["test_suite_status.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "test_history",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("start_datetime", sa.DateTime(), nullable=True),
        sa.Column("end_datetime", sa.DateTime(), nullable=True),
        sa.Column("trace", sa.String(), nullable=True),
        sa.Column("file", sa.String(length=2000), nullable=True),
        sa.Column("message", sa.String(length=2000), nullable=True),
        sa.Column("error_type", sa.String(length=2000), nullable=True),
        sa.Column("retries", sa.Integer(), nullable=True),
        sa.Column("test_id", sa.Integer(), nullable=False),
        sa.Column("test_status_id", sa.Integer(), nullable=False),
        sa.Column("test_resolution_id", sa.Integer(), nullable=False),
        sa.Column("test_run_id", sa.Integer(), nullable=False),
        sa.Column("test_suite_history_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["test_id"], ["test.id"],),
        sa.ForeignKeyConstraint(["test_resolution_id"], ["test_resolution.id"],),
        sa.ForeignKeyConstraint(["test_run_id"], ["test_run.id"],),
        sa.ForeignKeyConstraint(["test_status_id"], ["test_status.id"],),
        sa.ForeignKeyConstraint(["test_suite_history_id"], ["test_suite_history.id"],),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ###

    # ### initialise statuses tables ###

    bind = op.get_bind()
    session = orm.Session(bind=bind)

    session.add(models.ProjectStatus(name="Active"))
    session.add(models.ProjectStatus(name="Inactive"))
    session.add(models.ProjectStatus(name="Archived"))
    session.add(models.LaunchStatus(name="Failed"))
    session.add(models.LaunchStatus(name="In Process"))
    session.add(models.LaunchStatus(name="Successful"))
    session.add(models.TestSuiteStatus(name="Failed"))
    session.add(models.TestSuiteStatus(name="Successful"))
    session.add(models.TestSuiteStatus(name="Running"))
    session.add(models.TestRunStatus(name="Failed"))
    session.add(models.TestRunStatus(name="Passed"))
    session.add(models.TestRunStatus(name="Running"))
    session.add(models.TestStatus(name="Failed"))
    session.add(models.TestStatus(name="Passed"))
    session.add(models.TestStatus(name="Running"))
    session.add(models.TestStatus(name="Incomplete"))
    session.add(models.TestStatus(name="Skipped"))
    session.add(models.TestResolution(name="Not set"))
    session.add(models.TestResolution(name="Working as expected"))
    session.add(models.TestResolution(name="Test Issue"))
    session.add(models.TestResolution(name="Environment Issue"))
    session.add(models.TestResolution(name="Application Issue"))

    session.commit()


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("test_history")
    op.drop_table("test_suite_history")
    op.drop_table("test_run")
    op.drop_table("test")
    op.drop_table("test_suite")
    op.drop_table("launch")
    op.drop_table("project")
    op.drop_table("test_suite_status")
    op.drop_table("test_status")
    op.drop_table("test_run_status")
    op.drop_table("test_resolution")
    op.drop_table("project_status")
    op.drop_table("launch_status")
    # ### end Alembic commands ###
