From cb1e15fd53fc8083573ca841fd39a2cd1eeff3ef Mon Sep 17 00:00:00 2001 From: Klaus Zanders Date: Mon, 24 Nov 2025 14:47:33 +0100 Subject: [PATCH] Aggregate several new GoodJob migrations --- ...eate_good_job_execution_error_backtrace.rb | 11 +---- ...112407_create_good_job_process_lock_ids.rb | 14 +----- ...08_create_good_job_process_lock_indexes.rb | 48 +------------------ ...2409_create_good_job_execution_duration.rb | 11 +---- db/migrate/tables/good_job_executions.rb | 5 ++ db/migrate/tables/good_job_processes.rb | 1 + db/migrate/tables/good_jobs.rb | 9 ++++ 7 files changed, 23 insertions(+), 76 deletions(-) diff --git a/db/migrate/20241202112406_create_good_job_execution_error_backtrace.rb b/db/migrate/20241202112406_create_good_job_execution_error_backtrace.rb index 2a07174e23c..a023050417a 100644 --- a/db/migrate/20241202112406_create_good_job_execution_error_backtrace.rb +++ b/db/migrate/20241202112406_create_good_job_execution_error_backtrace.rb @@ -30,14 +30,7 @@ class CreateGoodJobExecutionErrorBacktrace < ActiveRecord::Migration[7.1] def change - reversible do |dir| - dir.up do - # Ensure this incremental update migration is idempotent - # with monolithic install migration. - return if connection.column_exists?(:good_job_executions, :error_backtrace) - end - end - - add_column :good_job_executions, :error_backtrace, :text, array: true + # Moved to db/migrate/tables/good_job_executions.rb + # These files are not squashed since good_job will recreate them otherwise when an update is done. end end diff --git a/db/migrate/20241202112407_create_good_job_process_lock_ids.rb b/db/migrate/20241202112407_create_good_job_process_lock_ids.rb index 0976bbeab90..26a45e40cd0 100644 --- a/db/migrate/20241202112407_create_good_job_process_lock_ids.rb +++ b/db/migrate/20241202112407_create_good_job_process_lock_ids.rb @@ -30,17 +30,7 @@ class CreateGoodJobProcessLockIds < ActiveRecord::Migration[7.1] def change - reversible do |dir| - dir.up do - # Ensure this incremental update migration is idempotent - # with monolithic install migration. - return if connection.column_exists?(:good_jobs, :locked_by_id) - end - end - - add_column :good_jobs, :locked_by_id, :uuid - add_column :good_jobs, :locked_at, :datetime - add_column :good_job_executions, :process_id, :uuid - add_column :good_job_processes, :lock_type, :integer, limit: 2 + # Moved to several db/migrate/tables/good_job*.rb + # These files are not squashed since good_job will recreate them otherwise when an update is done. end end diff --git a/db/migrate/20241202112408_create_good_job_process_lock_indexes.rb b/db/migrate/20241202112408_create_good_job_process_lock_indexes.rb index 15599e99870..1206e99c7b4 100644 --- a/db/migrate/20241202112408_create_good_job_process_lock_indexes.rb +++ b/db/migrate/20241202112408_create_good_job_process_lock_indexes.rb @@ -29,52 +29,8 @@ #++ class CreateGoodJobProcessLockIndexes < ActiveRecord::Migration[7.1] - disable_ddl_transaction! - - # rubocop:disable Metrics/AbcSize def change - reversible do |dir| - dir.up do - unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked) - add_index :good_jobs, %i[priority scheduled_at], - order: { priority: "ASC NULLS LAST", scheduled_at: :asc }, - where: "finished_at IS NULL AND locked_by_id IS NULL", - name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked, - algorithm: :concurrently - end - - unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_locked_by_id) - add_index :good_jobs, :locked_by_id, - where: "locked_by_id IS NOT NULL", - name: :index_good_jobs_on_locked_by_id, - algorithm: :concurrently - end - - unless connection.index_name_exists?(:good_job_executions, :index_good_job_executions_on_process_id_and_created_at) - add_index :good_job_executions, %i[process_id created_at], - name: :index_good_job_executions_on_process_id_and_created_at, - algorithm: :concurrently - end - end - - dir.down do - if connection.index_name_exists?( - :good_jobs, :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked - ) - remove_index(:good_jobs, name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked) - end - - if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_locked_by_id) - remove_index(:good_jobs, name: :index_good_jobs_on_locked_by_id) - end - - if connection.index_name_exists?( - :good_job_executions, :index_good_job_executions_on_process_id_and_created_at - ) - remove_index(:good_job_executions, name: :index_good_job_executions_on_process_id_and_created_at) - end - end - end + # Moved to several db/migrate/tables/good_job*.rb + # These files are not squashed since good_job will recreate them otherwise when an update is done. end - # rubocop:enable Metrics/AbcSize end diff --git a/db/migrate/20241202112409_create_good_job_execution_duration.rb b/db/migrate/20241202112409_create_good_job_execution_duration.rb index f0d6c65d6e8..2d0fac2c984 100644 --- a/db/migrate/20241202112409_create_good_job_execution_duration.rb +++ b/db/migrate/20241202112409_create_good_job_execution_duration.rb @@ -30,14 +30,7 @@ class CreateGoodJobExecutionDuration < ActiveRecord::Migration[7.1] def change - reversible do |dir| - dir.up do - # Ensure this incremental update migration is idempotent - # with monolithic install migration. - return if connection.column_exists?(:good_job_executions, :duration) - end - end - - add_column :good_job_executions, :duration, :interval + # Moved to db/migrate/tables/good_job_executions.rb + # These files are not squashed since good_job will recreate them otherwise when an update is done. end end diff --git a/db/migrate/tables/good_job_executions.rb b/db/migrate/tables/good_job_executions.rb index 2c58b65b4b2..98345389a30 100644 --- a/db/migrate/tables/good_job_executions.rb +++ b/db/migrate/tables/good_job_executions.rb @@ -42,9 +42,14 @@ class Tables::GoodJobExecutions < Tables::Base t.datetime :finished_at t.text :error t.integer :error_event, limit: 2 + t.text :error_backtrace, array: true + t.uuid :process_id + t.duration :interval t.index %i[active_job_id created_at], name: :index_good_job_executions_on_active_job_id_and_created_at + t.index %i[process_id created_at], + name: :index_good_job_executions_on_process_id_and_created_at end end end diff --git a/db/migrate/tables/good_job_processes.rb b/db/migrate/tables/good_job_processes.rb index 2fcb8c9e87e..72d5feb4879 100644 --- a/db/migrate/tables/good_job_processes.rb +++ b/db/migrate/tables/good_job_processes.rb @@ -35,6 +35,7 @@ class Tables::GoodJobProcesses < Tables::Base create_table migration, id: :uuid do |t| t.timestamps t.jsonb :state + t.integer :lock_type, limit: 2 end end end diff --git a/db/migrate/tables/good_jobs.rb b/db/migrate/tables/good_jobs.rb index 9174e7fb51d..0a3ddacb6ec 100644 --- a/db/migrate/tables/good_jobs.rb +++ b/db/migrate/tables/good_jobs.rb @@ -53,6 +53,8 @@ class Tables::GoodJobs < Tables::Base t.text :job_class t.integer :error_event, limit: 2 t.text :labels, array: true + t.uuid :locked_by_id + t.datetime :locked_at t.index :scheduled_at, where: "(finished_at IS NULL)", @@ -89,6 +91,13 @@ class Tables::GoodJobs < Tables::Base order: { priority: "ASC NULLS LAST", created_at: :asc }, where: "finished_at IS NULL", name: :index_good_job_jobs_for_candidate_lookup + t.index %i[priority scheduled_at], + order: { priority: "ASC NULLS LAST", scheduled_at: :asc }, + where: "finished_at IS NULL AND locked_by_id IS NULL", + name: :index_good_jobs_on_priority_scheduled_at_unfinished_unlocked + t.index :locked_by_id, + where: "locked_by_id IS NOT NULL", + name: :index_good_jobs_on_locked_by_id end end end