Giter Site home page Giter Site logo

eladmeidar / rails_indexes Goto Github PK

View Code? Open in Web Editor NEW
492.0 492.0 35.0 191 KB

A rake task to track down missing database indexes. does not assume that all foreign keys end with the convention of _id.

Home Page: http://blog.eizesus.com/2009/9/find-where-to-index-your-tables-on-a-rails-app/

License: MIT License

Ruby 100.00%

rails_indexes's Introduction

DEPRECATED

This gem doesn’t really work on Rails 4 – no plans on upgrading it anyway. you probably should take a look at lol_dba

Rails Indexes

Rails indexes is a small package of 2 rake tasks that scan your application models and displays a list of columns that probably should be indexed.

Note: there may be more fields depending on your application design and custom queries.

Rails 3.x and 4.x

If you’re using Rails 3.x or 4.x, you probably should take a look at lol_dba

Installation

as a rails plugin:

script/plugin install git://github.com/eladmeidar/rails_indexes.git

Usage

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

rake db:index_migration

Display a migration for adding/removing all necessary indexes based on AR::Base#find calls (including: find, find_by, find_all_by, find_by_x_and_y, find_all_by_x_and_y):

rake db:find_query_indexes

Note that it would probably make more sense running those tasks on production, where you actually need those indexes to be added.

Tests

Requires SQLite3 installed, then just:

rake

to run the tests

Author:

Elad Meidar – http://blog.eizesus.com

Thanks:
Eric Davis – http://littlestreamsoftware.com

Released under the same license as Ruby. No Support. No Warranty, no Pain.

rails_indexes's People

Contributors

andrew avatar edavis10 avatar ianheggie avatar kdonovan 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

rails_indexes's Issues

Error when running with rvm and ruby 1.9.2-p136

I get the following error when I try to run metrical with rails 3.

/home/user/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/racc/parser.rb:349:in `on_error':  (Racc::ParseError)
parse error on value "." (tDOT)

from /home/user/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/racc/parser.rb:99:in `_racc_do_parse_c'
from /home/user/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/racc/parser.rb:99:in `do_parse'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/ruby_parser-2.0.5/lib/ruby_parser_extras.rb:749:in `process'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/flog-2.5.0/lib/flog.rb:241:in `block in flog'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/flog-2.5.0/lib/flog.rb:235:in `each'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/flog-2.5.0/lib/flog.rb:235:in `flog'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metric_fu-2.0.1/lib/generators/flog.rb:20:in `emit'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metric_fu-2.0.1/lib/base/generator.rb:126:in `block in generate_report'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metric_fu-2.0.1/lib/base/generator.rb:124:in `each'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metric_fu-2.0.1/lib/base/generator.rb:124:in `generate_report'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metric_fu-2.0.1/lib/base/generator.rb:52:in `generate_report'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metric_fu-2.0.1/lib/base/report.rb:54:in `add'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metrical-0.0.4/bin/metrical:34:in `block in <top (required)>'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metrical-0.0.4/bin/metrical:34:in `each'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/gems/metrical-0.0.4/bin/metrical:34:in `<top (required)>'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/bin/metrical:19:in `load'
from /home/user/.rvm/gems/ruby-1.9.2-p136@global/bin/metrical:19:in `<main>'

can't exclude tables

I am using the ActiveSalesforce gem to connect one of my models to Salesforce and I'd love to be able to exclude that model from the search. It'd be great to be able to say something like either of the following

rake db:show_me_ar_find_indexes exclude="model1,model2"
rake db:show_me_ar_find_indexes only="model1,model2"

What I'm getting now is an exception. A "Mysql::Error: Table 'name' doesn't exist" error to be precise

Rails 3.1.1 Indexer problem?

Wanted to give this gem a try to tune up my queries, but I get the following error:

White-Dome:server kevin$ rake db:index_migration
/Users/kevin/.rvm/gems/ruby-1.9.2-p136/gems/rails-indexes-0.0.1/lib/rails-indexes/indexer.rb:332: warning: else without rescue is useless
rake aborted!
Don't know how to build task 'db:index_migration'

(See full trace by running task with --trace)
White-Dome:server kevin$ bundle exec rake -T db
/Users/kevin/.rvm/gems/ruby-1.9.2-p136/gems/rails-indexes-0.0.1/lib/rails-indexes/indexer.rb:332: warning: else without rescue is useless
rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load # Load fixtures into the current environment's database.
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump # Dump the database structure to an SQL file
rake db:version # Retrieves the current schema version number

Should not expect non-AR::Base classes to have a table

Should skip classes which don't inherit from AR::Base.
eg:

# app/models/stock_transfer_batches.rb
# Virtual AR class for creating stock_transfers
class StockTransferBatch < ActiveRecord::BaseWithoutTable
  ...
end

~/g2(master) > rake db:index_migration -t
(in /Users/zubin/ww/g2)
** Invoke db:index_migration (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:index_migration
rake aborted!
Mysql::Error: Table 'g2_development.stock_transfer_batches' doesn't exist: SHOW KEYS FROM `stock_transfer_batches`
/Users/zubin/ww/g2/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log'
/Users/zubin/ww/g2/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:323:in `execute'
/Users/zubin/ww/g2/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:452:in `indexes'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:85:in `check_for_indexes'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:82:in `each'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:82:in `check_for_indexes'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:222:in `simple_migration'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/indexer.rake:10
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/local/bin/rake:19:in `load'
/opt/local/bin/rake:19

Should also skip AR::Base models where columns class method is overriden (ie no table)
eg:

def self.columns
  @columns ||= []
end

def self.column(name, sql_type = nil, default = nil, null = true)
  columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end

column :text_input, :string

ruby 1.9 invalid next

ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
rake test gives errors:
rails_indexes/lib/indexer.rb: /home/jastix/projects/refinerycms/vendor/plugins/rails_indexes/lib/indexer.rb:158: Invalid next (SyntaxError)
rails_indexes/lib/indexer.rb:162: Invalid next

undefined method `index_list`

When I try to run the "db:show_me_some_indexes" task I get the following error:
rake aborted!
undefined method `index_list' for Indexer:Module

I'm using rails 2.3.4

Rake trace:

Invoke db:show_me_some_indexes (first_time)
Invoke environment (first_time) 
Execute environment
** Invoke db:show_me_some_indexes (first_time)
** Invoke environment (first_time)
** Execute environment
Loading haml-edge gem.
** Execute db:show_me_some_indexes
rake aborted!
undefined method `index_list' for Indexer:Module
/Users/paul/Documents/Projects/msvngit/rails/vendor/plugins/rails_indexes/tasks/indexer.rake:11
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/local/bin/rake:19:in `load'
/opt/local/bin/rake:19

Does not play with javan-whenever-0.3.6

rake db:show_me_a_migration

Expected /opt/local/lib/ruby/gems/1.8/gems/javan-whenever-0.3.6/lib/base.rb to define Base
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:426:in `load_missing_constant'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `const_get'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `check_for_indexes'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:380:in `inject'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `each'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `inject'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `check_for_indexes'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:16:in `each'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:16:in `check_for_indexes'
{RAILS_ROOT}/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:196:in `simple_migration'

Controller in modules doesn't work

It doesn't seem to work with a controller Forum::TopicsController, that comes with altered beast.
uninitialized constant TopicsController

Doesn't handle model class named APIError well

I've got a model class called "APIError", defined in the file api_error.rb. When I run the rake tasks, I see:

Expected /Users/chris/Code/myapp/app/models/api_error.rb to define ApiError

Composite indexes "both ways"

As I understand it composite indexes can only be read "from the front". Not sure about other databases, but I'm pretty sure this is the case with MySQL. So given this:

@posts = Post.find_by_title_and_published('test', true)
@posts = Post.find_by_published_and_title(true, 'test')

Shouldn't we get both:

add_index :posts, [:title, :published]

and:

add_index :posts, [:published, :title]

RailsIndexes only suggests the last one. More on how MySQL uses indexes here.

can create index for specific tables?

Hi,

This gem will create index for all the model(tables) columns which are ending with '_id' column. Can I know is there any way that I can create indexes for specific tables/models. Because creating index for unread tables may cause slow down while creating and updating. so i would like to create index for only specific tables in the application on fly. Can this possible with the present gem?

Thank You,
Uma Mahesh.

undefined method `table_name' for FooController:Class

I'm getting the following error:

~/code/knotebooks-rewrite
master $ rake db:find_query_indexes --trace
(in /Users/tom/code/knotebooks-rewrite)
** Invoke db:find_query_indexes (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:find_query_indexes
rake aborted!
undefined method `table_name' for CommentsController:Class
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:180:in `check_line_for_find_indexes'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:134:in `scan_finds'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:112:in `each'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:112:in `scan_finds'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:108:in `each'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:108:in `scan_finds'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:279:in `ar_find_indexes'
/Users/tom/code/knotebooks-rewrite/vendor/plugins/rails_indexes/tasks/indexer.rake:6
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/local/bin/rake:19:in `load'
/opt/local/bin/rake:19

I get this error on all my controllers.

class CommentsController < ApplicationController
  def create
    @commentable = find_commentable
    @comment = @commentable.comments.build(params[:comment])
    @comment.user = current_user

    respond_to do |format|
      if @comment.save
        flash[:notice] = "Comment Posted!"
        format.html { redirect_to @commentable }
      else
        flash[:error] = "Error posting comment"
        format.html { redirect_to @commentable }
      end
    end
  end

  def destroy
    @comment = Comment.find(params[:id])
    @comment.destroy if @comment.author == current_user

    respond_to do |format|
      flash[:notice] = 'Comment was successfully deleted'
      format.html { redirect_to @comment.commentable }
      # format.xml  { head :ok }
    end
  end

  private

  def find_commentable
    params.each do |name, value|
      if name =~ /(.+)_id$/
        return $1.classify.constantize.find(value)
      end
    end
  end
end

task db:find_query_indexes fails when a controller has a method "find_***"

One of controllers in my projeect had private a method named "find_attr_by_name". I runned the db:db:find_query_indexes query, it looks like it searchs for "find_xxxx" in all classes and when it found a class with this method it calls the "table_name" attribute from the class. Most of the cases it will be in a model class, but in this case it is a controller class, so the task fails.

Here is the backtrace:


undefined method table_name' for ExportacoesPdvController:Class /Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:180:incheck_line_for_find_indexes'
/Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:134:in scan_finds' /Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:112:ineach'
/Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:112:in scan_finds' /Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:108:ineach'
/Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:108:in scan_finds' /Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:279:inar_find_indexes'
/Users/razenha/Projects/Pro/portaltrademarketingpoptrade/vendor/plugins/rails_indexes/tasks/indexer.rake:6
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:636:in call' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:636:inexecute'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:631:in each' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:631:inexecute'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:597:in invoke_with_call_chain' /Users/razenha/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/1.8/monitor.rb:242:insynchronize'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:583:ininvoke'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2029:intop_level'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2029:in each' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2029:intop_level'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2023:intop_level'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2001:in run' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/lib/rake.rb:1998:in run' /Users/razenha/.rvm/gems/ruby-1.8.7-p299/gems/rake-0.8.7/bin/rake:31 /Users/razenha/.rvm/gems/ruby-1.8.7-p299/bin/rake:19:inload'

/Users/razenha/.rvm/gems/ruby-1.8.7-p299/bin/rake:19

undefined method `to_a' for "company_id":String (Rails 3 app)

wgd1 $ rake db:index_migration --trace

DEPRECATION WARNING: Having rake tasks in PLUGIN_PATH/tasks or PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead. (called from load_tasks at /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/plugin.rb:31)
DEPRECATION WARNING: Having rake tasks in PLUGIN_PATH/tasks or PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead. (called from load_tasks at /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/lib/rails/plugin.rb:31)

** Invoke db:index_migration (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:index_migration
rake aborted!
undefined method to_a' for "company_id":String /Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:216:inkey_exists?'
/Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:229:in block (2 levels) in simple_migration' /Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:228:ineach'
/Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:228:in block in simple_migration' /Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:227:ineach'
/Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:227:in simple_migration' /Users/billlazar/Sites/wested/wgg/wgd1/vendor/plugins/rails_indexes/tasks/indexer.rake:10:inblock (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in call' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:inblock in execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in each' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:inexecute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in block in invoke_with_call_chain' /usr/local/lib/ruby/1.9.1/monitor.rb:190:inmon_synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in invoke_with_call_chain' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:ininvoke'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in invoke_task' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:inblock (2 levels) in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in each' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:inblock in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:intop_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in block in run' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in run' /usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in<top (required)>'
/usr/local/bin/rake:19:in load' /usr/local/bin/rake:19:in

'

does not work with tableless models

rails_indexes breaks on tableless models with the following error:

(in /home/kakra/git/netactive/abfuhr)
rake aborted!
Mysql::Error: Table 'kakra_abfuhrkalender.tablelesses' doesn't exist: SHOW KEYS FROM `tablelesses`
(See full trace by running task with --trace)

This happens when using a model like this:

class AnonymousSession < Tableless
...
end

class Tableless < ActiveRecord::Base
  def self.columns
    @columns ||= [];
  end
  def self.column(name, sql_type = nil, default = nil, null = true)
    columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
  end
  # Override the save method to prevent exceptions.
  def save(validate = true)
    validate ? valid? : true
  end
end

See http://stackoverflow.com/questions/315850/rails-model-without-database/318919#318919 why such models may be useful. rails_indexes should be able to just ignore these.

Doesn't play well with sweepers

As the title says :-) Won't run the git tasks with them there.

Thomass-MacBook:thomas (master)$ rake db:show_me_ar_find_indexes --trace
(in /Users/thomas/rails_app/thiswayin)
** Invoke db:show_me_ar_find_indexes (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:show_me_ar_find_indexes
rake aborted!
Expected /Users/thomas/rails_app/thiswayin/app/sweepers/user_status_sweeper.rb to define UserStatusSweeper
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:426:in load_missing_constant' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:inconst_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:92:in const_missing' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/inflector.rb:361:inconstantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/inflector.rb:360:in each' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/inflector.rb:360:inconstantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/string/inflections.rb:162:in constantize' /Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:102:inscan_finds'
/Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:96:in each' /Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:96:inscan_finds'
/Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:93:in each' /Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:93:inscan_finds'
/Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:232:in ar_find_indexes' /Users/thomas/rails_app/thiswayin/vendor/plugins/rails_indexes/tasks/indexer.rake:6 /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

uninitialized constant <MODEL>

If there's a plugin with an unused model in the app, like Account that comes with Authlogic, the tool finds it through file scan, but Rails doesn't know it as it never loaded into memory. An attempt to constantize in indexer.rb:122 (table_name = model_name.constantize.table_name) fails with an exception.

Hope it helps.

Tables as views / Legacy

Hi,

First off, great plugin.

The project I've come in on uses quite a few interesting setups. The main one is views from a legacy database and models based off them.

I've added the following at various point to catch the SQL errors from executing 'abc' on the view tables.

See Gist: http://gist.github.com/232889

Just a thought for older rails apps which might have a lot of sick code or legacy connections ;)

Should be less strict with class names

eg when using aasm gem:

# vendor/gems/aasm-2.1.5/lib/aasm.rb
module AASM
end

~/g2(master) > rake db:index_migration -t
(in /Users/zubin/ww/g2)
** Invoke db:index_migration (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:index_migration
rake aborted!
Expected /Users/zubin/ww/g2/vendor/gems/aasm-2.1.5/lib/aasm.rb to define Aasm

Also happens with AR models, eg:

# app/models/mad_mimi_api.rb
class MadMimiAPI
  ...
end

~/g2(master) > rake db:index_migration -t
(in /Users/zubin/ww/g2)
** Invoke db:index_migration (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:index_migration
rake aborted!
Expected /Users/zubin/ww/g2/app/models/mad_mimi_api.rb to define MadMimiApi
/Users/zubin/ww/g2/vendor/rails/activesupport/lib/active_support/dependencies.rb:426:in `load_missing_constant'
/Users/zubin/ww/g2/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/zubin/ww/g2/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in `const_missing'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `const_get'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `check_for_indexes'
/Users/zubin/ww/g2/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in `inject'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `each'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `inject'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:19:in `check_for_indexes'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:16:in `each'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:16:in `check_for_indexes'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/../lib/indexer.rb:222:in `simple_migration'
/Users/zubin/ww/g2/vendor/plugins/rails_indexes/tasks/indexer.rake:10
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/opt/local/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/opt/local/bin/rake:19:in `load'
/opt/local/bin/rake:19

rake db:find_query_indexes fails for Rails 2.2.2

Hi, when I run "rake db:find_query_indexes" it get the following error:

Expected //app/controllers/application.rb to define Application
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:428:in `load_missing_constant'

Rails 2.2.2, ruby 1.8.7 (2009-06-12 patchlevel 174)

["rake db:index_migration" works fine on Rails 2.2.2]

For Rails 2.2.2, application.rb defines ApplicationController.
For Rails 2.3.x, application.rb was renamed to application_controller.rb (to be consistent with other controller naming)

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.