Skip to content

Commit

Permalink
Merge pull request #198 from alces-flight/chore/good-job-migrations
Browse files Browse the repository at this point in the history
Add missing good job migrations
  • Loading branch information
benarmston authored Mar 14, 2024
2 parents 2a9c885 + de27194 commit cd28f3e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

class RecreateGoodJobCronIndexesWithConditional < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
reversible do |dir|
dir.up do
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at_cond)
add_index :good_jobs, [:cron_key, :created_at], where: "(cron_key IS NOT NULL)",
name: :index_good_jobs_on_cron_key_and_created_at_cond, algorithm: :concurrently
end
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at_cond)
add_index :good_jobs, [:cron_key, :cron_at], where: "(cron_key IS NOT NULL)", unique: true,
name: :index_good_jobs_on_cron_key_and_cron_at_cond, algorithm: :concurrently
end

if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at)
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_created_at
end
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at)
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_cron_at
end
end

dir.down do
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at)
add_index :good_jobs, [:cron_key, :created_at],
name: :index_good_jobs_on_cron_key_and_created_at, algorithm: :concurrently
end
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at)
add_index :good_jobs, [:cron_key, :cron_at], unique: true,
name: :index_good_jobs_on_cron_key_and_cron_at, algorithm: :concurrently
end

if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_created_at_cond)
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_created_at_cond
end
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_cron_key_and_cron_at_cond)
remove_index :good_jobs, name: :index_good_jobs_on_cron_key_and_cron_at_cond
end
end
end
end
end
15 changes: 15 additions & 0 deletions db/migrate/20240313144612_create_good_job_labels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class CreateGoodJobLabels < 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, :labels)
end
end

add_column :good_jobs, :labels, :text, array: true
end
end
22 changes: 22 additions & 0 deletions db/migrate/20240313144613_create_good_job_labels_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class CreateGoodJobLabelsIndex < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
reversible do |dir|
dir.up do
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_labels)
add_index :good_jobs, :labels, using: :gin, where: "(labels IS NOT NULL)",
name: :index_good_jobs_on_labels, algorithm: :concurrently
end
end

dir.down do
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_labels)
remove_index :good_jobs, name: :index_good_jobs_on_labels
end
end
end
end
end
21 changes: 21 additions & 0 deletions db/migrate/20240313144614_remove_good_job_active_id_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class RemoveGoodJobActiveIdIndex < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
reversible do |dir|
dir.up do
if connection.index_name_exists?(:good_jobs, :index_good_jobs_on_active_job_id)
remove_index :good_jobs, name: :index_good_jobs_on_active_job_id
end
end

dir.down do
unless connection.index_name_exists?(:good_jobs, :index_good_jobs_on_active_job_id)
add_index :good_jobs, :active_job_id, name: :index_good_jobs_on_active_job_id
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

class CreateIndexGoodJobJobsForCandidateLookup < ActiveRecord::Migration[7.1]
disable_ddl_transaction!

def change
reversible do |dir|
dir.up do
# Ensure this incremental update migration is idempotent
# with monolithic install migration.
return if connection.index_name_exists?(:good_jobs, :index_good_job_jobs_for_candidate_lookup)
end
end

add_index :good_jobs, [:priority, :created_at], order: { priority: "ASC NULLS LAST", created_at: :asc },
where: "finished_at IS NULL", name: :index_good_job_jobs_for_candidate_lookup,
algorithm: :concurrently
end
end
10 changes: 6 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cd28f3e

Please sign in to comment.