"""add connections table

Revision ID: 55d923d0e3be
Revises: 33b3a136ea29
Create Date: 2026-02-24 21:39:55.533966

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "55d923d0e3be"
down_revision = "33b3a136ea29"
branch_labels = None
depends_on = None


def upgrade() -> None:
  # ### commands auto generated by Alembic - please adjust! ###
  op.create_table(
    "connections",
    sa.Column("id", sa.String(), nullable=False),
    sa.Column("graph_id", sa.String(), nullable=False),
    sa.Column("user_id", sa.String(), nullable=False),
    sa.Column("provider", sa.String(), nullable=False),
    sa.Column("status", sa.String(), nullable=False),
    sa.Column("realm_id", sa.String(), nullable=True),
    sa.Column("item_id", sa.String(), nullable=True),
    sa.Column("cik", sa.String(), nullable=True),
    sa.Column("entity_name", sa.String(), nullable=True),
    sa.Column("institution_name", sa.String(), nullable=True),
    sa.Column("auto_sync_enabled", sa.Boolean(), nullable=False),
    sa.Column("last_sync", sa.DateTime(), nullable=True),
    sa.Column("created_at", sa.DateTime(), nullable=False),
    sa.Column("updated_at", sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(
      ["graph_id"],
      ["graphs.graph_id"],
    ),
    sa.ForeignKeyConstraint(
      ["user_id"],
      ["users.id"],
    ),
    sa.PrimaryKeyConstraint("id"),
  )
  op.create_index("idx_connections_graph", "connections", ["graph_id"], unique=False)
  op.create_index(
    "idx_connections_graph_provider",
    "connections",
    ["graph_id", "provider"],
    unique=False,
  )
  op.create_index("idx_connections_provider", "connections", ["provider"], unique=False)
  op.create_index("idx_connections_user", "connections", ["user_id"], unique=False)
  # ### end Alembic commands ###


def downgrade() -> None:
  # ### commands auto generated by Alembic - please adjust! ###
  op.drop_index("idx_connections_user", table_name="connections")
  op.drop_index("idx_connections_provider", table_name="connections")
  op.drop_index("idx_connections_graph_provider", table_name="connections")
  op.drop_index("idx_connections_graph", table_name="connections")
  op.drop_table("connections")
  # ### end Alembic commands ###
