fast_change_table 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -3
- data/lib/fast_change_table/fast_change_table.rb +12 -11
- data/lib/fast_change_table/table.rb +19 -0
- data/lib/fast_change_table/version.rb +1 -1
- data/lib/fast_change_table.rb +6 -5
- metadata +6 -6
- data/lib/fast_change_table/connection_adapters.rb +0 -31
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
__fast\_change\_table__ 1.2.0
|
2
|
+
|
3
|
+
* updating for Rails 3 compatibility
|
4
|
+
|
5
|
+
|
6
|
+
__fast\_change\_table__ 1.1.4
|
7
|
+
|
8
|
+
* updating README.md
|
9
|
+
|
10
|
+
|
11
|
+
__fast\_change\_table__ 1.1.3
|
12
|
+
|
13
|
+
* updating another homepage error
|
14
|
+
|
15
|
+
|
1
16
|
__fast\_change\_table__ 1.1.2
|
2
17
|
|
3
18
|
* updating homepage error
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
Use fast\_change\_table instead of change_table in your migrations on large tables of data. Uses a duplication pattern to speed things up.
|
4
4
|
|
5
|
+
__Known issues:__
|
6
|
+
|
7
|
+
* Currently fast\_change\_table does not supported in Rails 3 reversible migration method.
|
8
|
+
|
9
|
+
|
10
|
+
__Usage:__
|
5
11
|
|
6
12
|
uses ordinary change_table syntax but adds two options
|
7
13
|
|
@@ -29,7 +35,7 @@ enable\_indexes(table, list\_of\_indexes)
|
|
29
35
|
restores a list of indexes to a table
|
30
36
|
|
31
37
|
fast\_add\_indexes(table, &block)
|
32
|
-
allows you to pass a block to add indexes.
|
38
|
+
allows you to pass a block to add indexes.
|
33
39
|
|
34
40
|
__Example:__
|
35
41
|
|
@@ -41,14 +47,15 @@ __Example:__
|
|
41
47
|
|
42
48
|
copy\_table(from\_table, to\_table, remaps = [])
|
43
49
|
|
44
|
-
* copies rows from one table into another.
|
50
|
+
* copies rows from one table into another.
|
45
51
|
by default copies data from column of from_table to to_table of same name.
|
46
52
|
will not copy data where there is no corresponding column.
|
47
53
|
the remaps argument can be supplied to tell copy table how to handle unmatched columns or override this behavior
|
54
|
+
for multiple remap columns provide an array of 2 element arrays
|
48
55
|
|
49
56
|
__Examples:__
|
50
57
|
|
51
58
|
|
52
59
|
copy_table(old_users_without_email_hash, new_table, ['MD5(email)', 'email_hash'])
|
53
60
|
|
54
|
-
copy_table(old_users_without_total, new_table, ['sum(payments)', 'total_payments'])
|
61
|
+
copy_table(old_users_without_total, new_table, [['sum(payments)', 'total_payments'], ['avg(payments)', 'average_payments']])
|
@@ -1,11 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module FastChangeTable
|
4
|
-
def self.included(base)
|
5
|
-
base.extend ClassMethods
|
6
|
-
end
|
7
2
|
|
8
|
-
module
|
3
|
+
module InstanceMethods
|
9
4
|
def fast_change_table(table_name, options = {}, &block)
|
10
5
|
options.symbolize_keys!
|
11
6
|
old_table_name = "old_#{table_name}"
|
@@ -25,6 +20,12 @@ module FastChangeTable
|
|
25
20
|
raise e
|
26
21
|
end
|
27
22
|
end
|
23
|
+
|
24
|
+
def change_table_with_remaps(table_name)
|
25
|
+
t = ActiveRecord::ConnectionAdapters::Table.new(table_name, self)
|
26
|
+
yield t
|
27
|
+
return t.renamed_columns
|
28
|
+
end
|
28
29
|
|
29
30
|
def fast_add_indexes(table, &blk)
|
30
31
|
phoney = PhoneyTable.new(table.to_s)
|
@@ -42,14 +43,14 @@ module FastChangeTable
|
|
42
43
|
else
|
43
44
|
code.gsub!(/add_index\s+"#{like_table}"/, "add_index :#{table}")
|
44
45
|
end
|
45
|
-
|
46
|
+
eval(code)
|
46
47
|
true
|
47
48
|
end
|
48
49
|
|
49
50
|
#copy_table( :sometable, :newtable, [[:old_column, :new_column]])
|
50
51
|
def copy_table(from, to, remaps = [])
|
51
|
-
old =
|
52
|
-
current =
|
52
|
+
old = columns(from).collect(&:name)
|
53
|
+
current = columns(to).collect(&:name)
|
53
54
|
remapped_columns = remaps.collect {|c| c.first.to_s}.compact
|
54
55
|
common = (current & old).sort - remapped_columns
|
55
56
|
from_columns = common.collect {|c| "`#{c}`"}
|
@@ -66,7 +67,7 @@ module FastChangeTable
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def table_schema_code(table)
|
69
|
-
dumper = ActiveRecord::SchemaDumper.send(:new,
|
70
|
+
dumper = ActiveRecord::SchemaDumper.send(:new, self)
|
70
71
|
stream = StringIO.new
|
71
72
|
dumper.send(:table, table.to_s, stream)
|
72
73
|
stream.rewind
|
@@ -75,7 +76,7 @@ module FastChangeTable
|
|
75
76
|
|
76
77
|
#removes all the indexes
|
77
78
|
def disable_indexes(table)
|
78
|
-
list =
|
79
|
+
list = indexes(table)
|
79
80
|
list.each do |i|
|
80
81
|
remove_index table, :name => i.name
|
81
82
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FastChangeTable
|
2
|
+
module TableInstanceMethods
|
3
|
+
def initialize(table_name, base)
|
4
|
+
@table_name = table_name
|
5
|
+
@base = base
|
6
|
+
@renamed_columns = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def renamed_columns
|
10
|
+
@renamed_columns || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def rename(column_name, new_column_name)
|
14
|
+
@renamed_columns ||= []
|
15
|
+
@renamed_columns << [column_name, new_column_name]
|
16
|
+
@base.rename_column(@table_name, column_name, new_column_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/fast_change_table.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'active_record'
|
2
|
-
require 'fast_change_table/
|
2
|
+
require 'fast_change_table/table'
|
3
3
|
require 'fast_change_table/fast_change_table'
|
4
4
|
require 'fast_change_table/version'
|
5
5
|
|
6
6
|
module FastChangeTable
|
7
|
-
def self.included(base)
|
8
|
-
|
9
|
-
end
|
7
|
+
# def self.included(base)
|
8
|
+
# base.extend ClassMethods
|
9
|
+
# end
|
10
10
|
end
|
11
11
|
|
12
|
-
::ActiveRecord::
|
12
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, FastChangeTable::InstanceMethods
|
13
|
+
::ActiveRecord::ConnectionAdapters::Table.send :include, FastChangeTable::TableInstanceMethods
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Grady Griffin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-05 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -78,8 +78,8 @@ files:
|
|
78
78
|
- Rakefile
|
79
79
|
- fast_change_table.gemspec
|
80
80
|
- lib/fast_change_table.rb
|
81
|
-
- lib/fast_change_table/connection_adapters.rb
|
82
81
|
- lib/fast_change_table/fast_change_table.rb
|
82
|
+
- lib/fast_change_table/table.rb
|
83
83
|
- lib/fast_change_table/version.rb
|
84
84
|
- spec/fast_change_table_spec.rb
|
85
85
|
- spec/spec_helper.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters #:nodoc:
|
3
|
-
|
4
|
-
module SchemaStatements
|
5
|
-
def change_table_with_remaps(table_name)
|
6
|
-
t = Table.new(table_name, self)
|
7
|
-
yield t
|
8
|
-
return t.renamed_columns
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class Table
|
13
|
-
|
14
|
-
def initialize(table_name, base)
|
15
|
-
@table_name = table_name
|
16
|
-
@base = base
|
17
|
-
@renamed_columns = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def renamed_columns
|
21
|
-
@renamed_columns
|
22
|
-
end
|
23
|
-
|
24
|
-
def rename(column_name, new_column_name)
|
25
|
-
@renamed_columns << [column_name, new_column_name]
|
26
|
-
@base.rename_column(@table_name, column_name, new_column_name)
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|