"""add graph status lifecycle columns

Revision ID: 4e82a2e1d16f
Revises: a1f1e478ed22
Create Date: 2026-02-10 18:46:28.056916

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "4e82a2e1d16f"
down_revision = "a1f1e478ed22"
branch_labels = None
depends_on = None


def upgrade() -> None:
  # Add status column with server_default so all existing rows become 'active'
  op.add_column(
    "graphs", sa.Column("status", sa.String(), nullable=False, server_default="active")
  )
  op.add_column("graphs", sa.Column("deleted_at", sa.DateTime(), nullable=True))
  op.create_index("idx_graphs_status", "graphs", ["status"], unique=False)
  op.create_index(
    "idx_graphs_status_tier_created",
    "graphs",
    ["status", "graph_tier", "created_at"],
    unique=False,
  )

  # Remove server_default after backfill (application handles defaults going forward)
  op.alter_column("graphs", "status", server_default=None)


def downgrade() -> None:
  # ### commands auto generated by Alembic - please adjust! ###
  op.drop_index("idx_graphs_status_tier_created", table_name="graphs")
  op.drop_index("idx_graphs_status", table_name="graphs")
  op.drop_column("graphs", "deleted_at")
  op.drop_column("graphs", "status")
  # ### end Alembic commands ###
