From 85cff5ef854f16d9dcd1ac6cabddab5ddc25ed38 Mon Sep 17 00:00:00 2001 From: Malaber Date: Thu, 16 Apr 2026 16:15:45 +0200 Subject: [PATCH] Fix merged tournament sync schema in tests --- app/controllers/tournaments_controller.rb | 3 +-- ...00_ensure_tournament_sync_columns_exist.rb | 27 +++++++++++++++++++ ...ure_tournament_sync_queue_entries_exist.rb | 25 +++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20260416143000_ensure_tournament_sync_columns_exist.rb create mode 100644 db/migrate/20260416144000_ensure_tournament_sync_queue_entries_exist.rb diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index f38e6dd..a95b245 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -304,9 +304,8 @@ class TournamentsController < ApplicationController def push_sync_if_needed!(tournament) TournamentSyncEnqueue.call(tournament) end -end -def validate_set_timer_end_params + def validate_set_timer_end_params timer_end = params[:timer_end] timer_end_seconds = params[:timer_end_seconds] diff --git a/db/migrate/20260416143000_ensure_tournament_sync_columns_exist.rb b/db/migrate/20260416143000_ensure_tournament_sync_columns_exist.rb new file mode 100644 index 0000000..0e70b6e --- /dev/null +++ b/db/migrate/20260416143000_ensure_tournament_sync_columns_exist.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class EnsureTournamentSyncColumnsExist < ActiveRecord::Migration[7.0] + def change + add_column_if_missing :tournaments, :read_only_mode, :boolean, null: false, default: false + add_column_if_missing :tournaments, :sync_target_url, :string + add_column_if_missing :tournaments, :sync_auth_token, :string + add_column_if_missing :tournaments, :sync_source_tournament_id, :integer + add_column_if_missing :tournaments, :sync_last_pushed_at, :datetime + add_column_if_missing :tournaments, :sync_last_push_error, :string + + add_column_if_missing :teams, :sync_source_id, :integer + add_column_if_missing :stages, :sync_source_id, :integer + add_column_if_missing :groups, :sync_source_id, :integer + add_column_if_missing :matches, :sync_source_id, :integer + add_column_if_missing :match_scores, :sync_source_id, :integer + add_column_if_missing :group_scores, :sync_source_id, :integer + end + + private + + def add_column_if_missing(table, column, type, **options) + return if column_exists?(table, column) + + add_column(table, column, type, **options) + end +end diff --git a/db/migrate/20260416144000_ensure_tournament_sync_queue_entries_exist.rb b/db/migrate/20260416144000_ensure_tournament_sync_queue_entries_exist.rb new file mode 100644 index 0000000..fa67a5e --- /dev/null +++ b/db/migrate/20260416144000_ensure_tournament_sync_queue_entries_exist.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class EnsureTournamentSyncQueueEntriesExist < ActiveRecord::Migration[7.0] + def change + return if table_exists?(:tournament_sync_queue_entries) + + create_table :tournament_sync_queue_entries do |t| + t.integer :tournament_id, null: false + t.text :snapshot_json, null: false + t.datetime :next_attempt_at, null: false + t.datetime :last_attempt_at + t.datetime :locked_at + t.string :lock_token + t.integer :attempts, default: 0, null: false + t.string :status, default: 'pending', null: false + t.string :last_error + t.timestamps null: false + end + + add_index :tournament_sync_queue_entries, :next_attempt_at + add_index :tournament_sync_queue_entries, :status + add_index :tournament_sync_queue_entries, :tournament_id, unique: true + add_foreign_key :tournament_sync_queue_entries, :tournaments, on_delete: :cascade + end +end