plentz / lol_dba

lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
1.59k stars 69 forks source link

NoMethodError: undefined method `sort' #149

Open Epigene opened 9 months ago

Epigene commented 9 months ago

Hi, I'm getting this error when running bundle exec rake db:find_indexes:

NoMethodError: undefined method `sort' for "lower((manufacturing_context)::text)":String (NoMethodError)

        index.columns.size > 1 ? index.columns.sort : index.columns.first
                                              ^^^^^
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:61:in `block in table_indexes'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:60:in `collect'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:60:in `table_indexes'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:55:in `existing_indexes'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:44:in `block in missing_indexes'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:42:in `each'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:42:in `missing_indexes'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:37:in `check_for_indexes'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/lol_dba/index_finding/index_finder.rb:4:in `run'
ruby-3.2.3/gems/lol_dba-2.4.0/lib/tasks/lol_dba.rake:6:in `block (2 levels) in <main>'
ruby-3.2.3/gems/bugsnag-6.26.0/lib/bugsnag/integrations/rake.rb:20:in `execute'
ruby-3.2.3/gems/rake-13.1.0/exe/rake:27:in `<top (required)>'
ruby-3.2.3/bin/ruby_executable_hooks:22:in `eval'
ruby-3.2.3/bin/ruby_executable_hooks:22:in `<main>'

This likely occurs because a synthetic index is defined:

CREATE INDEX idx_details_lower_manufacturing_context ON public.details USING btree (lower((manufacturing_context)::text));

My env: Ruby 3.2.3 Rails: 7.0 Postgres: 15.5 lol_dba (2.4.0)

h0jeZvgoxFepBQ2C commented 2 months ago

Same here: NoMethodError: undefined method `sort' for "lower((code)::text), locked_at":String Bildschirmfoto 2024-09-02 um 16 49 54

h0jeZvgoxFepBQ2C commented 2 months ago

Happens when you have a complex index