1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 21:24:25 +00:00

Added a separate table to record background job status for tournaments and fixed migrations/schemas for solid dbs. Foreign key constraints are now added to the migrations where we do belongs_to.

This commit is contained in:
2025-04-15 16:16:44 -04:00
parent 4828d9b876
commit 6e61a7245a
37 changed files with 678 additions and 1169 deletions

View File

@@ -1,6 +1,6 @@
class Mat < ApplicationRecord
belongs_to :tournament
has_many :matches
has_many :matches, dependent: :destroy
has_many :mat_assignment_rules, dependent: :destroy
validates :name, presence: true

View File

@@ -1,8 +1,8 @@
class School < ApplicationRecord
belongs_to :tournament, touch: true
has_many :wrestlers, dependent: :destroy
has_many :deductedPoints, class_name: "Teampointadjust"
has_many :delegates, class_name: "SchoolDelegate"
has_many :deductedPoints, class_name: "Teampointadjust", dependent: :destroy
has_many :delegates, class_name: "SchoolDelegate", dependent: :destroy
validates :name, presence: true

View File

@@ -6,9 +6,10 @@ class Tournament < ApplicationRecord
has_many :mats, dependent: :destroy
has_many :wrestlers, through: :weights
has_many :matches, dependent: :destroy
has_many :delegates, class_name: "TournamentDelegate"
has_many :delegates, class_name: "TournamentDelegate", dependent: :destroy
has_many :mat_assignment_rules, dependent: :destroy
has_many :tournament_backups, dependent: :destroy
has_many :tournament_job_statuses, dependent: :destroy
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
@@ -263,6 +264,16 @@ class Tournament < ApplicationRecord
return error_string.blank?
end
# Check if there are any active jobs for this tournament
def has_active_jobs?
tournament_job_statuses.active.exists?
end
# Get all active jobs for this tournament
def active_jobs
tournament_job_statuses.active
end
private
def connection_adapter

View File

@@ -0,0 +1,22 @@
class TournamentJobStatus < ApplicationRecord
belongs_to :tournament, optional: false
# Validations
validates :job_name, presence: true
validates :status, presence: true
validates_inclusion_of :status, in: ["Queued", "Running", "Errored"], allow_nil: false
validates :tournament, presence: true
# Scopes
scope :active, -> { where.not(status: "Errored") }
# Class methods to find jobs for a tournament
def self.for_tournament(tournament)
where(tournament_id: tournament.id)
end
# Clean up completed jobs (should be called when job finishes successfully)
def self.complete_job(tournament_id, job_name)
where(tournament_id: tournament_id, job_name: job_name).destroy_all
end
end

View File

@@ -4,8 +4,8 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :tournaments
has_many :delegated_tournament_permissions, class_name: "TournamentDelegate"
has_many :delegated_school_permissions, class_name: "SchoolDelegate"
has_many :delegated_tournament_permissions, class_name: "TournamentDelegate", dependent: :destroy
has_many :delegated_school_permissions, class_name: "SchoolDelegate", dependent: :destroy
# Replace Devise with has_secure_password
has_secure_password

View File

@@ -3,7 +3,7 @@ class Wrestler < ApplicationRecord
belongs_to :weight, touch: true
has_one :tournament, through: :weight
has_many :matches, through: :weight
has_many :deductedPoints, class_name: "Teampointadjust"
has_many :deductedPoints, class_name: "Teampointadjust", dependent: :destroy
attr_accessor :poolAdvancePoints, :originalId, :swapId
validates :name, :weight_id, :school_id, presence: true