0063_mpack_index_full_coverage.py
python
sha256:0997d6250ae6476362f6fe2025af7789f46d03df3e9f34356d5e8ee79b201923
fix(issues): use issue number as pagination cursor, not cre…
Sonnet 4.6
patch
8 days ago
| 1 | """Extend musehub_pack_index to cover commits and snapshots. |
| 2 | |
| 3 | Renames: |
| 4 | object_id → entity_id |
| 5 | pack_id → mpack_id |
| 6 | |
| 7 | Adds: |
| 8 | entity_type VARCHAR(16) NOT NULL — "object", "commit", or "snapshot" |
| 9 | Backfills existing rows with entity_type = 'object'. |
| 10 | |
| 11 | Renames index ix_musehub_pack_index_object_id → ix_musehub_pack_index_entity_id. |
| 12 | """ |
| 13 | |
| 14 | from __future__ import annotations |
| 15 | |
| 16 | import sqlalchemy as sa |
| 17 | from alembic import op |
| 18 | |
| 19 | revision = "0063" |
| 20 | down_revision = "0062" |
| 21 | branch_labels = None |
| 22 | depends_on = None |
| 23 | |
| 24 | |
| 25 | def upgrade() -> None: |
| 26 | op.drop_index("ix_musehub_pack_index_object_id", table_name="musehub_pack_index") |
| 27 | |
| 28 | with op.batch_alter_table("musehub_pack_index") as batch_op: |
| 29 | batch_op.alter_column("object_id", new_column_name="entity_id") |
| 30 | batch_op.alter_column("pack_id", new_column_name="mpack_id") |
| 31 | batch_op.add_column( |
| 32 | sa.Column( |
| 33 | "entity_type", |
| 34 | sa.String(16), |
| 35 | nullable=False, |
| 36 | server_default="object", |
| 37 | ) |
| 38 | ) |
| 39 | |
| 40 | op.execute("UPDATE musehub_pack_index SET entity_type = 'object'") |
| 41 | |
| 42 | op.create_index( |
| 43 | "ix_musehub_pack_index_entity_id", |
| 44 | "musehub_pack_index", |
| 45 | ["entity_id"], |
| 46 | ) |
| 47 | |
| 48 | |
| 49 | def downgrade() -> None: |
| 50 | op.drop_index("ix_musehub_pack_index_entity_id", table_name="musehub_pack_index") |
| 51 | |
| 52 | with op.batch_alter_table("musehub_pack_index") as batch_op: |
| 53 | batch_op.drop_column("entity_type") |
| 54 | batch_op.alter_column("mpack_id", new_column_name="pack_id") |
| 55 | batch_op.alter_column("entity_id", new_column_name="object_id") |
| 56 | |
| 57 | op.create_index( |
| 58 | "ix_musehub_pack_index_object_id", |
| 59 | "musehub_pack_index", |
| 60 | ["object_id"], |
| 61 | ) |
File History
1 commit
sha256:0997d6250ae6476362f6fe2025af7789f46d03df3e9f34356d5e8ee79b201923
fix(issues): use issue number as pagination cursor, not cre…
Sonnet 4.6
patch
8 days ago