"""INITIAL.

Revision ID: dacfb31bf13f
Revises:
Create Date: 2021-05-03 00:34:51.636145

"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "dacfb31bf13f"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ### noqa: ANN201
    op.create_table(
        "homework",
        sa.Column("text", sa.String(), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=False),
        sa.Column("deadline", sa.Interval(), nullable=True),
        sa.Column("teacher_firstname", sa.String(), nullable=True),
        sa.Column("teacher_lastname", sa.String(), nullable=True),
        sa.PrimaryKeyConstraint("text", "created"),
    )
    op.create_table(
        "student",
        sa.Column("first_name", sa.String(), nullable=False),
        sa.Column("last_name", sa.String(), nullable=False),
        sa.PrimaryKeyConstraint("first_name", "last_name"),
    )
    op.create_table(
        "teacher",
        sa.Column("first_name", sa.String(), nullable=False),
        sa.Column("last_name", sa.String(), nullable=False),
        sa.PrimaryKeyConstraint("first_name", "last_name"),
    )
    op.create_table(
        "homeworkresult",
        sa.Column("solution", sa.String(), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=False),
        sa.Column("author_firstname", sa.String(), nullable=True),
        sa.Column("author_lastname", sa.String(), nullable=True),
        sa.Column("homework_text", sa.String(), nullable=True),
        sa.Column("homework_created", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["author_firstname", "author_lastname"],
            ["student.first_name", "student.last_name"],
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["homework_text", "homework_created"],
            ["homework.text", "homework.created"],
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("solution", "created"),
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ### noqa: ANN201
    op.drop_table("homeworkresult")
    op.drop_table("teacher")
    op.drop_table("student")
    op.drop_table("homework")
    # ### end Alembic commands ###
