1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-03 05:27:25 +00:00

Fixed migration for mat assignment rule

This commit is contained in:
2024-11-25 20:12:36 -05:00
parent ad8e486205
commit 5d37e5e0d8
3 changed files with 22 additions and 21 deletions

View File

@@ -1,26 +1,22 @@
class CreateMatAssignmentRules < ActiveRecord::Migration[6.1]
def up
create_table :mat_assignment_rules do |t|
t.references :tournament, null: false, foreign_key: true
t.references :mat, null: false, foreign_key: true
t.json :weight_classes, default: []
t.json :bracket_positions, default: []
t.json :rounds, default: []
t.integer :tournament_id, null: false, foreign_key: true
t.integer :mat_id, null: false, foreign_key: true
t.json :weight_classes # Removed `default: []`
t.json :bracket_positions # Removed `default: []`
t.json :rounds # Removed `default: []`
t.timestamps
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 on tournament_id for faster lookups
add_index :mat_assignment_rules, :tournament_id unless index_exists?(:mat_assignment_rules, :tournament_id)
end
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, :tournament_id if index_exists?(:mat_assignment_rules, :tournament_id)
# Drop the table
drop_table :mat_assignment_rules