0028_rename_pr_number_and_pr_labels_table.py
python
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a
init: musehub initial commit
Human
171 days ago
| 1 | """rename proposal number column (previously pr_number) to proposal_number, rename musehub_pr_labels to musehub_proposal_labels |
| 2 | |
| 3 | Revision ID: 0028 |
| 4 | Revises: 0027 |
| 5 | Create Date: 2026-04-06 |
| 6 | """ |
| 7 | |
| 8 | from alembic import op |
| 9 | |
| 10 | revision = "0028" |
| 11 | down_revision = "0027" |
| 12 | branch_labels = None |
| 13 | depends_on = None |
| 14 | |
| 15 | |
| 16 | def upgrade() -> None: |
| 17 | # Drop index referencing pr_number first, then rename the column |
| 18 | op.drop_index("ix_musehub_proposals_repo_number", table_name="musehub_proposals") |
| 19 | op.alter_column("musehub_proposals", "pr_number", new_column_name="proposal_number") |
| 20 | op.create_index( |
| 21 | "ix_musehub_proposals_repo_number", |
| 22 | "musehub_proposals", |
| 23 | ["repo_id", "proposal_number"], |
| 24 | ) |
| 25 | |
| 26 | # Rename musehub_pr_labels → musehub_proposal_labels |
| 27 | op.rename_table("musehub_pr_labels", "musehub_proposal_labels") |
| 28 | |
| 29 | # Rename the label_id index on the table |
| 30 | op.drop_index("ix_musehub_pr_labels_label_id", table_name="musehub_proposal_labels") |
| 31 | op.create_index( |
| 32 | "ix_musehub_proposal_labels_label_id", |
| 33 | "musehub_proposal_labels", |
| 34 | ["label_id"], |
| 35 | ) |
| 36 | |
| 37 | |
| 38 | def downgrade() -> None: |
| 39 | op.drop_index("ix_musehub_proposal_labels_label_id", table_name="musehub_proposal_labels") |
| 40 | op.create_index( |
| 41 | "ix_musehub_pr_labels_label_id", |
| 42 | "musehub_proposal_labels", |
| 43 | ["label_id"], |
| 44 | ) |
| 45 | op.rename_table("musehub_proposal_labels", "musehub_pr_labels") |
| 46 | |
| 47 | # Rename column first, then recreate index referencing the old column name |
| 48 | op.alter_column("musehub_proposals", "proposal_number", new_column_name="pr_number") |
| 49 | op.drop_index("ix_musehub_proposals_repo_number", table_name="musehub_proposals") |
| 50 | op.create_index( |
| 51 | "ix_musehub_proposals_repo_number", |
| 52 | "musehub_proposals", |
| 53 | ["repo_id", "pr_number"], |
| 54 | ) |
File History
1 commit
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a
init: musehub initial commit
Human
171 days ago