|
| 1 | +class RemoveDuplicateIndexes < ActiveRecord::Migration[7.2] |
| 2 | + def up |
| 3 | + # Remove duplicate indexes from matches table |
| 4 | + # Keep the shorter-named index (idx_*) and remove the longer Rails-generated ones |
| 5 | + remove_index :matches, name: "index_matches_on_org_and_game_start", if_exists: true |
| 6 | + remove_index :matches, name: "index_matches_on_org_and_victory", if_exists: true |
| 7 | + |
| 8 | + # Remove duplicate indexes from player_match_stats table |
| 9 | + # Keep the shortest name (idx_player_stats_match) |
| 10 | + remove_index :player_match_stats, name: "index_player_match_stats_on_match", if_exists: true |
| 11 | + remove_index :player_match_stats, name: "index_player_match_stats_on_match_id", if_exists: true |
| 12 | + |
| 13 | + # Remove duplicate indexes from players table |
| 14 | + remove_index :players, name: "index_players_on_org_and_status", if_exists: true |
| 15 | + |
| 16 | + # Remove duplicate indexes from schedules table |
| 17 | + remove_index :schedules, name: "index_schedules_on_org_time_type", if_exists: true |
| 18 | + |
| 19 | + # Remove duplicate indexes from team_goals table |
| 20 | + remove_index :team_goals, name: "index_team_goals_on_org_and_status", if_exists: true |
| 21 | + end |
| 22 | + |
| 23 | + def down |
| 24 | + # Re-create the removed indexes if rollback is needed |
| 25 | + add_index :matches, [:organization_id, :game_start], name: "index_matches_on_org_and_game_start", if_not_exists: true |
| 26 | + add_index :matches, [:organization_id, :victory], name: "index_matches_on_org_and_victory", if_not_exists: true |
| 27 | + |
| 28 | + add_index :player_match_stats, :match_id, name: "index_player_match_stats_on_match", if_not_exists: true |
| 29 | + add_index :player_match_stats, :match_id, name: "index_player_match_stats_on_match_id", if_not_exists: true |
| 30 | + |
| 31 | + add_index :players, [:organization_id, :status], name: "index_players_on_org_and_status", if_not_exists: true |
| 32 | + |
| 33 | + add_index :schedules, [:organization_id, :scheduled_time, :schedule_type], name: "index_schedules_on_org_time_type", if_not_exists: true |
| 34 | + |
| 35 | + add_index :team_goals, [:organization_id, :status], name: "index_team_goals_on_org_and_status", if_not_exists: true |
| 36 | + end |
| 37 | +end |
0 commit comments