0002_drop_muse_variation_tables.py
python
| 1 | """Drop Muse variation tables (muse_variations, muse_phrases, muse_note_changes). |
| 2 | |
| 3 | Muse VCS was extracted to cgcardona/muse. These three tables tracked |
| 4 | DAW-level note editing history and are no longer needed in Maestro. |
| 5 | |
| 6 | Note: muse_commits, muse_snapshots, muse_objects, and muse_tags are |
| 7 | intentionally NOT dropped here — MuseHub reads those tables to display |
| 8 | repository commit history. They will be dropped when MuseHub is extracted. |
| 9 | |
| 10 | Revision ID: 0002 |
| 11 | Revises: 0001 |
| 12 | """ |
| 13 | from __future__ import annotations |
| 14 | |
| 15 | import sqlalchemy as sa |
| 16 | from alembic import op |
| 17 | |
| 18 | revision = "0002" |
| 19 | down_revision = "0001" |
| 20 | branch_labels = None |
| 21 | depends_on = None |
| 22 | |
| 23 | |
| 24 | def upgrade() -> None: |
| 25 | # Drop child tables first (FK constraints) |
| 26 | op.drop_index("ix_muse_note_changes_phrase_id", table_name="muse_note_changes") |
| 27 | op.drop_table("muse_note_changes") |
| 28 | |
| 29 | op.drop_index("ix_muse_phrases_variation_id", table_name="muse_phrases") |
| 30 | op.drop_table("muse_phrases") |
| 31 | |
| 32 | op.drop_index("ix_muse_variations_parent_variation_id", table_name="muse_variations") |
| 33 | op.drop_index("ix_muse_variations_project_id", table_name="muse_variations") |
| 34 | op.drop_table("muse_variations") |
| 35 | |
| 36 | |
| 37 | def downgrade() -> None: |
| 38 | op.create_table( |
| 39 | "muse_variations", |
| 40 | sa.Column("variation_id", sa.String(36), nullable=False), |
| 41 | sa.Column("project_id", sa.String(36), nullable=False), |
| 42 | sa.Column("intent", sa.Text(), nullable=False), |
| 43 | sa.Column("ai_explanation", sa.Text(), nullable=True), |
| 44 | sa.Column("affected_tracks", sa.JSON(), nullable=True), |
| 45 | sa.Column("affected_regions", sa.JSON(), nullable=True), |
| 46 | sa.Column("beat_range_start", sa.Float(), nullable=True), |
| 47 | sa.Column("beat_range_end", sa.Float(), nullable=True), |
| 48 | sa.Column("status", sa.String(20), nullable=False, server_default="pending"), |
| 49 | sa.Column("base_state_id", sa.String(64), nullable=True), |
| 50 | sa.Column("commit_state_id", sa.String(64), nullable=True), |
| 51 | sa.Column("is_head", sa.Boolean(), nullable=False, server_default="false"), |
| 52 | sa.Column("parent_variation_id", sa.String(36), nullable=True), |
| 53 | sa.Column("parent2_variation_id", sa.String(36), nullable=True), |
| 54 | sa.Column("region_metadata", sa.JSON(), nullable=True), |
| 55 | sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), |
| 56 | sa.ForeignKeyConstraint( |
| 57 | ["parent_variation_id"], ["muse_variations.variation_id"], ondelete="SET NULL" |
| 58 | ), |
| 59 | sa.ForeignKeyConstraint( |
| 60 | ["parent2_variation_id"], ["muse_variations.variation_id"], ondelete="SET NULL" |
| 61 | ), |
| 62 | sa.PrimaryKeyConstraint("variation_id"), |
| 63 | ) |
| 64 | op.create_index("ix_muse_variations_project_id", "muse_variations", ["project_id"]) |
| 65 | op.create_index( |
| 66 | "ix_muse_variations_parent_variation_id", "muse_variations", ["parent_variation_id"] |
| 67 | ) |
| 68 | |
| 69 | op.create_table( |
| 70 | "muse_phrases", |
| 71 | sa.Column("phrase_id", sa.String(36), nullable=False), |
| 72 | sa.Column("variation_id", sa.String(36), nullable=False), |
| 73 | sa.Column("track_id", sa.String(36), nullable=True), |
| 74 | sa.Column("region_id", sa.String(36), nullable=True), |
| 75 | sa.Column("beat_start", sa.Float(), nullable=True), |
| 76 | sa.Column("beat_end", sa.Float(), nullable=True), |
| 77 | sa.Column("label", sa.Text(), nullable=True), |
| 78 | sa.Column("diff_json", sa.JSON(), nullable=True), |
| 79 | sa.Column("ai_explanation", sa.Text(), nullable=True), |
| 80 | sa.Column("tags", sa.JSON(), nullable=True), |
| 81 | sa.Column("sequence_order", sa.Integer(), nullable=True), |
| 82 | sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), |
| 83 | sa.ForeignKeyConstraint( |
| 84 | ["variation_id"], ["muse_variations.variation_id"], ondelete="CASCADE" |
| 85 | ), |
| 86 | sa.PrimaryKeyConstraint("phrase_id"), |
| 87 | ) |
| 88 | op.create_index("ix_muse_phrases_variation_id", "muse_phrases", ["variation_id"]) |
| 89 | |
| 90 | op.create_table( |
| 91 | "muse_note_changes", |
| 92 | sa.Column("change_id", sa.String(36), nullable=False), |
| 93 | sa.Column("phrase_id", sa.String(36), nullable=False), |
| 94 | sa.Column("note_id", sa.String(36), nullable=False), |
| 95 | sa.Column("change_type", sa.String(20), nullable=False), |
| 96 | sa.Column("before_json", sa.JSON(), nullable=True), |
| 97 | sa.Column("after_json", sa.JSON(), nullable=True), |
| 98 | sa.ForeignKeyConstraint( |
| 99 | ["phrase_id"], ["muse_phrases.phrase_id"], ondelete="CASCADE" |
| 100 | ), |
| 101 | sa.PrimaryKeyConstraint("change_id"), |
| 102 | ) |
| 103 | op.create_index("ix_muse_note_changes_phrase_id", "muse_note_changes", ["phrase_id"]) |