"""added config type for cache config

Revision ID: 739c7981bdd8
Revises: f5fb392e6b0a
Create Date: 2024-04-26 09:14:37.750514

"""

from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = "739c7981bdd8"
down_revision: Union[str, None] = "f5fb392e6b0a"
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_unique_constraint(None, "chat_history", ["id"])
    op.create_unique_constraint(None, "pipeline_configurations", ["id"])
    op.create_unique_constraint(None, "pipelines", ["id"])
    op.execute("ALTER TYPE configtype ADD VALUE 'CACHE_CONFIG'")

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, "pipelines", type_="unique")
    op.drop_constraint(None, "pipeline_configurations", type_="unique")
    op.drop_constraint(None, "chat_history", type_="unique")
    op.create_table(
        "langchain_pg_collection",
        sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column(
            "cmetadata",
            postgresql.JSON(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column("uuid", sa.UUID(), autoincrement=False, nullable=False),
        sa.PrimaryKeyConstraint("uuid", name="langchain_pg_collection_pkey"),
        postgresql_ignore_search_path=False,
    )
    op.create_table(
        "langchain_pg_embedding",
        sa.Column("collection_id", sa.UUID(), autoincrement=False, nullable=True),
        sa.Column("embedding", sa.NullType(), autoincrement=False, nullable=True),
        sa.Column("document", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column(
            "cmetadata",
            postgresql.JSON(astext_type=sa.Text()),
            autoincrement=False,
            nullable=True,
        ),
        sa.Column("custom_id", sa.VARCHAR(), autoincrement=False, nullable=True),
        sa.Column("uuid", sa.UUID(), autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(
            ["collection_id"],
            ["langchain_pg_collection.uuid"],
            name="langchain_pg_embedding_collection_id_fkey",
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("uuid", name="langchain_pg_embedding_pkey"),
    )
    # ### end Alembic commands ###
