fast_change_table 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +4 -2
- data/README.md +3 -3
- data/db/test.db +0 -0
- data/fast_change_table.gemspec +3 -1
- data/lib/fast_change_table/fast_change_table.rb +3 -3
- data/lib/fast_change_table/version.rb +2 -2
- data/spec/fast_change_table_spec.rb +9 -4
- data/spec/spec_helper.rb +7 -2
- metadata +87 -44
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fast_change_table (1.5.
|
4
|
+
fast_change_table (1.5.2)
|
5
5
|
activerecord (>= 2.3)
|
6
6
|
|
7
7
|
GEM
|
@@ -32,7 +32,8 @@ GEM
|
|
32
32
|
rspec-expectations (2.8.0)
|
33
33
|
diff-lcs (~> 1.1.2)
|
34
34
|
rspec-mocks (2.8.0)
|
35
|
-
|
35
|
+
sqlite3 (1.3.5)
|
36
|
+
tzinfo (0.3.32)
|
36
37
|
|
37
38
|
PLATFORMS
|
38
39
|
ruby
|
@@ -41,3 +42,4 @@ DEPENDENCIES
|
|
41
42
|
fast_change_table!
|
42
43
|
mysql2
|
43
44
|
rspec
|
45
|
+
sqlite3
|
data/README.md
CHANGED
@@ -58,7 +58,7 @@ __Example:__
|
|
58
58
|
t.index [:some_other_column, :column_three], :name => "a_multicolumn_index"
|
59
59
|
end
|
60
60
|
|
61
|
-
copy\_table(from\_table, to\_table, remaps = [])
|
61
|
+
copy\_table\_data(from\_table, to\_table, remaps = [])
|
62
62
|
|
63
63
|
* copies rows from one table into another.
|
64
64
|
by default copies data from column of from_table to to_table of same name.
|
@@ -69,6 +69,6 @@ copy\_table(from\_table, to\_table, remaps = [])
|
|
69
69
|
__Examples:__
|
70
70
|
|
71
71
|
|
72
|
-
|
72
|
+
copy_table_data(old_users_without_email_hash, new_table, ['MD5(email)', 'email_hash'])
|
73
73
|
|
74
|
-
|
74
|
+
copy_table_data(old_users_without_total, new_table, [['sum(payments)', 'total_payments'], ['avg(payments)', 'average_payments']])
|
data/db/test.db
ADDED
Binary file
|
data/fast_change_table.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "fast_change_table"
|
7
7
|
s.version = FastChangeTable::VERSION::STRING
|
8
8
|
s.authors = ["Grady Griffin"]
|
9
|
-
s.email = ["
|
9
|
+
s.email = ["gradygriffin@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/thegboat/fast_change_table"
|
11
11
|
s.summary = %q{Faster table changes}
|
12
12
|
s.description = %q{Uses table duplication to speed up migrations on large tables}
|
@@ -23,9 +23,11 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency('activerecord', '>= 2.3')
|
24
24
|
s.add_development_dependency("rspec")
|
25
25
|
s.add_development_dependency("mysql2")
|
26
|
+
s.add_development_dependency("sqlite3")
|
26
27
|
else
|
27
28
|
s.add_dependency('activerecord', '>= 2.3')
|
28
29
|
s.add_development_dependency("rspec")
|
29
30
|
s.add_development_dependency("mysql2")
|
31
|
+
s.add_development_dependency("sqlite3")
|
30
32
|
end
|
31
33
|
end
|
@@ -10,7 +10,7 @@ module FastChangeTable
|
|
10
10
|
renamed_columns = change_table_with_remaps(table_name, options, &block)
|
11
11
|
index_list = options[:disable_keys] == false ? [] : disable_indexes(table_name)
|
12
12
|
#prepare the columns names for the insert statements
|
13
|
-
|
13
|
+
copy_table_data(old_table_name, table_name, renamed_columns)
|
14
14
|
enable_indexes(table_name, index_list) unless options[:disable_keys] == false
|
15
15
|
drop_table(old_table_name)
|
16
16
|
rescue Exception => e
|
@@ -56,8 +56,8 @@ module FastChangeTable
|
|
56
56
|
true
|
57
57
|
end
|
58
58
|
|
59
|
-
#
|
60
|
-
def
|
59
|
+
#copy_table_data( :sometable, :newtable, [[:old_column, :new_column]])
|
60
|
+
def copy_table_data(from, to, remaps = [])
|
61
61
|
old = columns(from).collect(&:name)
|
62
62
|
current = columns(to).collect(&:name)
|
63
63
|
remapped_columns = remaps.collect {|c| c.first.to_s}.compact
|
@@ -8,6 +8,11 @@ describe ActiveRecord::Migration do
|
|
8
8
|
t.string :a_name
|
9
9
|
t.string :old_name
|
10
10
|
end
|
11
|
+
unless defined?(TestClass)
|
12
|
+
klass = Class.new(ActiveRecord::Base)
|
13
|
+
klass.table_name = "my_table"
|
14
|
+
Kernel.const_set("TestClass", klass)
|
15
|
+
end
|
11
16
|
@connection = ActiveRecord::Migration.connection
|
12
17
|
end
|
13
18
|
|
@@ -61,12 +66,12 @@ describe ActiveRecord::Migration do
|
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
|
-
describe "#
|
69
|
+
describe "#copy_table_data" do
|
65
70
|
it "should copy the records from one table to another" do
|
66
|
-
|
71
|
+
TestClass.create(:an_integer => 1, :a_string => 'String', :a_name => 'Name')
|
67
72
|
ActiveRecord::Migration.create_table_like(:my_table, :my_copied_table)
|
68
73
|
ActiveRecord::Migration.add_column(:my_copied_table, :new_column, :string)
|
69
|
-
ActiveRecord::Migration.
|
74
|
+
ActiveRecord::Migration.copy_table_data(:my_table, :my_copied_table, [["'Nothing'", "new_column"]])
|
70
75
|
record = @connection.select_all("select * from my_copied_table").first
|
71
76
|
record['an_integer'].should eq(1)
|
72
77
|
record['a_string'].should eq('String')
|
@@ -77,7 +82,7 @@ describe ActiveRecord::Migration do
|
|
77
82
|
|
78
83
|
describe "#fast_change_table" do
|
79
84
|
it "should bring it all together" do
|
80
|
-
|
85
|
+
TestClass.create(:an_integer => 1, :a_string => 'String', :a_name => 'Name')
|
81
86
|
ActiveRecord::Migration.add_index :my_table, :an_integer, :name => "an_index"
|
82
87
|
ActiveRecord::Migration.fast_change_table :my_table, :remove_keys => true do |t|
|
83
88
|
t.change :an_integer, :integer
|
data/spec/spec_helper.rb
CHANGED
@@ -7,9 +7,14 @@ RSpec.configure do |config|
|
|
7
7
|
# some (optional) config here
|
8
8
|
end
|
9
9
|
|
10
|
+
# ActiveRecord::Base.establish_connection(
|
11
|
+
# :adapter => "mysql2",
|
12
|
+
# :database => "fast_change_table_test"
|
13
|
+
# )
|
14
|
+
|
10
15
|
ActiveRecord::Base.establish_connection(
|
11
|
-
:adapter => "
|
12
|
-
:database => "
|
16
|
+
:adapter => "sqlite3",
|
17
|
+
:database => "db/test.db"
|
13
18
|
)
|
14
19
|
|
15
20
|
|
metadata
CHANGED
@@ -1,56 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_change_table
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 1.6.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Grady Griffin
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2012-03-21 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: activerecord
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
version: "2.3"
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: rspec
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
33
47
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
- !ruby/object:Gem::Dependency
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
37
50
|
name: mysql2
|
38
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
53
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
44
61
|
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: sqlite3
|
45
65
|
prerelease: false
|
46
|
-
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
47
77
|
description: Uses table duplication to speed up migrations on large tables
|
48
|
-
email:
|
49
|
-
-
|
78
|
+
email:
|
79
|
+
- gradygriffin@gmail.com
|
50
80
|
executables: []
|
81
|
+
|
51
82
|
extensions: []
|
83
|
+
|
52
84
|
extra_rdoc_files: []
|
53
|
-
|
85
|
+
|
86
|
+
files:
|
54
87
|
- .gitignore
|
55
88
|
- CHANGELOG.md
|
56
89
|
- Gemfile
|
@@ -58,6 +91,7 @@ files:
|
|
58
91
|
- MIT-LICENSE
|
59
92
|
- README.md
|
60
93
|
- Rakefile
|
94
|
+
- db/test.db
|
61
95
|
- fast_change_table.gemspec
|
62
96
|
- lib/fast_change_table.rb
|
63
97
|
- lib/fast_change_table/fast_change_table.rb
|
@@ -67,28 +101,37 @@ files:
|
|
67
101
|
- spec/spec_helper.rb
|
68
102
|
homepage: https://github.com/thegboat/fast_change_table
|
69
103
|
licenses: []
|
104
|
+
|
70
105
|
post_install_message:
|
71
106
|
rdoc_options: []
|
72
|
-
|
107
|
+
|
108
|
+
require_paths:
|
73
109
|
- lib
|
74
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
111
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
120
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
86
128
|
requirements: []
|
129
|
+
|
87
130
|
rubyforge_project: fast_change_table
|
88
131
|
rubygems_version: 1.8.15
|
89
132
|
signing_key:
|
90
133
|
specification_version: 3
|
91
134
|
summary: Faster table changes
|
92
|
-
test_files:
|
135
|
+
test_files:
|
93
136
|
- spec/fast_change_table_spec.rb
|
94
137
|
- spec/spec_helper.rb
|