Skip to content

Commit 6ce3c96

Browse files
committed
Fixed Posgresql index tables with public.
1 parent 2d7694e commit 6ce3c96

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ group :development, :test do
1919
gem 'rubocop', '~> 0.37.2', require: false unless RUBY_VERSION =~ /^1.8/
2020
gem 'coveralls'
2121
gem 'codeclimate-test-reporter'
22+
gem 'ruby_dep', '1.3.1'
2223

2324
platforms :mri, :mingw do
2425
gem 'pry', require: false

lib/annotate/annotate_models.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ def schema_default(klass, column)
181181
quote(klass.column_defaults[column.name])
182182
end
183183

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+
184194
# Use the column information in an ActiveRecord class
185195
# to create a comment block containing a line for
186196
# each column. The line contains the column name,
@@ -244,7 +254,7 @@ def get_schema_info(klass, header, options = {})
244254
# Check if the column has indices and print "indexed" if true
245255
# If the index includes another column, print it too.
246256
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)
248258
if indices = indices.select { |ind| ind.columns.include? col.name }
249259
indices.sort_by(&:name).each do |ind|
250260
ind = ind.columns.reject! { |i| i == col.name }
@@ -305,7 +315,7 @@ def get_index_info(klass, options={})
305315
index_info = "#\n# Indexes\n#\n"
306316
end
307317

308-
indexes = klass.connection.indexes(klass.table_name)
318+
indexes = retrieve_indexes_from_table(klass)
309319
return '' if indexes.empty?
310320

311321
max_size = indexes.collect{|index| index.name.size}.max + 1

0 commit comments

Comments
 (0)