mschuerig-index_lifter 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/Rakefile +23 -23
- data/lib/index_lifter.rb +1 -1
- data/test/test_index_lifter.rb +102 -102
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= index_lifter
|
2
2
|
|
3
|
-
http://github.com/mschuerig/index_lifter
|
3
|
+
* http://github.com/mschuerig/index_lifter
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -47,7 +47,7 @@ ActiveRecord utility class that disables database indexes during a block.
|
|
47
47
|
|
48
48
|
== INSTALL:
|
49
49
|
|
50
|
-
* sudo gem install index_lifter
|
50
|
+
* sudo gem install mschuerig-index_lifter
|
51
51
|
|
52
52
|
== LICENSE:
|
53
53
|
|
data/Rakefile
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
-
require File.dirname(__FILE__) + '/lib/index_lifter'
|
3
|
-
|
4
|
-
# Generate all the Rake tasks
|
5
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
-
$hoe = Hoe.new('index_lifter', IndexLifter::VERSION) do |p|
|
7
|
-
p.developer('Michael Schuerig', 'michael@schuerig.de')
|
8
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
-
p.extra_deps = [
|
10
|
-
['activesupport','>= 2.0.2'],
|
11
|
-
]
|
12
|
-
p.extra_dev_deps = [
|
13
|
-
['newgem', ">= #{::Newgem::VERSION}"]
|
14
|
-
]
|
15
|
-
|
16
|
-
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
17
|
-
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
18
|
-
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
19
|
-
p.rsync_args = '-av --delete --ignore-errors'
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
23
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/index_lifter'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('index_lifter', IndexLifter::VERSION) do |p|
|
7
|
+
p.developer('Michael Schuerig', 'michael@schuerig.de')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.extra_deps = [
|
10
|
+
['activesupport','>= 2.0.2'],
|
11
|
+
]
|
12
|
+
p.extra_dev_deps = [
|
13
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
14
|
+
]
|
15
|
+
|
16
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
17
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
18
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
19
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
23
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
data/lib/index_lifter.rb
CHANGED
data/test/test_index_lifter.rb
CHANGED
@@ -1,102 +1,102 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
|
5
|
-
class TestIndexLifter < Test::Unit::TestCase
|
6
|
-
|
7
|
-
class TestConnection
|
8
|
-
#<struct ActiveRecord::ConnectionAdapters::IndexDefinition
|
9
|
-
# table="movies",
|
10
|
-
# name="index_movies_on_title",
|
11
|
-
# unique=false,
|
12
|
-
# columns=["title"]>
|
13
|
-
class IndexDefinition < Struct.new(:table, :name, :unique, :columns)
|
14
|
-
def to_hash
|
15
|
-
{ :table => table, :name => name, :unique => unique, :columns => columns }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(*defs)
|
20
|
-
@indexes = defs.inject({}) do |memo, idef|
|
21
|
-
memo[idef[:table].to_s] ||= []
|
22
|
-
memo[idef[:table].to_s] << IndexDefinition.new(
|
23
|
-
idef[:table].to_s,
|
24
|
-
idef[:name].to_s,
|
25
|
-
idef[:unique],
|
26
|
-
Array(idef[:columns]).map { |c| c.to_s }
|
27
|
-
)
|
28
|
-
memo
|
29
|
-
end
|
30
|
-
end
|
31
|
-
def tables
|
32
|
-
@indexes.keys.sort
|
33
|
-
end
|
34
|
-
def indexes(table)
|
35
|
-
@indexes[table.to_s]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def setup
|
40
|
-
@index_people_on_lastname_firstname_unique = {
|
41
|
-
:name => 'index_people_on_lastname_firstname',
|
42
|
-
:table => 'people', :columns => ['lastname', 'firstname'], :unique => true
|
43
|
-
}
|
44
|
-
@index_movies_on_title = {
|
45
|
-
:name => 'index_movies_on_title',
|
46
|
-
:table => 'movies', :columns => ['title'], :unique => false
|
47
|
-
}
|
48
|
-
@connection = TestConnection.new(
|
49
|
-
@index_movies_on_title,
|
50
|
-
@index_people_on_lastname_firstname_unique
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_find_indexes
|
55
|
-
lifter = IndexLifter.new(:connection => @connection)
|
56
|
-
assert_equal [@index_movies_on_title, @index_people_on_lastname_firstname_unique],
|
57
|
-
lifter.indexes.map(&:to_hash)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_exclude_unique_indexes
|
61
|
-
lifter = IndexLifter.new(:connection => @connection,
|
62
|
-
:except_unique => true)
|
63
|
-
assert_equal [@index_movies_on_title],
|
64
|
-
lifter.indexes.map(&:to_hash)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_exclude_index_by_name_as_string
|
68
|
-
lifter = IndexLifter.new(:connection => @connection,
|
69
|
-
:except => 'index_people_on_lastname_firstname')
|
70
|
-
assert_equal [@index_movies_on_title],
|
71
|
-
lifter.indexes.map(&:to_hash)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_exclude_index_by_hashed_name
|
75
|
-
lifter = IndexLifter.new(:connection => @connection,
|
76
|
-
:except => { :name => 'index_people_on_lastname_firstname' })
|
77
|
-
assert_equal [@index_movies_on_title],
|
78
|
-
lifter.indexes.map(&:to_hash)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_exclude_index_by_name_array
|
82
|
-
lifter = IndexLifter.new(:connection => @connection,
|
83
|
-
:except => ['index_people_on_lastname_firstname'])
|
84
|
-
assert_equal [@index_movies_on_title],
|
85
|
-
lifter.indexes.map(&:to_hash)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_exclude_index_by_table_and_column
|
89
|
-
lifter = IndexLifter.new(:connection => @connection,
|
90
|
-
:except => { :table => :movies, :column => :title})
|
91
|
-
assert_equal [@index_people_on_lastname_firstname_unique],
|
92
|
-
lifter.indexes.map(&:to_hash)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_exclude_index_by_table_and_columns
|
96
|
-
lifter = IndexLifter.new(:connection => @connection,
|
97
|
-
:except => { :table => :people, :columns => [:lastname, :firstname]})
|
98
|
-
assert_equal [@index_movies_on_title],
|
99
|
-
lifter.indexes.map(&:to_hash)
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
|
5
|
+
class TestIndexLifter < Test::Unit::TestCase
|
6
|
+
|
7
|
+
class TestConnection
|
8
|
+
#<struct ActiveRecord::ConnectionAdapters::IndexDefinition
|
9
|
+
# table="movies",
|
10
|
+
# name="index_movies_on_title",
|
11
|
+
# unique=false,
|
12
|
+
# columns=["title"]>
|
13
|
+
class IndexDefinition < Struct.new(:table, :name, :unique, :columns)
|
14
|
+
def to_hash
|
15
|
+
{ :table => table, :name => name, :unique => unique, :columns => columns }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(*defs)
|
20
|
+
@indexes = defs.inject({}) do |memo, idef|
|
21
|
+
memo[idef[:table].to_s] ||= []
|
22
|
+
memo[idef[:table].to_s] << IndexDefinition.new(
|
23
|
+
idef[:table].to_s,
|
24
|
+
idef[:name].to_s,
|
25
|
+
idef[:unique],
|
26
|
+
Array(idef[:columns]).map { |c| c.to_s }
|
27
|
+
)
|
28
|
+
memo
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def tables
|
32
|
+
@indexes.keys.sort
|
33
|
+
end
|
34
|
+
def indexes(table)
|
35
|
+
@indexes[table.to_s]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
@index_people_on_lastname_firstname_unique = {
|
41
|
+
:name => 'index_people_on_lastname_firstname',
|
42
|
+
:table => 'people', :columns => ['lastname', 'firstname'], :unique => true
|
43
|
+
}
|
44
|
+
@index_movies_on_title = {
|
45
|
+
:name => 'index_movies_on_title',
|
46
|
+
:table => 'movies', :columns => ['title'], :unique => false
|
47
|
+
}
|
48
|
+
@connection = TestConnection.new(
|
49
|
+
@index_movies_on_title,
|
50
|
+
@index_people_on_lastname_firstname_unique
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_find_indexes
|
55
|
+
lifter = IndexLifter.new(:connection => @connection)
|
56
|
+
assert_equal [@index_movies_on_title, @index_people_on_lastname_firstname_unique],
|
57
|
+
lifter.indexes.map(&:to_hash)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_exclude_unique_indexes
|
61
|
+
lifter = IndexLifter.new(:connection => @connection,
|
62
|
+
:except_unique => true)
|
63
|
+
assert_equal [@index_movies_on_title],
|
64
|
+
lifter.indexes.map(&:to_hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_exclude_index_by_name_as_string
|
68
|
+
lifter = IndexLifter.new(:connection => @connection,
|
69
|
+
:except => 'index_people_on_lastname_firstname')
|
70
|
+
assert_equal [@index_movies_on_title],
|
71
|
+
lifter.indexes.map(&:to_hash)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_exclude_index_by_hashed_name
|
75
|
+
lifter = IndexLifter.new(:connection => @connection,
|
76
|
+
:except => { :name => 'index_people_on_lastname_firstname' })
|
77
|
+
assert_equal [@index_movies_on_title],
|
78
|
+
lifter.indexes.map(&:to_hash)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_exclude_index_by_name_array
|
82
|
+
lifter = IndexLifter.new(:connection => @connection,
|
83
|
+
:except => ['index_people_on_lastname_firstname'])
|
84
|
+
assert_equal [@index_movies_on_title],
|
85
|
+
lifter.indexes.map(&:to_hash)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_exclude_index_by_table_and_column
|
89
|
+
lifter = IndexLifter.new(:connection => @connection,
|
90
|
+
:except => { :table => :movies, :column => :title})
|
91
|
+
assert_equal [@index_people_on_lastname_firstname_unique],
|
92
|
+
lifter.indexes.map(&:to_hash)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_exclude_index_by_table_and_columns
|
96
|
+
lifter = IndexLifter.new(:connection => @connection,
|
97
|
+
:except => { :table => :people, :columns => [:lastname, :firstname]})
|
98
|
+
assert_equal [@index_movies_on_title],
|
99
|
+
lifter.indexes.map(&:to_hash)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|