107 lines
4.8 KiB
Ruby
107 lines
4.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CreateTournaments < ActiveRecord::Migration[7.2]
|
|
def change
|
|
add_column :teams, :internal_kind, :string
|
|
add_index :teams, [:club_id, :internal_kind]
|
|
|
|
create_table :tournaments, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.references :club, type: :uuid, null: false, foreign_key: true
|
|
t.references :broadcast_team, type: :uuid, foreign_key: { to_table: :teams }
|
|
t.string :name, null: false
|
|
t.string :slug, null: false
|
|
t.string :sport_key, null: false
|
|
t.string :venue
|
|
t.jsonb :courts, null: false, default: []
|
|
t.date :starts_on, null: false
|
|
t.date :ends_on, null: false
|
|
t.string :format_kind, null: false, default: "mixed"
|
|
t.string :status, null: false, default: "draft"
|
|
t.text :description
|
|
t.integer :knockout_size
|
|
t.jsonb :scoring_settings, null: false, default: {}
|
|
t.timestamps
|
|
end
|
|
add_index :tournaments, :slug, unique: true
|
|
add_index :tournaments, [:club_id, :status]
|
|
|
|
create_table :tournament_groups, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.references :tournament, type: :uuid, null: false, foreign_key: true
|
|
t.string :name, null: false
|
|
t.integer :position, null: false, default: 0
|
|
t.timestamps
|
|
end
|
|
|
|
create_table :tournament_rounds, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.references :tournament, type: :uuid, null: false, foreign_key: true
|
|
t.string :kind, null: false
|
|
t.string :name, null: false
|
|
t.integer :position, null: false, default: 0
|
|
t.timestamps
|
|
end
|
|
|
|
create_table :tournament_participants, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.references :tournament, type: :uuid, null: false, foreign_key: true
|
|
t.references :group, type: :uuid, foreign_key: { to_table: :tournament_groups }
|
|
t.references :source_team, type: :uuid, foreign_key: { to_table: :teams }
|
|
t.string :name, null: false
|
|
t.string :primary_color
|
|
t.string :secondary_color
|
|
t.string :logo_url
|
|
t.integer :seed
|
|
t.integer :position, null: false, default: 0
|
|
t.timestamps
|
|
end
|
|
add_index :tournament_participants, [:tournament_id, :name]
|
|
|
|
create_table :tournament_broadcast_invitations, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.references :tournament, type: :uuid, null: false, foreign_key: true
|
|
t.string :email, null: false
|
|
t.string :token_digest, null: false
|
|
t.string :scope_kind, null: false, default: "matches"
|
|
t.jsonb :match_ids, null: false, default: []
|
|
t.string :court
|
|
t.date :on_date
|
|
t.datetime :expires_at, null: false
|
|
t.datetime :accepted_at
|
|
t.references :accepted_by, type: :uuid, foreign_key: { to_table: :users }
|
|
t.timestamps
|
|
end
|
|
add_index :tournament_broadcast_invitations, :token_digest, unique: true
|
|
add_index :tournament_broadcast_invitations, [:tournament_id, :email]
|
|
|
|
add_reference :matches, :tournament, type: :uuid, foreign_key: true
|
|
add_reference :matches, :home_participant, type: :uuid, foreign_key: { to_table: :tournament_participants }
|
|
add_reference :matches, :away_participant, type: :uuid, foreign_key: { to_table: :tournament_participants }
|
|
add_reference :matches, :tournament_group, type: :uuid, foreign_key: true
|
|
add_reference :matches, :tournament_round, type: :uuid, foreign_key: true
|
|
add_column :matches, :court, :string
|
|
add_column :matches, :home_score, :integer
|
|
add_column :matches, :away_score, :integer
|
|
add_column :matches, :result_status, :string
|
|
add_column :matches, :result_source, :string
|
|
add_column :matches, :result_data, :jsonb, null: false, default: {}
|
|
add_column :matches, :winner_participant_id, :uuid
|
|
add_column :matches, :home_source_kind, :string
|
|
add_column :matches, :away_source_kind, :string
|
|
add_column :matches, :home_source_match_id, :uuid
|
|
add_column :matches, :away_source_match_id, :uuid
|
|
add_column :matches, :home_source_group_id, :uuid
|
|
add_column :matches, :away_source_group_id, :uuid
|
|
add_column :matches, :home_source_rank, :integer
|
|
add_column :matches, :away_source_rank, :integer
|
|
add_index :matches, [:tournament_id, :scheduled_at]
|
|
add_index :matches, [:tournament_id, :court]
|
|
|
|
create_table :tournament_broadcast_assignments, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
|
|
t.references :tournament, type: :uuid, null: false, foreign_key: true
|
|
t.references :match, type: :uuid, null: false, foreign_key: true
|
|
t.references :user, type: :uuid, null: false, foreign_key: true
|
|
t.references :invitation, type: :uuid, foreign_key: { to_table: :tournament_broadcast_invitations }
|
|
t.timestamps
|
|
end
|
|
add_index :tournament_broadcast_assignments, [:match_id, :user_id], unique: true,
|
|
name: "index_tournament_assignments_on_match_and_user"
|
|
end
|
|
end
|