mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-08 07:22:38 +00:00
Fixed migration for mat assignment rule
This commit is contained in:
@@ -1,4 +1,12 @@
|
|||||||
class MatAssignmentRule < ApplicationRecord
|
class MatAssignmentRule < ApplicationRecord
|
||||||
belongs_to :mat
|
belongs_to :mat
|
||||||
belongs_to :tournament
|
belongs_to :tournament
|
||||||
|
|
||||||
|
# Ensure default values for JSON fields
|
||||||
|
# because mysql doesn't allow this
|
||||||
|
after_initialize do
|
||||||
|
self.weight_classes ||= []
|
||||||
|
self.bracket_positions ||= []
|
||||||
|
self.rounds ||= []
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@@ -1,26 +1,22 @@
|
|||||||
class CreateMatAssignmentRules < ActiveRecord::Migration[6.1]
|
class CreateMatAssignmentRules < ActiveRecord::Migration[6.1]
|
||||||
def up
|
def up
|
||||||
create_table :mat_assignment_rules do |t|
|
create_table :mat_assignment_rules do |t|
|
||||||
t.references :tournament, null: false, foreign_key: true
|
t.integer :tournament_id, null: false, foreign_key: true
|
||||||
t.references :mat, null: false, foreign_key: true
|
t.integer :mat_id, null: false, foreign_key: true
|
||||||
t.json :weight_classes, default: []
|
t.json :weight_classes # Removed `default: []`
|
||||||
t.json :bracket_positions, default: []
|
t.json :bracket_positions # Removed `default: []`
|
||||||
t.json :rounds, default: []
|
t.json :rounds # Removed `default: []`
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add unique index on mat_id if it does not already exist
|
# Add unique index only if it does not already exist
|
||||||
add_index :mat_assignment_rules, :mat_id, unique: true unless index_exists?(:mat_assignment_rules, :mat_id)
|
add_index :mat_assignment_rules, :mat_id, unique: true unless index_exists?(:mat_assignment_rules, :mat_id)
|
||||||
|
|
||||||
# Add index on tournament_id for faster lookups
|
|
||||||
add_index :mat_assignment_rules, :tournament_id unless index_exists?(:mat_assignment_rules, :tournament_id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
# Remove indexes if they exist
|
# Remove the unique index if it exists
|
||||||
remove_index :mat_assignment_rules, :mat_id if index_exists?(:mat_assignment_rules, :mat_id)
|
remove_index :mat_assignment_rules, :mat_id if index_exists?(:mat_assignment_rules, :mat_id)
|
||||||
remove_index :mat_assignment_rules, :tournament_id if index_exists?(:mat_assignment_rules, :tournament_id)
|
|
||||||
|
|
||||||
# Drop the table
|
# Drop the table
|
||||||
drop_table :mat_assignment_rules
|
drop_table :mat_assignment_rules
|
||||||
|
|||||||
11
db/schema.rb
11
db/schema.rb
@@ -31,13 +31,12 @@ ActiveRecord::Schema[7.1].define(version: 2024_10_27_203209) do
|
|||||||
create_table "mat_assignment_rules", force: :cascade do |t|
|
create_table "mat_assignment_rules", force: :cascade do |t|
|
||||||
t.integer "tournament_id", null: false
|
t.integer "tournament_id", null: false
|
||||||
t.integer "mat_id", null: false
|
t.integer "mat_id", null: false
|
||||||
t.json "weight_classes", default: []
|
t.json "weight_classes"
|
||||||
t.json "bracket_positions", default: []
|
t.json "bracket_positions"
|
||||||
t.json "rounds", default: []
|
t.json "rounds"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["mat_id"], name: "index_mat_assignment_rules_on_mat_id"
|
t.index ["mat_id"], name: "index_mat_assignment_rules_on_mat_id", unique: true
|
||||||
t.index ["tournament_id"], name: "index_mat_assignment_rules_on_tournament_id"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "matches", force: :cascade do |t|
|
create_table "matches", force: :cascade do |t|
|
||||||
@@ -168,6 +167,4 @@ ActiveRecord::Schema[7.1].define(version: 2024_10_27_203209) do
|
|||||||
t.index ["weight_id"], name: "index_wrestlers_on_weight_id"
|
t.index ["weight_id"], name: "index_wrestlers_on_weight_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_foreign_key "mat_assignment_rules", "mats"
|
|
||||||
add_foreign_key "mat_assignment_rules", "tournaments"
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user