Skip to content

Commit 1033205

Browse files
authored
Add test for missing/pending GoodJob migrations (#1305)
GoodJob upgrades sometimes include migrations that need to be generated and run. This test alerts us to that fact.
1 parent 42ec17f commit 1033205

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
class AddIndexGoodJobsJobClass < ActiveRecord::Migration[8.0]
4+
disable_ddl_transaction!
5+
6+
def change
7+
reversible do |dir|
8+
dir.up do
9+
# Ensure this incremental update migration is idempotent
10+
# with monolithic install migration.
11+
return if connection.index_exists? :good_jobs, :job_class
12+
end
13+
end
14+
15+
add_index :good_jobs, :job_class, algorithm: :concurrently
16+
end
17+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2025_04_02_192110) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_10_10_233458) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "citext"
1616
enable_extension "pg_catalog.plpgsql"
@@ -120,6 +120,7 @@
120120
t.index ["cron_key", "created_at"], name: "index_good_jobs_on_cron_key_and_created_at_cond", where: "(cron_key IS NOT NULL)"
121121
t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at_cond", unique: true, where: "(cron_key IS NOT NULL)"
122122
t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))"
123+
t.index ["job_class"], name: "index_good_jobs_on_job_class"
123124
t.index ["labels"], name: "index_good_jobs_on_labels", where: "(labels IS NOT NULL)", using: :gin
124125
t.index ["locked_by_id"], name: "index_good_jobs_on_locked_by_id", where: "(locked_by_id IS NOT NULL)"
125126
t.index ["priority", "created_at"], name: "index_good_job_jobs_for_candidate_lookup", where: "(finished_at IS NULL)"

test/lib/good_job_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class GoodJobTest < ActiveSupport::TestCase
4+
test 'has no pending migrations' do
5+
assert GoodJob.migrated?
6+
end
7+
end

0 commit comments

Comments
 (0)