-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 add guard clauses to add_indices_to_bulkrax migration (#862)
add guard clauses to add_indices_to_bulkrax migration Not doing so produced the following error in Adventist, when trying to run migrations: "ArgumentError: Index name 'index_bulkrax_entries_on_identifier' on table 'bulkrax_entries' already exists"
- Loading branch information
1 parent
71a3529
commit 1fc65e4
Showing
1 changed file
with
9 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
class AddIndicesToBulkrax < ActiveRecord::Migration[5.1] | ||
def change | ||
check_and_add_index :bulkrax_entries, :identifier | ||
check_and_add_index :bulkrax_entries, :type | ||
check_and_add_index :bulkrax_entries, [:importerexporter_id, :importerexporter_type], name: 'bulkrax_entries_importerexporter_idx' | ||
check_and_add_index :bulkrax_pending_relationships, :child_id | ||
check_and_add_index :bulkrax_pending_relationships, :parent_id | ||
check_and_add_index :bulkrax_statuses, :error_class | ||
check_and_add_index :bulkrax_statuses, [:runnable_id, :runnable_type], name: 'bulkrax_statuses_runnable_idx' | ||
check_and_add_index :bulkrax_statuses, [:statusable_id, :statusable_type], name: 'bulkrax_statuses_statusable_idx' | ||
end | ||
add_index :bulkrax_entries, :identifier unless index_exists?(:bulkrax_entries, :identifier) | ||
add_index :bulkrax_entries, :type unless index_exists?(:bulkrax_entries, :type) | ||
add_index :bulkrax_entries, [:importerexporter_id, :importerexporter_type], name: 'bulkrax_entries_importerexporter_idx' unless index_exists?(:bulkrax_entries, [:importerexporter_id, :importerexporter_type], name: 'bulkrax_entries_importerexporter_idx') | ||
|
||
add_index :bulkrax_pending_relationships, :parent_id unless index_exists?(:bulkrax_pending_relationships, :parent_id) | ||
add_index :bulkrax_pending_relationships, :child_id unless index_exists?(:bulkrax_pending_relationships, :child_id) | ||
|
||
def check_and_add_index(table_name, column_name, options = {}) | ||
add_index(table_name, column_name, options) unless index_exists?(table_name, column_name, options) | ||
add_index :bulkrax_statuses, [:statusable_id, :statusable_type], name: 'bulkrax_statuses_statusable_idx' unless index_exists?(:bulkrax_statuses, [:statusable_id, :statusable_type], name: 'bulkrax_statuses_statusable_idx') | ||
add_index :bulkrax_statuses, [:runnable_id, :runnable_type], name: 'bulkrax_statuses_runnable_idx' unless index_exists?(:bulkrax_statuses, [:runnable_id, :runnable_type], name: 'bulkrax_statuses_runnable_idx') | ||
add_index :bulkrax_statuses, :error_class unless index_exists?(:bulkrax_statuses, :error_class) | ||
end | ||
end |