Git Product home page Git Product logo

lol_dba's Introduction

lol_dba ci Maintainability Test Coverage

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.

Quick example

To use lol_dba in the easiest way possible you have to do two things:

gem install lol_dba

Then run one of the following commands...

To display a migration for adding/removing all necessary indexes based on associations:

lol_dba db:find_indexes

To generate .sql files for your migrations inside db/migrate_sql folder:

lol_dba db:migrate_sql # defaults to all migrations
lol_dba db:migrate_sql[pending] # only pending migrations
lol_dba db:migrate_sql[20120221205526] # generate sql only for migration 20120221205526

Not-so-quick example

If you want to use lol_dba with rake, you should do a few more steps:

Add lol_dba to your Gemfile

gem "lol_dba"

Run the install command

bundle install

Use it the same way you use other rake commands

rake db:find_indexes
rake db:migrate_sql # defaults to all migrations
rake db:migrate_sql[pending] # only pending migrations
rake db:migrate_sql[20120221205526] # generate sql only for migration 20120221205526

Compatibility

Compatible with Ruby 2.x, Ruby 3.x and Rails 3.x, 4.x, 5.x, 6.x, and 7.x.

About primary_key

The primary key is always indexed. This is generally true for all storage engines that at all supports indexes.

For this reason, we no longer suggest to add indexes to primary keys.

Tests

To run lol_dba tests, just clone the repo and run:

bundle install && rake

Contributors

Most of the initial code came from rails_indexes and migration_sql_generator. Other people helped as well.

License

Lol DBA is released under the MIT license.

lol_dba's People

Contributors

a2ikm avatar alebruck avatar amnesia7 avatar andersoncardoso avatar andrew avatar andyw8 avatar chmurph2 avatar cmason avatar dependabot[bot] avatar edavis10 avatar efueger avatar fgrehm avatar ivanovaleksey avatar jamesbowles avatar olleolleolle avatar petergoldstein avatar pikachuexe avatar plentz avatar rzane avatar sadfuzzy avatar skunkworker avatar sobrinho avatar tapajos avatar warpc avatar zainosaurus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lol_dba's Issues

Not idempotent

I ran lol_dba db:find_indexes once, made a few changes, and ran it again, and the ordering was different. Maybe it's because it searches for files and the order in which they get returned depends on when they were last modified.

A simple alphabetical search at some stage of the process should fix this.

Index column is incorrect when subclasses are involved

I'm not positive I pinned down the problem in the issue title, but here's what's happening. A line generated by lol_dba reads like this: add_index :foo, [:bar_id, :subclass_id] when it should read like this: add_index :foo, [:bar_id, :baz_id]

Here's my class structure:

class Bar < ActiveRecord::Base
  has_many :foo
end

class Baz < ActiveRecord::Base
  has_may :foo
end

class BazSubclass < Baz
end

class Foo < ActiveRecord::Base
  belongs_to :baz
  belongs_to :bar
end

It looks like lol_dba is using the subclass name instead of the parent class name for some reason.

Namespaced models issue

Class: Spree::Taxon
Association type: has_many
Association options: {:through=>:classifications, :extend=>[]}
Exception: uninitialized constant Classification
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:229:in `each'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/inflector/methods.rb:229:in `constantize'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/activesupport-3.2.16/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba.rb:137:in `block (2 levels) in check_for_indexes'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `each_pair'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `each'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `check_for_indexes'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba.rb:190:in `simple_migration'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba/cli.rb:29:in `start'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/lib/lol_dba/cli.rb:17:in `start'
/Users/peterberkenbosch/.gem/ruby/1.9.3/gems/lol_dba-1.6.0/bin/lol_dba:10:in `<top (required)>'
/Users/peterberkenbosch/.gem/ruby/1.9.3/bin/lol_dba:23:in `load'
/Users/peterberkenbosch/.gem/ruby/1.9.3/bin/lol_dba:23:in `<main>'

The issue is the missing Spree namespace on the Classification. So it should be Spree::Classification

table does not exist

Unfortunately there is no more output there which I could provide.
If you give me a hint, I'll look into the details.

I suspect there is some problem with has_many through: associations, maybe in combination with STI, as Team is a subclass of another model.

Error running rake db:find_indexes

Class: Site
Association type: has_many
Association options: {:through=>:users, :extend=>[]}
Exception: undefined method `options' for nil:NilClass
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/lol_dba.rb:129:in `block (2 levels) in check_for_indexes'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/lol_dba.rb:92:in `each_pair'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/lol_dba.rb:86:in `each'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/lol_dba.rb:86:in `check_for_indexes'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/lol_dba.rb:179:in `simple_migration'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/lol_dba-2.0.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/vagrant/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/vagrant/.rvm/gems/ruby-2.1.6/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.1.6/bin/rake:23:in `load'
/home/vagrant/.rvm/gems/ruby-2.1.6/bin/rake:23:in `<main>'
/home/vagrant/.rvm/gems/ruby-2.1.6/bin/ruby_executable_hooks:15:in `eval'
/home/vagrant/.rvm/gems/ruby-2.1.6/bin/ruby_executable_hooks:15:in `<main>'

source option in the model can not be found

I have 2 models, such as:

#encoding: utf-8
class Kullanici < ActiveRecord::Base
  has_many :yetki_atamalar, :class_name => "YetkiAtama", :foreign_key => :bakan_id
  has_many :yerine_baktigi_kullanicilar, :through => :yetki_atamalar, :source => :yerine
..
end

class YetkiAtama < ActiveRecord::Base
  attr_accessible :bakan_id, :yerine_id
...
end

lol dba has a problem with the source attribute. Here is the log:

Class: Kullanici
Association type: has_many
Association options: {:through=>:yetki_atamalar, :source=>:yerine, :extend=>[]}
uninitialized constant Yerine
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in consta194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gemsector/methods.rb:229:in `constantize'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/lol_dba-1.3.0/lib/lol_dba.rb:140:in `block (2 levels) in check_for_indexes'\", \l_dba-1.3.0/lib/lol_dba.rb:104:in `each_pair'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/lol_dba-1.3.0/lib/lol_dba.rb:104:in .rvm/gems/ruby-1.9.3-p194/gems/lol_dba-1.3.0/lib/lol_dba.rb:95:in `each'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/lol_dba-1'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/lol_dba-1.3.0/lib/lol_dba.rb:200:in `simple_migration'
/home/bor/.rvm/gems//lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/tasruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/task.rb:227:in `block in execute'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-1ome/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/task.rb:222:in `execute'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gek in invoke_with_call_chain'
/home/bor/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
e-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/tass/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/application.rb:141:in `invoke_task'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rack (2 levels) in top_level'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/application.rb:99:in `each'
e-10.0.2/lib/rake/application.rb:99:in `block in top_level'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/a"/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/application.rb:93:in `top_level'
/home/bor/.rvm/gems/ruby-1.on.rb:71:in `block in run'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exuby-1.9.3-p194/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
/home/bor/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.2/bior/.rvm/gems/ruby-1.9.3-p194/bin/rake:19:in `load'
/home/bor/.rvm/gems/ruby-1.9.3-p194/bin/rake:19:in `<main>'
/home/b_wrapper:14:in `eval'
/home/bor/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'\"]"
BUG: table 'ekran_goruntuleri' does not exist, please report this bug.

Error with mssql driver, possibly others

I'm trying to use lol_dba for generating migrations as raw SQL and it is brilliant, but I ran into a problem when testing with SQL server. I'm using jRuby and the source of the active record JDBC driver for SQL server queries the version of the database using select_value.

Tracing the source, this eventually calls select_all which has be redefined by lol_dba to return an array, meaning that the adapter is given an empty array instead of the result from the database, which then causes an exception to be raised.

I've made a minor alteration to a local copy so that the redefinition of select all does a similar test to some of the other implementations so it checks for the type of query. This is my change

connection.class.send(:define_method, :select_all) { |*args| 
  if args.first =~ /SELECT @@version/
    self.orig_select_all(*args)
  else
    []
  end
}

This is very specific to SQL server hence I haven't made a new pull request, but I imagine this may be a problem for other DBMS engines?

Add Ruby version Runtime Dependencies

Hello,
You wrote that you still support ruby 1.9.3. But I found it hard to install the last 1.6.x version of lol_dba using gem 'lol_dba' in my Gemfile.

Gem::InstallError: lol_dba requires Ruby version >= 2.0.0.
An error occurred while installing lol_dba (1.6.7), and Bundler cannot continue.
Make sure that `gem install lol_dba -v '1.6.7'` succeeds before bundling

Btw, I have successfully installed 1.5.x version that is compatible with ruby 1.9.3.
In my Gemfile I have the runtime dependency for ruby. So I think it would be useful to update runtime dependency for this gem lol_dba.
Do you think?

Another through issue

Class: City
Association type: has_many
Association options: {:through=>:addresses, :source=>:addressable, :source_type=>"Apartment", :extend=>[]}
Exception: undefined method `reflections' for Addressable:Module
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:21:in `get_through_foreign_key'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:128:in `block (2 levels) in check_for_indexes'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `each_pair'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `each'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `check_for_indexes'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/lol_dba.rb:190:in `simple_migration'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/lol_dba-1.6.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/uriklar/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:150:in `invoke_task'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `each'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block in top_level'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:115:in `run_with_threads'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:100:in `top_level'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:78:in `block in run'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/lib/rake/application.rb:75:in `run'
/home/uriklar/.rvm/gems/ruby-2.1.0/gems/rake-10.2.2/bin/rake:33:in `<top (required)>'
/home/uriklar/.rvm/gems/ruby-2.1.0/bin/rake:23:in `load'
/home/uriklar/.rvm/gems/ruby-2.1.0/bin/rake:23:in `<main>'
/home/uriklar/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
/home/uriklar/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'

Not working for some associations

Class: User
Association type: has_many
Association options: {:through=>:followings, :source=>:users, :order=>"created_at DESC", :extend=>[]}
Exception: undefined method `klass' for nil:NilClass
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:127:in `block (2 levels) in check_for_indexes'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:92:in `each_pair'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:88:in `each'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:88:in `check_for_indexes'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:190:in `simple_migration'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/manoj/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/bin/rake:19:in `load'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/bin/rake:19:in `<main>'
/Users/manoj/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval'
/Users/manoj/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>'
Class: Question
Association type: has_many
Association options: {:through=>:question_sets, :source=>:questionable, :source_type=>"Group", :extend=>[]}
Exception: uninitialized constant QuestionSet::Questionable
/Users/manoj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/inheritance.rb:111:in `compute_type'
/Users/manoj/.rvm/gems/[email protected]/gems/activerecord-3.2.13/lib/active_record/reflection.rb:172:in `klass'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:127:in `block (2 levels) in check_for_indexes'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:92:in `each_pair'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:88:in `each'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:88:in `check_for_indexes'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/lol_dba.rb:190:in `simple_migration'
/Users/manoj/.rvm/gems/[email protected]/gems/lol_dba-1.5.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/manoj/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/bin/rake:19:in `load'
/Users/manoj/.rvm/gems/ruby-1.9.3-p429@global/bin/rake:19:in `<main>'
/Users/manoj/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval'
/Users/manoj/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>'

fix the tests

in the process of improving lol_dba compatibility with rails 3.x, I've broke some tests. fixe'm all!

has_and_belong_to_many with class_name option generates the wrong add_index migration.

I have a has_and_belong_to_many (HABTM) between User and Account.

The association definitions are as follows:

class Account < ActiveRecord::Base
    has_and_belongs_to_many :users
end

class User < ActiveRecord::Base
    has_and_belongs_to_many :accessible_accounts, class_name: Account
end

The resulting index from lol_dba is:

add_index :accounts_users, [:accessible_account_id, :user_id]

Essentially it is ignoring the class_name option in the HABTM association definition.

I call the association from User to Accounts, accessible_accounts because I have a method called accounts that checks to see if they're a "super user" in which case they get access to all Accounts, otherwise, they only get access to the Accounts from the accessible_accounts relationship.

Thanks!

Through issue

Class: User
Association type: has_many
Association options: {:through=>:follow_teams, :source=>"team", :extend=>[]}
Exception: undefined method `klass' for nil:NilClass
/usr/local/rvm/gems/ruby-2.1.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:121:in `block (2 levels) in check_for_indexes'

Don't know why. Here is the has_many association.
has_many :followed_teams, through: :follow_teams, source: "team"

Thanks in advance.

Exception: undefined method `klass' for nil:NilClass

I tested with a Rails 4.2.0.beta2 application, to find missing indexes.
lol_dba gives some warnings, and lists indexes.

Here is the stack trace;

WARN: Unresolved specs during Gem::Specification.reset:
      activerecord (>= 3.0)
      actionpack (>= 3.0)
      railties (>= 3.0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Some errors here:
Please, create an issue with the following information here https://github.com/plentz/lol_dba/issues:
***************************
Class: User
Association type: has_many
Association options: {:through=>:managers}
Exception: undefined method `klass' for nil:NilClass
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:121:in `block (2 levels) in check_for_indexes'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:92:in `each_pair'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:88:in `each'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:88:in `check_for_indexes'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:190:in `simple_migration'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba/cli.rb:29:in `start'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/lib/lol_dba/cli.rb:17:in `start'
/Users/dev/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.4/bin/lol_dba:10:in `<top (required)>'
/Users/dev/.rbenv/versions/2.1.2/bin/lol_dba:23:in `load'
/Users/dev/.rbenv/versions/2.1.2/bin/lol_dba:23:in `<main>'
Some errors here:
Please, create an issue with the following information here https://github.com/plentz/lol_dba/issues:

Exception: comparison of Symbol with String failed

In some class I have an HABTM association defined where the foreign key is given as symbol which leads to the exception in the title. Changing the symbol to a string fixes this issue, so there probably is some to_s missing somewhere.

has_and_belongs_to_many :teams, association_foreign_key: :circle_id is bad
has_and_belongs_to_many :teams, association_foreign_key: 'circle_id' is fine

:class_name in has_many is not handled

Nice of you to solicit this feedback!

The error:

"Class: User"
"Association type: has_many"
"Association options: {:through=>:memberships, :source=>:group, :source_type=>\"Club\", :conditions=>{:clubs=>{:group=>\"club\"}, :memberships=>{:role=>\"manager\"}}, :extend=>[]}"
"uninitialized constant Group"

The association:

has_many :clubs, through: :memberships, source: :group, source_type: "Club", conditions: { clubs: { group: "club", type: nil }, memberships: { role: "member" }}

The memberships schema:

  create_table "memberships", :force => true do |t|
    t.integer  "user_id",                          :null => false
    t.integer  "group_id",                         :null => false
    t.string   "group_type",                       :null => false
    t.string   "role",       :default => "member", :null => false
    t.datetime "created_at"
    t.datetime "updated_at"

acts_as_taggable problem?

I was told to put this here, no idea why this happens because it does create the actual index regardless.

Class: Contact
Association type: has_many
Association options: {:through=>:tag_taggings, :source=>:tag, :class_name=>\"ActsAsTaggableOn::Tag\", :extend=>[]}
uninitialized constant TagTagging


/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/lol_dba.rb:135:in `block (2 levels) in check_for_indexes'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/lol_dba.rb:104:in `each_pair'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/lol_dba.rb:104:in `block in check_for_indexes'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/lol_dba.rb:95:in `each'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/lol_dba.rb:95:in `check_for_indexes'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/lol_dba.rb:200:in `simple_migration'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/gems/lol_dba-1.3.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/mhenrixon/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/bin/ruby_noexec_wrapper:14:in `eval'
/Users/mhenrixon/.rvm/gems/ruby-1.9.3-p194@Linq/bin/ruby_noexec_wrapper:14:in `<main>'

one or two bugs... maybe related to custom table name

Very well done! I like this recommendation to report an error


"Some errors here:"
"Please add info after this string in to https://github.com/plentz/lol_dba/issues"
"Class: B"
"Association type: has_many"
"Association options: {:through=>:a_to_bs, :extend=>[]}"
"undefined method `options' for nil:NilClass"

"[\"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/lol_dba.rb:145:in `block (2 levels) in check_for_indexes'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/lol_dba.rb:104:in `each_pair'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/lol_dba.rb:104:in `block in check_for_indexes'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/lol_dba.rb:95:in `each'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/lol_dba.rb:95:in `check_for_indexes'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/lol_dba.rb:200:in `simple_migration'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/lol_dba-1.3.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:205:in `call'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:200:in `each'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:200:in `execute'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:94:in `each'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/rake/application.rb:63:in `run'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:32:in `<top (required)>'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/bin/rake:23:in `load'\", \"/Users/xxx/.rbenv/versions/1.9.3-p125/bin/rake:23:in `<main>'\"]"
BUG: table 'log_info_table' does not exist, please report this bug.

It looks like two bugs to me... Whereas the second bug might be caused, due to a different db and table name.

class Flexviews::LogInfo < ActiveRecord::Base
  establish_connection ("flexviews_" + Rails.env).to_sym
  self.table_name = 'log_info_table'
  [...]
end

Handle too long index name

MySQL has a limitation on the length of the index name, not sure if it applies to other databases as well

Would be nice if it automatically shortened the name of the index

Its done like this with the extra name attribute

add_index :studies, ["user_id", "university_id", \
          "subject_name_id", "subject_type_id"], 
          :unique => true, :name => 'my_index'

Unitialized Constant On Polymorphic Through Association

First up, here is the dump when I run rake db:find_indexes:

Class: Page
Association type: has_many
Association options: {:through=>:slots, :source=>:slottable, :source_type=>"TextElement", :autosave=>true}
Exception: uninitialized constant Slot::Slottable
/Users/pedr/.gem/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/inheritance.rb:133:in `compute_type'
/Users/pedr/.gem/ruby/2.0.0/gems/activerecord-4.1.5/lib/active_record/reflection.rb:221:in `klass'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:127:in `block (2 levels) in check_for_indexes'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:92:in `each_pair'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:88:in `each'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:88:in `check_for_indexes'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/lol_dba.rb:190:in `simple_migration'
/Users/pedr/.gem/ruby/2.0.0/gems/lol_dba-1.6.4/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/pedr/.rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Users/pedr/.gem/ruby/2.0.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/Users/pedr/.gem/ruby/2.0.0/bin/rake:23:in `load'
/Users/pedr/.gem/ruby/2.0.0/bin/rake:23:in `<main>'

The app is working fine and the relevant setup is:

class Page < ActiveRecord::Base 
   has_many :slots
   has_many :text_elements, through: :slots, source: :slottable, source_type: 'TextElement'
end

class Slot < ActiveRecord::Base
  belongs_to :page
  belongs_to :slottable, polymorphic: true
end

Exception: undefined method `options' for nil:NilClass

Class: Accommodation::Allotment
Association type: has_many
Association options: {:class_name=>"Accommodation::Booking", :through=>:quantities}

Exception: undefined method `options' for nil:NilClass

/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:129:in `block (2 levels) in check_for_indexes'
/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:92:in `each_pair'
/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:86:in `each'
/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:86:in `check_for_indexes'
/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:179:in `simple_migration'
/Users/piciben/.rvm/gems/ruby-2.2.0/gems/lol_dba-2.0.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/piciben/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
./bin/rake:8:in `<main>'

undefined method `reflections' for Categorical:Module

Class: Product
Association type: has_many
Association options: {:through=>:product_categories, :source=>:categorical, :source_type=>"Genre", :extend=>[]}
Exception: undefined method `reflections' for Categorical:Module
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:21:in `get_through_foreign_key'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:128:in `block (2 levels) in check_for_indexes'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `each_pair'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `each'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `check_for_indexes'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/lol_dba.rb:190:in `simple_migration'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/lol_dba-1.6.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/stewartknapman/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/bin/rake:19:in `load'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/bin/rake:19:in `<main>'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/bin/ruby_noexec_wrapper:14:in `eval'
/Users/stewartknapman/.rvm/gems/ruby-1.9.3-p385@heroes/bin/ruby_noexec_wrapper:14:in `<main>'

I got this one twice.

error while generating .sql migrations with indexes modifications

first we need to understand how lol_dba works: it basically runs every migration of your application "against the current database". what it actually does is redirect the scripts that should be executed in the database to it's corresponding .sql file.

now, lets dig in the bug. there's 2 situations with indexes where an error will happen:

  • if you have a remove_index migration
  • if you have a add_index migration that adds a index to a table that don't exist anymore when using rsim/oracle-enhanced

why this happen: in the remove_index situation, when you try to remove an index, rails will try to inspect the table schema to determine if the index still exists. since the index doesn't exist anymore(because you already ran the migrations in the current database, so the drop index was executed before). the error when the remove_index is used will look like this:

Index name 'some_index_on_some_table' on table 'customer_teams' does not exist
/Users/plentz/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/schema_statements.rb:587:in `index_name_for_remove'
/Users/plentz/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/schema_statements.rb:366:in `remove_index'
/Users/plentz/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/migration.rb:466:in `block in method_missing'
/Users/plentz/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/plentz/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time'
/Users/plentz/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/migration.rb:458:in `method_missing'
/Users/plentz/Projects/prime/foo/db/migrate/20130130123719_remove_some_index_migration.rb:4:in `up'

However, if you're using rsim/oracle-enhanced and you have a migration that adds a index to a table that no longer exists(see a scenario bellow), it will also generated an error because of the way it works. The scenario is something like this

20120301175922_create_table_foo.rb
20120301275922_add_index_on_some_column_of_table_foo.rb
20120301375922_drop_table_foo.rb

The error will look like this

"DESC grids" failed; does it exist?
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:76:in `describe'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb:192:in `index_name_exists?'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb:135:in `add_index'
org/jruby/RubyBasicObject.java:1671:in `__send__'
org/jruby/RubyKernel.java:2094:in `send'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.11/lib/active_record/migration.rb:466:in `method_missing'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.11/lib/active_record/migration.rb:458:in `method_missing'
org/jruby/RubyBasicObject.java:1671:in `__send__'
org/jruby/RubyKernel.java:2094:in `send'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.11/lib/active_record/migration.rb:334:in `method_missing'
/var/lib/jenkins/jobs/foo (generate sql)/workspace/db/migrate/20120301175922_add_some_index.rb:29:in `up'

Error running db:findindexes

Class: Dojo
Association type: has_many
Association options: {:through=>:disciplines}
Exception: undefined method `options' for nil:NilClass
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/lol_dba.rb:131:in `block (2 levels) in check_for_indexes'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/lol_dba.rb:90:in `each_pair'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/lol_dba.rb:90:in `block in check_for_indexes'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/lol_dba.rb:86:in `each'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/lol_dba.rb:86:in `check_for_indexes'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/lol_dba.rb:177:in `simple_migration'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/lol_dba-1.6.7/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/Users/tvoet/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/Users/tvoet/.rbenv/versions/2.1.0/bin/rake:23:in `load'
/Users/tvoet/.rbenv/versions/2.1.0/bin/rake:23:in `<main>'

Polymorphic indexes invert field order and thought of as non-existing

In my original migration, consider something like this:

create_table :comments do |t|
t.references :commentable, polymorphic: true, index: true
end

This will create a "index_comments_on_commentable_type_and_commentable_id" (note the order of the fields)

When I run the gem, it will tell me that I should create an index on
create_index :comments, [:commentable_id, :commentable_type]

This is a handy tool, as a starting point. I only could really add 3 of the 13 or so indexes it proposed because the others either already existed in different field order, or the fields were not on the table.

No gemspec error

If I install lol_dba as a gem from the Github master branch (to compensate for the fact that the last Rubygems release was some time ago) using gem 'lol_dba', github: 'plentz/lol_dba' I get the following error when doing bundle update:

RuntimeError: no gemspec found
An error occurred while installing lol_dba (1.6.0), and Bundler cannot continue.

I get the feeling a Gemspec should be present...

index creation inconsistencies

we should add tests to make sure that every version find the same indexes

> billable_weeks - ["remote_worker_id", "timesheet_id", ["freelancer_id", "timesheet_id"]]
> billable_weeks - ["remote_worker_id", "timesheet_id", ["remote_worker_id", "timesheet_id"]]
> billable_weeks - ["remote_worker_id", "timesheet_id", ["timesheet_id", "worker_id"], ["remote_worker_id", "timesheet_id"], ["freelancer_id", "timesheet_id"]]
> billable_weeks - ["remote_worker_id", "timesheet_id", ["timesheet_id", "worker_id"]]

> companies_freelancers - [["company_id", "freelancer_id"], "company_id", "freelancer_id"]
> companies_freelancers - [["company_id", "freelancer_id"], "freelancer_id", "company_id"]
> companies_freelancers - [["company_id", "freelancer_id"]]
> companies_freelancers - [["employer_id", "worker_id"], ["company_id", "freelancer_id"], ["employer_id", "freelancer_id"]]

> complex_billable_week - [["complex_timesheet_id", "freelancer_id"], "slave_id", "id_complex_timesheet", ["id_complex_timesheet", "worker_id"], ["freelancer_id", "id_complex_timesheet"]]
> complex_billable_week - [["freelancer_id", "id_complex_timesheet"], "slave_id", "id_complex_timesheet", ["complex_timesheet_id", "freelancer_id"], ["id_complex_timesheet", "worker_id"]]
> complex_billable_week - [["id_complex_timesheet", "worker_id"], "slave_id", "id_complex_timesheet", ["freelancer_id", "id_complex_timesheet"]]
> complex_billable_week - [["id_complex_timesheet", "worker_id"], ["complex_timesheet_id", "freelancer_id"], "slave_id", "id_complex_timesheet", ["freelancer_id", "id_complex_timesheet"]]

> purchases - [["buyer_id", "present_id"], "buyer_id", "present_id"]
> purchases - [["buyer_id", "present_id"], "buyer_id", "present_id"]
> purchases - [["buyer_id", "present_id"]]
> purchases - [["buyer_id", "present_id"]]

:class_name in has_many is not handled

The following association is correct:

has_many :user_disliked_links, :class_name => "DislikedLink"

But :class_name is probably not handled, because I got this error message.

Class: User
Association type: has_many
Association options: throughuser_disliked_linksorderdisliked_links.created_at descsourcelinkextend
uninitialized constant UserDislikedLink

In reality, the constant should be 'DislikedLink'.

Create differently titled migration if migration exists already

I have previously run rails g migration AddMissingIndexes

I wanted to run it again but there is a name clash with the previous migration. Would be helpful it it automatically added a number to the name or something or had an options to manually change the name

Exception: undefined method `klass' for nil:NilClass

Class: Collector
Association type: has_many
Association options: {:through=>:loan_collectors, :extend=>[]}
Exception: undefined method `klass' for nil:NilClass
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/lol_dba.rb:121:in `block (2 levels) in check_for_indexes'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `each_pair'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `each'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `check_for_indexes'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/lol_dba.rb:190:in `simple_migration'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/lol_dba-1.6.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/var/rbenv/versions/2.1.1/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/gems/rake-10.1.1/bin/rake:33:in `<top (required)>'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/bin/rake:23:in `load'
/Volumes/MacHD/Users/denis/code/mili/mili/vendor/bundle/bin/rake:23:in `<main>'

Errors

Class: User
Association type: has_many
Association options: {:through=>:inverse_friendships, :source=>:user, :extend=>[]}
uninitialized constant InverseFriendship
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:229:in `block in constantize'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:228:in `each'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:228:in `constantize'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/activesupport-3.2.1/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/lol_dba.rb:135:in `block (2 levels) in check_for_indexes'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/lol_dba.rb:104:in `each_pair'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/lol_dba.rb:104:in `block in check_for_indexes'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/lol_dba.rb:95:in `each'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/lol_dba.rb:95:in `check_for_indexes'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/lol_dba.rb:200:in `simple_migration'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/lol_dba-1.2.1/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/denis/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/denis/RubymineProjects/questick/vendor/bundle/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/denis/RubymineProjects/questick/vendor/bundle/bin/rake:19:in `load'
/Users/denis/RubymineProjects/questick/vendor/bundle/bin/rake:19:in `<main>'

Some indexes on column that doesn't exists

Hi, i found this gem and i tried it. but the output have one index on column that doesn't exists: the signed row >> have :serieopt_id that's wrong!
:vehicle_optionals table is a habtm table, so it have only two column: vehicle_id and optional_id, but :serieopt is a booleand field of vehicle table!
I hope this help

class AddMissingIndexes < ActiveRecord::Migration
  def change
    add_index :optional_packs, [:optional_b_id, :optional_a_id]
    add_index :estimates, :user_id
    add_index :estimates, :tabiva_id
    add_index :estimates, :model_id
    >>add_index :vehicle_optionals, [:serieopt_id, :optional_id]
    add_index :assembleds, :user_id
    add_index :assembleds, :bom_id
  end
end

Cannot define multiple 'included' blocks for a Concern

rake db:find_indexes
rake aborted!
ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/activesupport-4.1.4/lib/active_support/concern.rb:126:in `included'
/Users/ericbrooke/dev/mybesthelper/app/models/concerns/geocode.rb:4:in `<module:Geocode>'
/Users/ericbrooke/dev/mybesthelper/app/models/concerns/geocode.rb:1:in `<top (required)>'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/lol_dba-1.6.0/lib/lol_dba.rb:77:in `block in check_for_indexes'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/lol_dba-1.6.0/lib/lol_dba.rb:77:in `each'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/lol_dba-1.6.0/lib/lol_dba.rb:77:in `check_for_indexes'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/lol_dba-1.6.0/lib/lol_dba.rb:190:in `simple_migration'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/gems/lol_dba-1.6.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/bin/ruby_executable_hooks:15:in `eval'
/Users/ericbrooke/.rvm/gems/ruby-2.1.2@mbh/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:find_indexes
(See full trace by running task with --trace)

Polymorphic associations with explicit source trips lol_dba

Hi there, I'm a developer on Coursemology (repo: Coursemology/Coursemology2), and I'm setting up lol_dba. Running db:find_indexes fails:

Class: Course::Assessment::Submission
Association type: has_many
Association options: {:through=>:answers, :source=>:actable, :source_type=>"Course::Assessment::Answer::MultipleResponse"}
Exception: uninitialized constant Course::Assessment::Answer::Actable
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/inheritance.rb:158:in `compute_type'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/reflection.rb:271:in `compute_class'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/reflection.rb:267:in `klass'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:125:in `block (2 levels) in check_for_indexes'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:92:in `each_pair'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:86:in `each'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:86:in `check_for_indexes'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/lol_dba.rb:179:in `simple_migration'
D:/Development/Projects/Coursemology/vendor/bundle/ruby/2.2.0/gems/lol_dba-2.0.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'

Probably because we're using somewhat exotic options, in part due to the hzamani/activerecord-acts_as gem.

Not working with has_many + through

Class: TrackLink
Association type: has_many
Association options: {:through=>:track_visits, :extend=>[]}
Exception: undefined method `klass' for nil:NilClass
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:121:in `block (2 levels) in check_for_indexes'
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `each_pair'
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:92:in `block in check_for_indexes'
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `each'
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:88:in `check_for_indexes'
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/lol_dba.rb:190:in `simple_migration'
/var/lib/gems/1.9.1/gems/lol_dba-1.6.0/lib/tasks/lol_dba.rake:7:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/var/lib/gems/1.9.1/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19:in `<main>'

Undefined method constantize for Class

This gem seems to fail when an association class_name option is provided as a class rather than a string.

Exception: undefined methodconstantize' for #Class:0x000001100c2040`

Support of No-SQL dbs

Is there any future plan for supporting no-sql databases like mongodb (through Mongoid ORM) ?

error while trying to generate .sql files and the project have migratons created by rake my_engine_engine:install:migrations

db/migrate/20130123180738_add_avatar_to_user_preferences.harvey_engine.rb

# This migration comes from harvey_engine (originally 20120406191349)
class AddAvatarToUserPreferences < ActiveRecord::Migration
...

error:

wrong constant name AddAvatarToUserPreferences.harveyEngine
org/jruby/RubyModule.java:2575:in `const_defined?'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:230:in `constantize'
org/jruby/RubyArray.java:1613:in `each'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:229:in `constantize'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.11/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/migration.rb:23:in `migration_class'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/migration.rb:27:in `up'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/sql_generator.rb:55:in `up_and_down'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/sql_generator.rb:49:in `generate'
org/jruby/RubyArray.java:1613:in `each'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/sql_generator.rb:49:in `generate'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/sql_generator.rb:40:in `generate_instead_of_executing'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/lol_dba/sql_generator.rb:49:in `generate'
/var/lib/jenkins/.rvm/gems/jruby-1.7.2/gems/lol_dba-1.4.1/lib/tasks/lol_dba.rake:11:in `(root)'
org/jruby/RubyProc.java:249:in `call'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyKernel.java:1046:in `load'
org/jruby/RubyKernel.java:1066:in `eval'
/var/lib/jenkins/.rvm//gems/jruby-1.7.2/bin/ruby_noexec_wrapper:14:in `(root)'
Tasks: TOP => db:migrate_sql

Wrong index generation

I have this tables:

create_table :users do |t|
end

create_table:roles do |t|
end

create_table :roles_users, id: false do |t|
    t.references :role
    t.references :user
end

when i run the command rake db:find_indexes it says to add this index:

add_index :roles_users, :left_side_id

But, the table does not have this column.
Did not found anything in the documentation about this.

lol_dba tries to create indexes on columns that don't exist in the table

Here's the output of bundle exec rake db:find_indexes when run on my rails 3.2.12 app:

   class AddMissingIndexes < ActiveRecord::Migration
      def change
        add_index :keyword_visit_associations, :visit_id
        add_index :keyword_visit_associations, :keyword_id
        add_index :keyword_visit_associations, [:keyword_id, :visit_id]
        add_index :hiking_parties, :visit_id
        add_index :hiking_parties, :participant_id
        add_index :hiking_parties, [:participant_id, :visit_id]
        add_index :images, [:id, :type]
        add_index :images, :camera_id
        add_index :images, :lens_id
     ->add_index :locations, [:capture_id, :station_id]
        add_index :locations, :visit_id
     ->add_index :locations, [:location_image_id, :visit_id]
     ->add_index :locations, [:capture_id, :visit_id]
     ->add_index :visits, [:capture_id, :station_id]
     ->add_index :visits, [:location_image_id, :station_id]
        add_index :visits, :station_id
        add_index :survey_seasons, :survey_id
        add_index :captures, :camera_id
        add_index :captures, :lens_id
        add_index :comparison_indices, [:capture_id, :historic_capture_id]
        add_index :comparison_indices, :capture_id
        add_index :comparison_indices, :historic_capture_id
        add_index :photographers_visits, [:photographer_id, :participant_id]
        add_index :photographers_visits, [:visits_photographed_id, :visit_id]
        add_index :fn_authors_visits, [:fn_author_id, :participant_id]
        add_index :fn_authors_visits, [:visits_authored_id, :visit_id]
        add_index :historic_visits, :station_id
        add_index :surveys, :surveyor_id
        add_index :historic_captures, :camera_id
        add_index :historic_captures, :lens_id
        add_index :historic_captures, [:hcapture_owner_id, :hcapture_owner_type]
        add_index :metadata_files, [:metadata_owner_id, :metadata_owner_type]
      end
    end

And you can see my schema here: https://gist.github.com/cgat/5873205

I've put an arrow next to a few of the failing indexes (the table does not contain the column). It seems to be creating indices for has_many and has_many through relationships (that's my best guess).

Here are the relationships from my visit model:

  belongs_to :station, inverse_of: :visits
  has_and_belongs_to_many :photographers, join_table: :photographers_visits, class_name: 'Participant', order: :last_name
  has_and_belongs_to_many :fn_authors, join_table: :fn_authors_visits, class_name: 'Participant', order: :last_name
  has_many :locations, inverse_of: :visit, dependent: :destroy, order: :location_identity
  has_many :sorted_location_photos, through: :locations, source: :location_photos, order: :image
  has_many :located_captures, through: :locations, source: :captures
  has_many :keyword_visit_associations, dependent: :destroy
  has_many :keywords, through: :keyword_visit_associations, order: :keyword
  has_many :hiking_parties, dependent: :destroy
  has_many :hiking_party_participants, through: :hiking_parties, source: :participant, order: :last_name
  has_many :field_notes, inverse_of: :visit, dependent: :destroy, order: :field_note_file
  has_many :unsorted_captures, as: :capture_owner, class_name: "Capture", dependent: :destroy
  has_many :unsorted_location_photos, as: :image_owner, class_name: "LocationImage", dependent: :destroy, order: :image

Polymorphic association generates migration with syntax error.

Hey there.

Using v 2.0.1 out of master. I have an Attachment model that is polymorphic with the following definition in the model:

class Attachment < ActiveRecord::Base
  belongs_to :attachable,  polymorphic: true
end

Using rake db:find_indexes it generates the following migration suggestion:

class AddMissingIndexes < ActiveRecord::Migration
  def change
    add_index :attachments, [:["attachable_id", "attachable_type"]]
  end
end

And when running rake db:migrate I get:

syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
    add_index :attachments, [:["attachable_id", "attachable_type"]]

I can look into it if you want to point me in the right direction...

Thanks!

Weirdness with active_admin

db:find_indexes gives me this:

add_index :active_admin_comments, [:["resource_id", "resource_type"]]
add_index :active_admin_comments, [:["author_id", "author_type"]]

which is obviously not valid ruby.

I already have these indexes defined:

add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id"
add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id"

So I'm just going to remove those lines from the migration.

warning: previous definition

The warning looks like this:

app/models/activity.rb:18: warning: already initialized constant Activity::Kinds
app/models/activity.rb:18: warning: previous definition of Kinds was here

Note it's complaining about a constant being previously defined... on the same line.

Line 18 in activity.rb, and some following lines, looks like this:

Kinds = {
  foo: 0,
  bar: 1,
  [...]
  baz: 18
}

This broken warning only shows up when I include lol_dba in my Gemfile and run rake db:find_indexes; if I instead run bundle exec lol_dba find_indexes, I get no output at all, which also seems wrong...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.