"""Added token table

Revision ID: 25e4ec3cea32
Revises:
Create Date: 2023-11-14 18:52:16.906404

"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "25e4ec3cea32"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "rooms",
        sa.Column("nameOrAlias", sa.String(length=255), nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
        ),
        sa.PrimaryKeyConstraint("nameOrAlias"),
    )
    op.create_table(
        "tokens",
        sa.Column("token", sa.String(length=50), nullable=False),
        sa.Column("owner", sa.String(length=255), nullable=False),
        sa.Column("create_dm", sa.Boolean(), nullable=False),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
        ),
        sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
        sa.PrimaryKeyConstraint("token"),
    )
    op.create_table(
        "accepted",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user", sa.String(length=255), nullable=False),
        sa.Column("token_id", sa.String(length=50), nullable=True),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("(CURRENT_TIMESTAMP)"),
            nullable=True,
        ),
        sa.ForeignKeyConstraint(
            ["token_id"],
            ["tokens.token"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "token_room_associations",
        sa.Column("token", sa.String(length=50), nullable=False),
        sa.Column("room", sa.String(length=255), nullable=False),
        sa.ForeignKeyConstraint(
            ["room"],
            ["rooms.nameOrAlias"],
        ),
        sa.ForeignKeyConstraint(
            ["token"],
            ["tokens.token"],
        ),
        sa.PrimaryKeyConstraint("token", "room"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("token_room_associations")
    op.drop_table("accepted")
    op.drop_table("tokens")
    op.drop_table("rooms")
    # ### end Alembic commands ###
