"""initial_schema

Revision ID: 86c0732b1e07
Revises:
Create Date: 2025-03-02 01:32:34.225402

"""

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

# revision identifiers, used by Alembic.
revision = "86c0732b1e07"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "embedding_model",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("short_name", sa.String(), nullable=False),
        sa.Column("provider", sa.String(), nullable=False),
        sa.Column("auth_config_class", sa.String(), nullable=True),
        sa.Column(
            "auth_type",
            sa.Enum(
                "oauth2",
                "oauth2_with_refresh",
                "oauth2_with_refresh_rotating",
                "trello_auth",
                "api_key",
                "native_functionality",
                "config_class",
                "none",
                name="authtype",
            ),
            nullable=True,
        ),
        sa.Column("model_name", sa.String(), nullable=True),
        sa.Column("model_version", sa.String(), nullable=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("short_name"),
    )
    op.create_table(
        "organization",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_table(
        "destination",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("short_name", sa.String(), nullable=False),
        sa.Column("class_name", sa.String(), nullable=False),
        sa.Column("auth_config_class", sa.String(), nullable=True),
        sa.Column(
            "auth_type",
            sa.Enum(
                "oauth2",
                "oauth2_with_refresh",
                "oauth2_with_refresh_rotating",
                "trello_auth",
                "api_key",
                "native_functionality",
                "config_class",
                "none",
                name="authtype",
            ),
            nullable=True,
        ),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("input_entity_definition_ids", sa.JSON(), nullable=False),
        sa.Column("config_schema", sa.JSON(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=True),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name", "organization_id", name="uq_destination_name_org"),
        sa.UniqueConstraint("short_name"),
    )
    op.create_table(
        "entity_definition",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("type", sa.Enum("FILE", "JSON", name="entitytype"), nullable=False),
        sa.Column("schema", sa.JSON(), nullable=False),
        sa.Column("parent_id", sa.UUID(), nullable=True),
        sa.Column("module_name", sa.String(), nullable=False),
        sa.Column("class_name", sa.String(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=True),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["parent_id"],
            ["entity_definition.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name", "organization_id", name="uq_entity_definition_name_org"),
    )
    op.create_table(
        "source",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("short_name", sa.String(), nullable=False),
        sa.Column("class_name", sa.String(), nullable=False),
        sa.Column("auth_config_class", sa.String(), nullable=True),
        sa.Column(
            "auth_type",
            sa.Enum(
                "oauth2",
                "oauth2_with_refresh",
                "oauth2_with_refresh_rotating",
                "trello_auth",
                "api_key",
                "native_functionality",
                "config_class",
                "none",
                name="authtype",
            ),
            nullable=True,
        ),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("organization_id", sa.UUID(), nullable=True),
        sa.Column("output_entity_definition_ids", sa.JSON(), nullable=False),
        sa.Column("config_schema", sa.JSON(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name", "organization_id", name="uq_source_name_org"),
        sa.UniqueConstraint("short_name"),
    )
    op.create_table(
        "transformer",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("method_name", sa.String(), nullable=False),
        sa.Column("module_name", sa.String(), nullable=False),
        sa.Column("input_entity_definition_ids", sa.JSON(), nullable=False),
        sa.Column("output_entity_definition_ids", sa.JSON(), nullable=False),
        sa.Column("config_schema", sa.JSON(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=True),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "user",
        sa.Column("full_name", sa.String(), nullable=False),
        sa.Column("email", sa.String(), nullable=False),
        sa.Column("password", sa.String(), nullable=False),
        sa.Column("is_active", sa.Boolean(), nullable=False),
        sa.Column("is_superuser", sa.Boolean(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("email"),
    )
    op.create_table(
        "api_key",
        sa.Column("key", sa.String(), nullable=False),
        sa.Column("key_prefix", sa.String(length=8), nullable=False),
        sa.Column("expiration_date", sa.DateTime(timezone=True), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("key"),
    )
    op.create_table(
        "entity_relation",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("from_entity_definition_id", sa.UUID(), nullable=False),
        sa.Column("to_entity_definition_id", sa.UUID(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=True),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["from_entity_definition_id"],
            ["entity_definition.id"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["to_entity_definition_id"],
            ["entity_definition.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "integration_credential",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("integration_short_name", sa.String(), nullable=False),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("integration_type", sa.String(), nullable=False),
        sa.Column("auth_type", sa.String(), nullable=False),
        sa.Column("encrypted_credentials", sa.Text(), nullable=False),
        sa.Column("auth_config_class", sa.String(), nullable=True),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "white_label",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("source_short_name", sa.String(), nullable=False),
        sa.Column("redirect_url", sa.String(), nullable=False),
        sa.Column("client_id", sa.String(), nullable=False),
        sa.Column("client_secret", sa.String(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["source_short_name"],
            ["source.short_name"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "connection",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column(
            "integration_type",
            sa.Enum("SOURCE", "DESTINATION", "EMBEDDING_MODEL", name="integrationtype"),
            nullable=False,
        ),
        sa.Column(
            "status",
            sa.Enum("ACTIVE", "INACTIVE", "ERROR", name="connectionstatus"),
            nullable=False,
        ),
        sa.Column("integration_credential_id", sa.UUID(), nullable=True),
        sa.Column("short_name", sa.String(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["integration_credential_id"],
            ["integration_credential.id"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "sync",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("source_connection_id", sa.UUID(), nullable=False),
        sa.Column("destination_connection_id", sa.UUID(), nullable=True),
        sa.Column(
            "status", sa.Enum("ACTIVE", "INACTIVE", "ERROR", name="syncstatus"), nullable=False
        ),
        sa.Column("embedding_model_connection_id", sa.UUID(), nullable=True),
        sa.Column("cron_schedule", sa.String(length=100), nullable=True),
        sa.Column("white_label_id", sa.UUID(), nullable=True),
        sa.Column("white_label_user_identifier", sa.String(length=256), nullable=True),
        sa.Column("sync_metadata", sa.JSON(), nullable=True),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["destination_connection_id"],
            ["connection.id"],
        ),
        sa.ForeignKeyConstraint(
            ["embedding_model_connection_id"],
            ["connection.id"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["source_connection_id"],
            ["connection.id"],
        ),
        sa.ForeignKeyConstraint(
            ["white_label_id"],
            ["white_label.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint(
            "white_label_id", "white_label_user_identifier", name="uq_white_label_user"
        ),
    )
    op.create_table(
        "chat",
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.Column("sync_id", sa.UUID(), nullable=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("model_name", sa.String(length=50), nullable=False),
        sa.Column("model_settings", sa.JSON(), nullable=False),
        sa.Column("search_settings", sa.JSON(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["sync_id"],
            ["sync.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "sync_dag",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("description", sa.String(), nullable=True),
        sa.Column("sync_id", sa.UUID(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(["sync_id"], ["sync.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("sync_id", name="uq_sync_dag_def_sync_id"),
    )
    op.create_table(
        "sync_job",
        sa.Column("sync_id", sa.UUID(), nullable=False),
        sa.Column(
            "status",
            sa.Enum("PENDING", "IN_PROGRESS", "COMPLETED", "FAILED", name="syncjobstatus"),
            nullable=False,
        ),
        sa.Column("started_at", sa.DateTime(), nullable=True),
        sa.Column("completed_at", sa.DateTime(), nullable=True),
        sa.Column("failed_at", sa.DateTime(), nullable=True),
        sa.Column("entities_detected", sa.Integer(), nullable=False),
        sa.Column("entities_inserted", sa.Integer(), nullable=False),
        sa.Column("entities_deleted", sa.Integer(), nullable=False),
        sa.Column("entities_skipped", sa.Integer(), nullable=False),
        sa.Column("error", sa.String(), nullable=True),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["sync_id"], ["sync.id"], name="fk_sync_job_sync_id", ondelete="CASCADE"
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "chat_message",
        sa.Column("chat_id", sa.UUID(), nullable=False),
        sa.Column("content", sa.Text(), nullable=False),
        sa.Column("role", sa.Enum("USER", "ASSISTANT", "SYSTEM", name="chatrole"), nullable=False),
        sa.Column("tokens_used", sa.Integer(), nullable=True),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(["chat_id"], ["chat.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_chat_message_chat_id"), "chat_message", ["chat_id"], unique=False)
    op.create_table(
        "dag_node",
        sa.Column("dag_id", sa.UUID(), nullable=False),
        sa.Column("type", sa.String(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("config", sa.JSON(), nullable=True),
        sa.Column("connection_id", sa.UUID(), nullable=True),
        sa.Column("entity_definition_id", sa.UUID(), nullable=True),
        sa.Column("transformer_id", sa.UUID(), nullable=True),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["connection_id"],
            ["connection.id"],
        ),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(["dag_id"], ["sync_dag.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(
            ["entity_definition_id"],
            ["entity_definition.id"],
        ),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["transformer_id"],
            ["transformer.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "entity",
        sa.Column("sync_job_id", sa.UUID(), nullable=False),
        sa.Column("sync_id", sa.UUID(), nullable=False),
        sa.Column("entity_id", sa.String(), nullable=False),
        sa.Column("hash", sa.String(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(
            ["sync_id"], ["sync.id"], name="fk_entity_sync_id", ondelete="CASCADE"
        ),
        sa.ForeignKeyConstraint(
            ["sync_job_id"], ["sync_job.id"], name="fk_entity_sync_job_id", ondelete="CASCADE"
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("sync_id", "entity_id", name="uq_sync_id_entity_id"),
    )
    op.create_table(
        "dag_edge",
        sa.Column("dag_id", sa.UUID(), nullable=False),
        sa.Column("from_node_id", sa.UUID(), nullable=False),
        sa.Column("to_node_id", sa.UUID(), nullable=False),
        sa.Column("organization_id", sa.UUID(), nullable=False),
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("modified_at", sa.DateTime(), nullable=False),
        sa.Column("created_by_email", sa.String(), nullable=False),
        sa.Column("modified_by_email", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["created_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(["dag_id"], ["sync_dag.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(["from_node_id"], ["dag_node.id"], ondelete="CASCADE"),
        sa.ForeignKeyConstraint(
            ["modified_by_email"],
            ["user.email"],
        ),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organization.id"],
        ),
        sa.ForeignKeyConstraint(["to_node_id"], ["dag_node.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("dag_id", "from_node_id", "to_node_id", name="uq_dag_edge_from_to"),
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("dag_edge")
    op.drop_table("entity")
    op.drop_table("dag_node")
    op.drop_index(op.f("ix_chat_message_chat_id"), table_name="chat_message")
    op.drop_table("chat_message")
    op.drop_table("sync_job")
    op.drop_table("sync_dag")
    op.drop_table("chat")
    op.drop_table("sync")
    op.drop_table("connection")
    op.drop_table("white_label")
    op.drop_table("integration_credential")
    op.drop_table("entity_relation")
    op.drop_table("api_key")
    op.drop_table("user")
    op.drop_table("transformer")
    op.drop_table("source")
    op.drop_table("entity_definition")
    op.drop_table("destination")
    op.drop_table("organization")
    op.drop_table("embedding_model")
    # ### end Alembic commands ###
