0023_coord_reservation_composite_pk.py
python
sha256:94ef169c149a452bff7c604ded8b280b19bd477c2dabcb56972780b0b784c7aa
Merge 'fix/assignee-sigil-inline' into 'dev' — proposal: As…
Human
1 day ago
| 1 | """Fix musehub_coord_reservations: composite PK (reservation_id, symbol_address). |
| 2 | |
| 3 | The original schema used reservation_id alone as PK, which prevented a single |
| 4 | reservation from covering multiple symbol addresses — _materialize_reservation |
| 5 | would create only the first row and skip all subsequent addresses because |
| 6 | session.get(PK) found the first row on loop iteration 2+. |
| 7 | |
| 8 | The correct design: one row per (reservation_id, symbol_address) pair, with a |
| 9 | composite PK. This matches the query pattern (conflict_check uses symbol_address |
| 10 | IN filter) and enables proper multi-address reservations. |
| 11 | |
| 12 | Revision ID: 0023 |
| 13 | Revises: 0022 |
| 14 | """ |
| 15 | from __future__ import annotations |
| 16 | |
| 17 | from alembic import op |
| 18 | import sqlalchemy as sa |
| 19 | |
| 20 | revision = "0023" |
| 21 | down_revision = "0022" |
| 22 | branch_labels = None |
| 23 | depends_on = None |
| 24 | |
| 25 | |
| 26 | def upgrade() -> None: |
| 27 | # Drop the old single-column PK |
| 28 | op.drop_constraint("musehub_coord_reservations_pkey", "musehub_coord_reservations", type_="primary") |
| 29 | |
| 30 | # Add composite PK |
| 31 | op.create_primary_key( |
| 32 | "musehub_coord_reservations_pkey", |
| 33 | "musehub_coord_reservations", |
| 34 | ["reservation_id", "symbol_address"], |
| 35 | ) |
| 36 | |
| 37 | # Add index on repo_id for the list_reservations query pattern |
| 38 | op.create_index("ix_coord_reservations_repo_id", "musehub_coord_reservations", ["repo_id"]) |
| 39 | |
| 40 | |
| 41 | def downgrade() -> None: |
| 42 | from sqlalchemy import text |
| 43 | op.execute(text("DROP INDEX IF EXISTS ix_coord_reservations_repo_id")) |
| 44 | op.drop_constraint("musehub_coord_reservations_pkey", "musehub_coord_reservations", type_="primary") |
| 45 | op.create_primary_key( |
| 46 | "musehub_coord_reservations_pkey", |
| 47 | "musehub_coord_reservations", |
| 48 | ["reservation_id"], |
| 49 | ) |
File History
3 commits
sha256:94ef169c149a452bff7c604ded8b280b19bd477c2dabcb56972780b0b784c7aa
Merge 'fix/assignee-sigil-inline' into 'dev' — proposal: As…
Human
1 day ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f
fix: use wire_bytes not mpack_bytes_raw in compute_object_b…
Sonnet 4.6
patch
9 days ago
sha256:4aed3d8601c8dd3ed37074de35f11f4a9699a0a4b99d43727048fd3f8e6fd13d
chore: doc sweep, ignore wrangler build state, misc fixes
Sonnet 4.6
minor
⚠
12 days ago