"""init table
Revision ID: a7841c3b04d0
Revises: 1ff5763812c1
Create Date: 2021-11-15 18:16:30.192984
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic
revision = "a7841c3b04d0"
down_revision = "1ff5763812c1"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index("ix_users_username", table_name="users")
    op.drop_table("users")
    op.drop_index("ix_experiments_name", table_name="experiments")
    op.drop_index("ix_experiments_owner", table_name="experiments")
    op.drop_table("experiments")
    op.drop_index("ix_whitelist_experiment_id", table_name="whitelist")
    op.drop_table("whitelist")
    op.drop_table("collaborators")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "collaborators",
        sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("peer_public_key", postgresql.BYTEA(), autoincrement=False, nullable=False),
        sa.Column("user_id", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column("whitelist_item_id", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("id", name="collaborators_pkey"),
    )
    op.create_table(
        "whitelist",
        sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("experiment_id", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column("user_id", sa.INTEGER(), autoincrement=False, nullable=False),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("id", name="whitelist_pkey"),
    )
    op.create_index("ix_whitelist_experiment_id", "whitelist", ["experiment_id"], unique=False)
    op.create_table(
        "experiments",
        sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("name", sa.TEXT(), autoincrement=False, nullable=False),
        sa.Column("owner", sa.TEXT(), autoincrement=False, nullable=False),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column("coordinator_ip", sa.VARCHAR(length=50), autoincrement=False, nullable=True),
        sa.Column("coordinator_port", sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column("auth_server_public_key", postgresql.BYTEA(), autoincrement=False, nullable=True),
        sa.Column("auth_server_private_key", postgresql.BYTEA(), autoincrement=False, nullable=True),
        sa.PrimaryKeyConstraint("id", name="experiments_pkey"),
    )
    op.create_index("ix_experiments_owner", "experiments", ["owner"], unique=False)
    op.create_index("ix_experiments_name", "experiments", ["name"], unique=False)
    op.create_table(
        "users",
        sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("username", sa.TEXT(), autoincrement=False, nullable=True),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            postgresql.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            autoincrement=False,
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("id", name="users_pkey"),
    )
    op.create_index("ix_users_username", "users", ["username"], unique=True)
    # ### end Alembic commands ###
