fast_change_table 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/fast_change_table/fast_change_table.rb +12 -8
- data/lib/fast_change_table/version.rb +1 -1
- data/spec/fast_change_table_spec.rb +5 -2
- metadata +3 -3
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ uses ordinary change_table syntax but adds two options
|
|
14
14
|
* "replace\_keys" to remove all indexes; new indexes will be specified
|
15
15
|
- "disable\_keys" to remove indexes and apply them after data load; this is a tremendous performance enhancement for a dbms with fast index creation; it is active by default. set it to false to prevent its usage
|
16
16
|
|
17
|
-
the bulk option is set by default set it to false to prevent its usage.
|
17
|
+
the bulk option is set by default; set it to false to prevent its usage.
|
18
18
|
|
19
19
|
__Example:__
|
20
20
|
|
@@ -31,13 +31,13 @@ create\_table\_like(orignal\_table, table\_to\_copy\_to)
|
|
31
31
|
creates a table with the same structure
|
32
32
|
|
33
33
|
disable\_indexes(table)
|
34
|
-
removes all indexes from a table, returns a list of index objects removed
|
34
|
+
removes all indexes from a table, returns a list of index objects removed. uses bulk alter when possible
|
35
35
|
|
36
36
|
enable\_indexes(table, list\_of\_indexes)
|
37
|
-
restores a list of indexes to a table
|
37
|
+
restores a list of indexes to a table. uses bulk alter when possible
|
38
38
|
|
39
39
|
fast\_add\_indexes(table, &block)
|
40
|
-
allows you to pass a block to add indexes.
|
40
|
+
allows you to pass a block to add indexes. uses bulk alter when possible
|
41
41
|
|
42
42
|
__Example:__
|
43
43
|
|
@@ -85,20 +85,24 @@ module FastChangeTable
|
|
85
85
|
#removes all the indexes
|
86
86
|
def disable_indexes(table)
|
87
87
|
list = indexes(table)
|
88
|
-
|
89
|
-
|
88
|
+
change_table_with_remaps table do |t|
|
89
|
+
list.each do |i|
|
90
|
+
t.remove_index :name => i.name
|
91
|
+
end
|
90
92
|
end
|
91
93
|
list
|
92
94
|
end
|
93
95
|
|
94
96
|
#
|
95
97
|
def enable_indexes(table, list)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
change_table_with_remaps table do |t|
|
99
|
+
list.each do |i|
|
100
|
+
options = {}
|
101
|
+
options[:name] = i.name if i.name
|
102
|
+
options[:length] = i.lengths if i.lengths
|
103
|
+
options[:unique] = i.unique if i.unique
|
104
|
+
t.index i.columns, options
|
105
|
+
end
|
102
106
|
end
|
103
107
|
true
|
104
108
|
end
|
@@ -6,6 +6,7 @@ describe ActiveRecord::Migration do
|
|
6
6
|
t.integer :an_integer
|
7
7
|
t.string :a_string
|
8
8
|
t.string :a_name
|
9
|
+
t.string :old_name
|
9
10
|
end
|
10
11
|
@connection = ActiveRecord::Migration.connection
|
11
12
|
end
|
@@ -17,7 +18,7 @@ describe ActiveRecord::Migration do
|
|
17
18
|
describe "initialize table" do
|
18
19
|
it "should have expected starting table" do
|
19
20
|
@connection.columns("my_table").all? do |c|
|
20
|
-
["id", "an_integer", "a_string", "a_name"].include?(c.name)
|
21
|
+
["id", "an_integer", "a_string", "a_name", "old_name"].include?(c.name)
|
21
22
|
end.should eq(true)
|
22
23
|
end
|
23
24
|
end
|
@@ -27,7 +28,7 @@ describe ActiveRecord::Migration do
|
|
27
28
|
ActiveRecord::Migration.create_table_like(:my_table, :my_copied_table)
|
28
29
|
|
29
30
|
@connection.columns("my_copied_table").all? do |c|
|
30
|
-
["id", "an_integer", "a_string", "a_name"].include?(c.name.to_s)
|
31
|
+
["id", "an_integer", "a_string", "a_name","old_name"].include?(c.name.to_s)
|
31
32
|
end.should eq(true)
|
32
33
|
end
|
33
34
|
end
|
@@ -69,6 +70,7 @@ describe ActiveRecord::Migration do
|
|
69
70
|
t.change :an_integer, :integer
|
70
71
|
t.change :a_string, :string
|
71
72
|
t.change :a_name, :string
|
73
|
+
t.rename :old_name, :new_name
|
72
74
|
t.string :new_column
|
73
75
|
end
|
74
76
|
record = @connection.select_all("select * from my_table").first
|
@@ -76,6 +78,7 @@ describe ActiveRecord::Migration do
|
|
76
78
|
record['a_string'].should eq('String')
|
77
79
|
record['a_name'].should eq('Name')
|
78
80
|
record['new_column'].should eq(nil)
|
81
|
+
record['new_name'].should eq(nil)
|
79
82
|
@connection.indexes("my_table").empty?.should eq(true)
|
80
83
|
end
|
81
84
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_change_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Grady Griffin
|