Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 add guard clauses to add_indices_to_bulkrax migration #862

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions db/migrate/20230608153601_add_indices_to_bulkrax.rb
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
Loading