|
22 | 22 |
|
23 | 23 | def upgrade() -> None: |
24 | 24 | # Track metadata indexes for filtering/searching |
25 | | - op.create_index("ix_tracks_artist", "tracks", ["artist"]) |
26 | | - op.create_index("ix_tracks_album", "tracks", ["album"]) |
27 | | - op.create_index("ix_tracks_year", "tracks", ["year"]) |
28 | | - op.create_index("ix_tracks_genre", "tracks", ["genre"]) |
| 25 | + # Use if_not_exists=True since baseline migration may have already created them |
| 26 | + op.create_index("ix_tracks_artist", "tracks", ["artist"], if_not_exists=True) |
| 27 | + op.create_index("ix_tracks_album", "tracks", ["album"], if_not_exists=True) |
| 28 | + op.create_index("ix_tracks_year", "tracks", ["year"], if_not_exists=True) |
| 29 | + op.create_index("ix_tracks_genre", "tracks", ["genre"], if_not_exists=True) |
29 | 30 |
|
30 | 31 | # Foreign key indexes for faster joins |
31 | | - op.create_index("ix_track_analysis_track_id", "track_analysis", ["track_id"]) |
32 | | - op.create_index("ix_playlists_profile_id", "playlists", ["profile_id"]) |
33 | | - op.create_index("ix_smart_playlists_profile_id", "smart_playlists", ["profile_id"]) |
| 32 | + op.create_index("ix_track_analysis_track_id", "track_analysis", ["track_id"], if_not_exists=True) |
| 33 | + op.create_index("ix_playlists_profile_id", "playlists", ["profile_id"], if_not_exists=True) |
| 34 | + op.create_index("ix_smart_playlists_profile_id", "smart_playlists", ["profile_id"], if_not_exists=True) |
34 | 35 |
|
35 | 36 |
|
36 | 37 | def downgrade() -> None: |
37 | | - op.drop_index("ix_tracks_artist", "tracks") |
38 | | - op.drop_index("ix_tracks_album", "tracks") |
39 | | - op.drop_index("ix_tracks_year", "tracks") |
40 | | - op.drop_index("ix_tracks_genre", "tracks") |
41 | | - op.drop_index("ix_track_analysis_track_id", "track_analysis") |
42 | | - op.drop_index("ix_playlists_profile_id", "playlists") |
43 | | - op.drop_index("ix_smart_playlists_profile_id", "smart_playlists") |
| 38 | + op.drop_index("ix_tracks_artist", "tracks", if_exists=True) |
| 39 | + op.drop_index("ix_tracks_album", "tracks", if_exists=True) |
| 40 | + op.drop_index("ix_tracks_year", "tracks", if_exists=True) |
| 41 | + op.drop_index("ix_tracks_genre", "tracks", if_exists=True) |
| 42 | + op.drop_index("ix_track_analysis_track_id", "track_analysis", if_exists=True) |
| 43 | + op.drop_index("ix_playlists_profile_id", "playlists", if_exists=True) |
| 44 | + op.drop_index("ix_smart_playlists_profile_id", "smart_playlists", if_exists=True) |
0 commit comments