fast_change_table 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +18 -0
- data/Rakefile +1 -0
- data/fast_change_table.gemspec +27 -0
- data/lib/fast_change_table/version.rb +3 -0
- data/lib/fast_change_table.rb +33 -0
- metadata +89 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use default@fast_change_table
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fast_change_table (0.0.1)
|
5
|
+
activerecord (~> 2.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activerecord (2.3.14)
|
11
|
+
activesupport (= 2.3.14)
|
12
|
+
activesupport (2.3.14)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
fast_change_table!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fast_change_table/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fast_change_table"
|
7
|
+
s.version = FastChangeTable::VERSION
|
8
|
+
s.authors = ["Joe Peduto"]
|
9
|
+
s.email = ["joey@izea.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Faster table changes}
|
12
|
+
s.description = %q{Uses table duplication to speed up migrations on large tables}
|
13
|
+
|
14
|
+
s.rubyforge_project = "fast_change_table"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
23
|
+
s.add_runtime_dependency('activerecord', '~> 2.3')
|
24
|
+
else
|
25
|
+
s.add_dependency('activerecord', '~> 2.3')
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "activerecord"
|
2
|
+
require "fast_change_table/version"
|
3
|
+
|
4
|
+
module FastChangeTable
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def fast_change_table(table_name, &block)
|
11
|
+
old_table_name = "old_#{table_name}"
|
12
|
+
rename_table table_name, old_table_name
|
13
|
+
begin
|
14
|
+
execute "DROP TABLE IF EXISTS #{table_name}"
|
15
|
+
execute "CREATE TABLE #{table_name} LIKE #{old_table_name}"
|
16
|
+
change_table(table_name, &block)
|
17
|
+
#prepare the columns names for the insert statements
|
18
|
+
old = connection.columns(old_table_name).collect(&:name)
|
19
|
+
current = connection.columns(table_name).collect(&:name)
|
20
|
+
common = (current & old).sort
|
21
|
+
columns_to_s = common.collect {|c| "`#{c}`"}.join(',')
|
22
|
+
execute "INSERT INTO #{table_name}(#{columns_to_s}) SELECT #{columns_to_s} FROM #{old_table_name}"
|
23
|
+
drop_table old_table_name
|
24
|
+
rescue Exception => e
|
25
|
+
puts "#{e}\n#{e.backtrace}"
|
26
|
+
execute "DROP TABLE IF EXISTS #{table_name}"
|
27
|
+
rename_table old_table_name, table_name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
::ActiveRecord::Migration.send :include, FastChangeTable
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_change_table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joe Peduto
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-30 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
version: "2.3"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Uses table duplication to speed up migrations on large tables
|
37
|
+
email:
|
38
|
+
- joey@izea.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- .rvmrc
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- Rakefile
|
51
|
+
- fast_change_table.gemspec
|
52
|
+
- lib/fast_change_table.rb
|
53
|
+
- lib/fast_change_table/version.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: ""
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: fast_change_table
|
84
|
+
rubygems_version: 1.4.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Faster table changes
|
88
|
+
test_files: []
|
89
|
+
|