lib/findex/tasks.rb in findex-0.2.0 vs lib/findex/tasks.rb in findex-0.2.1
- old
+ new
@@ -3,11 +3,11 @@
require 'rake/tasklib'
namespace :db do
desc 'Finds indexes your application probably needs'
task :indexes => [:environment, :prepare] do
- indices = @findex.get_indices(:geo, [:name, [:id, :type]], :primary, :reflection, [:type, [:boolean, :date, :datetime, :time]])
+ indices = @findex.get_indices(:geo, [:name, [:id, :type]], :reflection, [:type, [:boolean, :date, :datetime, :time]])
@findex.send_indices(indices)
end
task :prepare do
@findex = Findex.new
@@ -47,11 +47,11 @@
puts ''
puts " You can add migration=true to generate a migration file\n or perform=true to perform the indexing immediately:"
puts ' `rake db:indexes migration=true`'
puts ''
puts ' You can also target specific column types, like so:'
- [:boolean, :datetime, :geo, :primary, :relationships].each do |type|
+ [:boolean, :datetime, :geo, :relationships].each do |type|
puts " `rake db:indexes:#{type}`"
end
puts ''
puts ' You can also filter by column names and types, or by whole tables:'
puts ' `rake db:indexes:names names=type,state`'
@@ -62,11 +62,11 @@
desc 'Generates a migration file with the recommended indexes'
task :migration => :environment do
@findex.generate_migration = true
@findex.perform_index = false
- indices = @findex.get_indices(:geo, [:name, [:id, :type]], :primary, :reflection, [:type, [:boolean, :date, :datetime, :time]])
+ indices = @findex.get_indices(:geo, [:name, [:id, :type]], :reflection, [:type, [:boolean, :date, :datetime, :time]])
@findex.send_indices(indices)
end
desc 'Finds unindexed columns matching the names you supply'
task :names => [:environment, :prepare] do
@@ -83,20 +83,14 @@
desc 'Performs a migration with the recommended indexes'
task :perform => :environment do
@findex.generate_migration = false
@findex.perform_index = true
- indices = @findex.get_indices(:geo, [:name, [:id, :type]], :primary, :reflection, [:type, [:boolean, :date, :datetime, :time]])
+ indices = @findex.get_indices(:geo, [:name, [:id, :type]], :reflection, [:type, [:boolean, :date, :datetime, :time]])
@findex.send_indices(indices)
end
- desc 'Finds unindexed primary keys'
- task :primary => [:environment, :prepare] do
- @findex.migration_name = 'primary'
- @findex.send_indices(@findex.get_indices(:primary))
- end
-
desc 'Finds unindexed relationship foreign keys'
task :relationships => [:environment, :prepare] do
@findex.migration_name = 'relationship'
@findex.send_indices(@findex.get_indices(:reflection))
end
@@ -171,20 +165,10 @@
end
end
indices
end
- def get_model_primary_indices(model, indices, existing_indices)
- indices[model.table_name] ||= []
- parse_columns(model) do |column, column_name|
- if column.primary && check_index(column_name, indices[model.table_name], existing_indices)
- indices[model.table_name].push(column_name)
- end
- end
- indices
- end
-
def get_model_reflection_indices(model, indices, existing_indices)
indices[model.table_name] ||= []
model.reflections.each do |name, reflection|
case reflection.macro.to_sym
when :belongs_to
@@ -212,10 +196,10 @@
end
indices
end
def parse_columns(model)
- model.columns.each{|column| yield(column, column.name.to_sym)} if block_given?
+ model.columns.reject(&:primary).each{|column| yield(column, column.name.to_sym)} if block_given?
end
def send_indices(indices)
if @generate_migration
require 'rails_generator'
\ No newline at end of file