fast_change_table 0.0.4 → 0.0.5
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/README +12 -2
- data/lib/fast_change_table/version.rb +1 -1
- data/lib/fast_change_table.rb +10 -39
- metadata +5 -7
data/README
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
Use fast_change_table instead of change_table in your migrations on large tables of data. Uses a duplication pattern to speed things up.
|
2
2
|
|
3
3
|
# Known issues
|
4
|
-
- Probably only works with MySQL
|
5
4
|
- Not tested
|
6
5
|
|
7
6
|
uses ordinary change_table syntax but adds two options
|
@@ -26,4 +25,15 @@ fast_add_indexes(table, &block)
|
|
26
25
|
fast_add_indexes :sometable do |t|
|
27
26
|
t.index :some_column
|
28
27
|
t.index [:some_other_column, :column_three], :name => "a_multicolumn_index"
|
29
|
-
end
|
28
|
+
end
|
29
|
+
|
30
|
+
copy_table(from_table, to_table, remaps = [])
|
31
|
+
copies rows from one table into another. this probably only works with Mysql.
|
32
|
+
by default copies data from column of from_table to to_table of same name.
|
33
|
+
will not copy data where there is no corresponding column.
|
34
|
+
the remaps argument can be supplied to tell copy table how to handle unmatched columns or override this behavior
|
35
|
+
examples
|
36
|
+
|
37
|
+
copy_table(old_users_without_email_hash, new_table, ['MD5(email)', 'email_hash'])
|
38
|
+
|
39
|
+
copy_table(old_users_without_total, new_table, ['sum(payments)', 'total_payments'])
|
data/lib/fast_change_table.rb
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters #:nodoc:
|
3
3
|
|
4
|
-
class MysqlAdapter < AbstractAdapter
|
5
|
-
def tables_without_views(name = nil) #:nodoc:
|
6
|
-
tables = []
|
7
|
-
result = execute("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'", name)
|
8
|
-
result.each { |field| tables << field[0] }
|
9
|
-
result.free
|
10
|
-
tables
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
4
|
module SchemaStatements
|
15
5
|
def change_table_with_remaps(table_name)
|
16
6
|
t = Table.new(table_name, self)
|
@@ -104,17 +94,11 @@ module FastChangeTable
|
|
104
94
|
to_columns_to_s = to_columns.join(', ')
|
105
95
|
execute "INSERT INTO #{to}(#{to_columns_to_s}) SELECT #{from_columns_to_s} FROM #{from}"
|
106
96
|
end
|
107
|
-
|
108
|
-
def create_table(table_name, options = {})
|
109
|
-
rtn = super
|
110
|
-
execute "alter table `#{table_name}` row_format=dynamic" if connection.adapter_name =~ /^mysql/i
|
111
|
-
rtn
|
112
|
-
end
|
113
97
|
|
114
98
|
def table_schema_code(table)
|
115
99
|
dumper = ActiveRecord::SchemaDumper.send(:new, connection)
|
116
100
|
stream = StringIO.new
|
117
|
-
dumper.
|
101
|
+
dumper.send(:table, table.to_s, stream)
|
118
102
|
stream.rewind
|
119
103
|
code = stream.read
|
120
104
|
end
|
@@ -122,33 +106,20 @@ module FastChangeTable
|
|
122
106
|
#removes all the indexes
|
123
107
|
def disable_indexes(table)
|
124
108
|
list = connection.indexes(table)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
else
|
129
|
-
list.each do |i|
|
130
|
-
remove_index table, :name => i.name
|
131
|
-
end
|
132
|
-
end
|
109
|
+
list.each do |i|
|
110
|
+
remove_index table, :name => i.name
|
111
|
+
end
|
133
112
|
list
|
134
113
|
end
|
135
114
|
|
136
115
|
#
|
137
116
|
def enable_indexes(table, list)
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
else
|
145
|
-
list.each do |i|
|
146
|
-
options = {}
|
147
|
-
options[:name] = i.name if i.name
|
148
|
-
options[:length] = i.lengths if i.lengths
|
149
|
-
options[:unique] = i.unique if i.unique
|
150
|
-
add_index table, i.columns, options
|
151
|
-
end
|
117
|
+
list.each do |i|
|
118
|
+
options = {}
|
119
|
+
options[:name] = i.name if i.name
|
120
|
+
options[:length] = i.lengths if i.lengths
|
121
|
+
options[:unique] = i.unique if i.unique
|
122
|
+
add_index table, i.columns, options
|
152
123
|
end
|
153
124
|
true
|
154
125
|
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Grady Griffin
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
19
|
-
default_executable:
|
18
|
+
date: 2012-01-23 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: activerecord
|
@@ -52,7 +51,6 @@ files:
|
|
52
51
|
- lib/fast_change_table.rb
|
53
52
|
- lib/fast_change_table/version.rb
|
54
53
|
- test/fast_change_table_test.rb
|
55
|
-
has_rdoc: true
|
56
54
|
homepage: https://github.com/moxie/fast_change_table
|
57
55
|
licenses: []
|
58
56
|
|
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
80
|
requirements: []
|
83
81
|
|
84
82
|
rubyforge_project: fast_change_table
|
85
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.8.15
|
86
84
|
signing_key:
|
87
85
|
specification_version: 3
|
88
86
|
summary: Faster table changes
|