Skip to content

Commit

Permalink
allow ruby 3 syntax in migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf authored Aug 29, 2023
1 parent fe51a43 commit 3dac0f5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions db/migrate/20230608153601_add_indices_to_bulkrax.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This migration comes from bulkrax (originally 20230608153601)
class AddIndicesToBulkrax < ActiveRecord::Migration[5.1]
def change
check_and_add_index :bulkrax_entries, :identifier
Expand All @@ -10,7 +11,15 @@ def change
check_and_add_index :bulkrax_statuses, [:statusable_id, :statusable_type], name: 'bulkrax_statuses_statusable_idx'
end

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)
if RUBY_VERSION =~ /^2/
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)
end
elsif RUBY_VERSION =~ /^3/
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)
end
else
raise "Ruby version #{RUBY_VERSION} is unknown"
end
end

0 comments on commit 3dac0f5

Please sign in to comment.