"""Add discussion schemas

Revision ID: aa1a6be51104
Revises: 5822bc51497e
Create Date: 2022-07-26 07:25:58.059677

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "aa1a6be51104"
down_revision = "5822bc51497e"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "discussion_boards",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "discussion_threads",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("board_id", sa.Integer(), nullable=False),
        sa.Column("author_id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["author_id"],
            ["users.id"],
        ),
        sa.ForeignKeyConstraint(
            ["board_id"],
            ["discussion_boards.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_discussion_threads_author_id"),
        "discussion_threads",
        ["author_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_discussion_threads_board_id"),
        "discussion_threads",
        ["board_id"],
        unique=False,
    )
    op.create_table(
        "discussion_posts",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("board_id", sa.Integer(), nullable=False),
        sa.Column("thread_id", sa.Integer(), nullable=False),
        sa.Column("author_id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.Column("content", sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(
            ["author_id"],
            ["users.id"],
        ),
        sa.ForeignKeyConstraint(
            ["board_id"],
            ["discussion_boards.id"],
        ),
        sa.ForeignKeyConstraint(
            ["thread_id"],
            ["discussion_threads.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_discussion_posts_author_id"),
        "discussion_posts",
        ["author_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_discussion_posts_board_id"),
        "discussion_posts",
        ["board_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_discussion_posts_thread_id"),
        "discussion_posts",
        ["thread_id"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_discussion_posts_thread_id"), table_name="discussion_posts")
    op.drop_index(op.f("ix_discussion_posts_board_id"), table_name="discussion_posts")
    op.drop_index(op.f("ix_discussion_posts_author_id"), table_name="discussion_posts")
    op.drop_table("discussion_posts")
    op.drop_index(
        op.f("ix_discussion_threads_board_id"), table_name="discussion_threads"
    )
    op.drop_index(
        op.f("ix_discussion_threads_author_id"), table_name="discussion_threads"
    )
    op.drop_table("discussion_threads")
    op.drop_table("discussion_boards")
    # ### end Alembic commands ###
