"""Make musehub_commit_graph global — drop repo_id, PK becomes commit_id alone. Commits are content-addressed like snapshots; repo_id was the wrong abstraction. Dropping it also fixes the bug where re-pushed commits (already in musehub_commits) never got a graph row because the ON CONFLICT key included repo_id. """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "0061" down_revision = "0060" branch_labels = None depends_on = None def upgrade() -> None: op.drop_index("ix_musehub_commit_graph_repo_generation", table_name="musehub_commit_graph") op.drop_constraint("musehub_commit_graph_pkey", "musehub_commit_graph", type_="primary") op.drop_constraint("musehub_commit_graph_repo_id_fkey", "musehub_commit_graph", type_="foreignkey") op.drop_column("musehub_commit_graph", "repo_id") op.create_primary_key("musehub_commit_graph_pkey", "musehub_commit_graph", ["commit_id"]) op.create_index("ix_musehub_commit_graph_generation", "musehub_commit_graph", ["generation"]) def downgrade() -> None: op.drop_index("ix_musehub_commit_graph_generation", table_name="musehub_commit_graph") op.drop_constraint("musehub_commit_graph_pkey", "musehub_commit_graph", type_="primary") op.add_column( "musehub_commit_graph", sa.Column("repo_id", sa.String(128), nullable=False, server_default=""), ) op.create_foreign_key( "musehub_commit_graph_repo_id_fkey", "musehub_commit_graph", "musehub_repos", ["repo_id"], ["repo_id"], ondelete="CASCADE", ) op.create_primary_key( "musehub_commit_graph_pkey", "musehub_commit_graph", ["repo_id", "commit_id"] ) op.create_index( "ix_musehub_commit_graph_repo_generation", "musehub_commit_graph", ["repo_id", "generation"], )