Skip to content

Commit 3eb76a5

Browse files
author
Janusz Mordarski
committed
Fix indexes method - use SpatialIndexDefinition only for type :spatial
1 parent a255544 commit 3eb76a5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/active_record/connection_adapters/mysql2spatial_adapter/main_adapter.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def columns(table_name_, name_=nil)
120120
columns_
121121
end
122122

123-
123+
# Returns an array of indexes for the given table.
124124
def indexes(table_name_, name_=nil)
125125
indexes_ = []
126126
current_index_ = nil
@@ -129,11 +129,20 @@ def indexes(table_name_, name_=nil)
129129
if current_index_ != row_[:Key_name]
130130
next if row_[:Key_name] == 'PRIMARY' # skip the primary key
131131
current_index_ = row_[:Key_name]
132-
indexes_ << ::RGeo::ActiveRecord::SpatialIndexDefinition.new(row_[:Table], row_[:Key_name], row_[:Non_unique] == 0, [], [], row_[:Index_type] == 'SPATIAL')
132+
mysql_index_type = row_[:Index_type].downcase.to_sym
133+
index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil
134+
index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil
135+
options = [row_[:Table], row_[:Key_name], row_[:Non_unique].to_i == 0, [], [], nil, nil, index_type, index_using]
136+
indexes_ << if mysql_index_type == :spatial
137+
options.push(true)
138+
::RGeo::ActiveRecord::SpatialIndexDefinition.new(*options)
139+
else
140+
IndexDefinition.new(*options)
141+
end
133142
end
134143
last_index_ = indexes_.last
135144
last_index_.columns << row_[:Column_name]
136-
last_index_.lengths << row_[:Sub_part] unless last_index_.spatial
145+
last_index_.lengths << row_[:Sub_part] unless mysql_index_type == :spatial
137146
end
138147
indexes_
139148
end

0 commit comments

Comments
 (0)