<filename>services/traction/api/db/migrations/versions/v1_invitations_12a486c50ac3.py
"""v1-invitations

Revision ID: 12a486c50ac3
Revises: <KEY>4
Create Date: 2022-05-04 13:00:33.959764

"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
from sqlalchemy.dialects import postgresql

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "connection_invitation",
        sa.Column(
            "connection_invitation_id",
            postgresql.UUID(as_uuid=True),
            server_default=sa.text("gen_random_uuid()"),
            nullable=False,
        ),
        sa.Column("tags", postgresql.ARRAY(sa.String()), nullable=True),
        sa.Column("connection", postgresql.JSON(astext_type=sa.Text()), nullable=True),
        sa.Column("invitation", postgresql.JSON(astext_type=sa.Text()), nullable=True),
        sa.Column(
            "created_at",
            postgresql.TIMESTAMP(),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            postgresql.TIMESTAMP(),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.Column("tenant_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("state", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("reusable", sa.Boolean(), nullable=False),
        sa.Column("public", sa.Boolean(), nullable=False),
        sa.Column("deleted", sa.Boolean(), nullable=False),
        sa.Column("connection_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column(
            "connection_alias", sqlmodel.sql.sqltypes.AutoString(), nullable=False
        ),
        sa.Column("invitation_url", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("invitation_key", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
        sa.ForeignKeyConstraint(
            ["tenant_id"],
            ["tenant.id"],
        ),
        sa.PrimaryKeyConstraint("connection_invitation_id"),
    )
    op.create_index(
        op.f("ix_connection_invitation_name"),
        "connection_invitation",
        ["name"],
        unique=False,
    )
    op.create_index(
        op.f("ix_connection_invitation_invitation_key"),
        "connection_invitation",
        ["invitation_key"],
        unique=False,
    )
    op.create_index(
        op.f("ix_connection_invitation_tenant_id"),
        "connection_invitation",
        ["tenant_id"],
        unique=False,
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_connection_invitation_tenant_id"), table_name="connection_invitation"
    )
    op.drop_index(
        op.f("ix_connection_invitation_name"), table_name="connection_invitation"
    )
    op.drop_table("connection_invitation")
    # ### end Alembic commands ###
