findex 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.markdown +9 -7
- data/VERSION +1 -1
- data/lib/findex/tasks.rb +18 -6
- metadata +3 -2
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/README.markdown
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
# Findex #
|
2
2
|
|
3
|
-
Findex is a simple collection of Rake tasks that will help you locate missing database indexes in your Rails app.
|
3
|
+
Findex is a simple collection of Rake tasks that will help you locate missing database indexes in your Rails app.
|
4
|
+
It can also generate migrations and run them, as well as filter by specific column types, names, and tables.
|
4
5
|
|
5
|
-
**Please note** that Findex designed to find any potentially overlooked indexes. It is not a good practice to index every matching column
|
6
|
+
**Please note** that Findex designed to find any potentially overlooked indexes. It is not a good practice to index every matching column Findex returns -
|
7
|
+
that's often overkill.
|
6
8
|
|
7
9
|
## Installation ##
|
8
10
|
|
9
11
|
Install Findex as a gem:
|
10
12
|
|
11
|
-
$ gem install findex
|
13
|
+
$ gem install findex
|
12
14
|
|
13
15
|
You may want to configure it as a gem in environment.rb instead, since you're going to need it in your Rakefile:
|
14
16
|
|
15
|
-
config.gem 'findex'
|
17
|
+
config.gem 'findex'
|
16
18
|
|
17
19
|
... then run:
|
18
20
|
|
19
|
-
rake gems:install
|
21
|
+
$ rake gems:install
|
20
22
|
|
21
23
|
Now add it to your projects' Rakefile:
|
22
24
|
|
@@ -25,9 +27,9 @@ Now add it to your projects' Rakefile:
|
|
25
27
|
rescue MissingSourceFile
|
26
28
|
end
|
27
29
|
|
28
|
-
##
|
30
|
+
## Usage ##
|
29
31
|
|
30
|
-
|
32
|
+
Findex is pretty simple to use. To get instructions, try running the Rake task below:
|
31
33
|
|
32
34
|
$ rake db:indexes:help
|
33
35
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/findex/tasks.rb
CHANGED
@@ -61,7 +61,7 @@ namespace :db do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
desc 'Generates a migration file with the recommended indexes'
|
64
|
-
task :migration => :environment do
|
64
|
+
task :migration => [:environment, :prepare] do
|
65
65
|
@findex.generate_migration = true
|
66
66
|
@findex.perform_index = false
|
67
67
|
indices = @findex.get_indices(:geo, [:name, [:id, :type]], :reflection, [:type, [:boolean, :date, :datetime, :time]])
|
@@ -82,7 +82,7 @@ namespace :db do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
desc 'Performs a migration with the recommended indexes'
|
85
|
-
task :perform => :environment do
|
85
|
+
task :perform => [:environment, :prepare] do
|
86
86
|
@findex.generate_migration = false
|
87
87
|
@findex.perform_index = true
|
88
88
|
indices = @findex.get_indices(:geo, [:name, [:id, :type]], :reflection, [:type, [:boolean, :date, :datetime, :time]])
|
@@ -138,9 +138,15 @@ class Findex
|
|
138
138
|
ObjectSpace.each_object(Class) do |model|
|
139
139
|
next unless model.ancestors.include?(ActiveRecord::Base) && model != ActiveRecord::Base && model.table_exists?
|
140
140
|
next if @tables && !@tables.include?(model.table_name.to_s)
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
begin
|
142
|
+
# Check for views... expected to fail.
|
143
|
+
Applicant.connection.execute("SHOW CREATE VIEW #{model.table_name}")
|
144
|
+
rescue ActiveRecord::StatementInvalid
|
145
|
+
existing_indices = connection.indexes(model.table_name).map{|index| index.columns.length == 1 ? index.columns.first.to_sym : index.columns.map(&:to_sym) }
|
146
|
+
args.each do |method, options|
|
147
|
+
indices = send("get_model_#{method}_indices", *[model, options, indices, existing_indices].compact)
|
148
|
+
end
|
149
|
+
|
144
150
|
end
|
145
151
|
end
|
146
152
|
collect_indices(indices)
|
@@ -224,7 +230,13 @@ class Findex
|
|
224
230
|
index_up.push("\s\s\s\s# Indices for `#{table}`")
|
225
231
|
index_down.push("\s\s\s\s# Remove indices for `#{table}`")
|
226
232
|
columns.each do |column|
|
227
|
-
|
233
|
+
if column.is_a?(Array)
|
234
|
+
index_up.push("\s\s\s\sadd_index :#{table}, #{column.inspect}, :name => :#{table}_#{column.join('_')}")
|
235
|
+
elsif "index_#{table}_on_#{column}".length > 64
|
236
|
+
index_up.push("\s\s\s\sadd_index :#{table}, #{column.inspect}, :name => :#{"#{table.to_s.singularize}_#{column.to_s.singularize}"[0, 64]}")
|
237
|
+
else
|
238
|
+
index_up.push("\s\s\s\sadd_index :#{table}, #{column.inspect}")
|
239
|
+
end
|
228
240
|
index_down.push("\s\s\s\sremove_index :#{table}, #{column.inspect}")
|
229
241
|
end
|
230
242
|
migration_up.push(index_up.join("\n"))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: findex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flip Sasser
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-10 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,6 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README.markdown
|
24
24
|
files:
|
25
|
+
- .gitignore
|
25
26
|
- MIT-LICENSE
|
26
27
|
- README.markdown
|
27
28
|
- Rakefile
|