Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for versions of ActiveRecord pre-2.3.4 (primary_key on MySQL …

…ConnectionAdapter only added in this version)
  • Loading branch information...
commit 108ae38edd362a3988ce213d192ab3a15a3dd392 1 parent e98c8f1
@samsworldofno authored
Showing with 19 additions and 2 deletions.
  1. +19 −2 lib/classes/table_index.rb
View
21 lib/classes/table_index.rb
@@ -28,13 +28,30 @@ def self.merge_to_one_per_table(indexes)
def exists_in_database?
existing_indexes = []
+ connection = ActiveRecord::Base.connection
- ActiveRecord::Base.connection.indexes(self.table).each do |index|
+ connection.indexes(self.table).each do |index|
existing_indexes << index.columns.sort
end
- existing_indexes << Array(ActiveRecord::Base.connection.primary_key(self.table))
+ existing_indexes << Array(get_table_primary_key)
existing_indexes.include?(self.fields.sort)
end
+
+ protected
+ def get_table_primary_key
+ connection = ActiveRecord::Base.connection
+
+ if connection.respond_to?(:primary_key)
+ # This method introduced in ActiveRecord 2.3.4
+ connection.primary_key(self.table)
+ elsif connection.respond_to?(:pk_and_sequence)
+ pk_and_sequence = connection.pk_and_sequence_for(self.table)
+ pk_and_sequence && pk_and_sequence.first
+ else
+ # Broad assumption!
+ 'id'
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.