# frozen_string_literal: true ROM::SQL.migration do change do # Drop and recreate matches table with new structure drop_table?(:matches) create_table :matches do primary_key :id foreign_key :event_id, :events column :played_at, DateTime column :team_1_p1_id, Integer column :team_1_p2_id, Integer column :team_2_p1_id, Integer column :team_2_p2_id, Integer column :team_1_score, Integer column :team_2_score, Integer column :status, String, default: 'completed' end # Add current_elo to players table alter_table :players do add_column :current_elo, Integer, default: 1000 end # Create elo_snapshots table create_table :elo_snapshots do primary_key :id foreign_key :player_id, :players, null: false foreign_key :match_id, :matches, null: false column :rating_before, Integer, null: false column :rating_after, Integer, null: false column :rating_change, Integer, null: false column :created_at, DateTime, null: false, default: Sequel::CURRENT_TIMESTAMP end # Add indexes for performance add_index :elo_snapshots, [:player_id, :match_id], unique: true add_index :matches, :played_at add_index :matches, :status end end