@@ -181,6 +181,16 @@ def schema_default(klass, column)
181
181
quote ( klass . column_defaults [ column . name ] )
182
182
end
183
183
184
+ def retrieve_indexes_from_table ( klass )
185
+ table_name = klass . table_name
186
+ indexes = klass . connection . indexes ( table_name )
187
+ return indexes if indexes . any? || !klass . table_name_prefix
188
+
189
+ # Try to search the table without prefix
190
+ table_name . slice! ( klass . table_name_prefix )
191
+ klass . connection . indexes ( table_name )
192
+ end
193
+
184
194
# Use the column information in an ActiveRecord class
185
195
# to create a comment block containing a line for
186
196
# each column. The line contains the column name,
@@ -244,7 +254,7 @@ def get_schema_info(klass, header, options = {})
244
254
# Check if the column has indices and print "indexed" if true
245
255
# If the index includes another column, print it too.
246
256
if options [ :simple_indexes ] && klass . table_exists? # Check out if this column is indexed
247
- indices = klass . connection . indexes ( klass . table_name )
257
+ indices = retrieve_indexes_from_table ( klass )
248
258
if indices = indices . select { |ind | ind . columns . include? col . name }
249
259
indices . sort_by ( &:name ) . each do |ind |
250
260
ind = ind . columns . reject! { |i | i == col . name }
@@ -305,7 +315,7 @@ def get_index_info(klass, options={})
305
315
index_info = "#\n # Indexes\n #\n "
306
316
end
307
317
308
- indexes = klass . connection . indexes ( klass . table_name )
318
+ indexes = retrieve_indexes_from_table ( klass )
309
319
return '' if indexes . empty?
310
320
311
321
max_size = indexes . collect { |index | index . name . size } . max + 1
0 commit comments