fast_change_table 1.4.0 → 1.5.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 +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +16 -5
- data/lib/fast_change_table/fast_change_table.rb +2 -1
- data/lib/fast_change_table/version.rb +1 -1
- data/spec/fast_change_table_spec.rb +13 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,17 +27,28 @@ __Example:__
|
|
27
27
|
|
28
28
|
__other methods:__
|
29
29
|
|
30
|
-
create\_table\_like(orignal\_table,
|
31
|
-
|
30
|
+
create\_table\_like(orignal\_table, new\_table)
|
31
|
+
|
32
|
+
* creates a table with the same structure.
|
33
|
+
* BE CAREFUL!, create\_table\_like always drops the new table if it exists
|
34
|
+
|
35
|
+
__Example of creating a similar table but without the indexes and an added column:__
|
36
|
+
|
37
|
+
create_table_like :original_table, :new_table, :remove_keys => true do |t|
|
38
|
+
t.integer :an_integer
|
39
|
+
end
|
32
40
|
|
33
41
|
disable\_indexes(table)
|
34
|
-
|
42
|
+
|
43
|
+
* removes all indexes from a table, returns a list of index objects removed. uses bulk alter when possible
|
35
44
|
|
36
45
|
enable\_indexes(table, list\_of\_indexes)
|
37
|
-
|
46
|
+
|
47
|
+
* restores a list of indexes to a table. uses bulk alter when possible
|
38
48
|
|
39
49
|
fast\_add\_indexes(table, &block)
|
40
|
-
|
50
|
+
|
51
|
+
* allows you to pass a block to add indexes. uses bulk alter when possible
|
41
52
|
|
42
53
|
__Example:__
|
43
54
|
|
@@ -42,7 +42,7 @@ module FastChangeTable
|
|
42
42
|
end
|
43
43
|
|
44
44
|
#create_table_like( :sometable, :newtable, :remove_keys => true)
|
45
|
-
def create_table_like(like_table, table, options = {})
|
45
|
+
def create_table_like(like_table, table, options = {}, &blk)
|
46
46
|
options.symbolize_keys!
|
47
47
|
code = table_schema_code(like_table)
|
48
48
|
code.gsub!(/create_table\s+"#{like_table}"/, "create_table :#{table}")
|
@@ -52,6 +52,7 @@ module FastChangeTable
|
|
52
52
|
code.gsub!(/add_index\s+"#{like_table}"/, "add_index :#{table}")
|
53
53
|
end
|
54
54
|
eval(code)
|
55
|
+
change_table(table,&blk) if block_given?
|
55
56
|
true
|
56
57
|
end
|
57
58
|
|
@@ -33,6 +33,19 @@ describe ActiveRecord::Migration do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
describe "#create_table_like" do
|
37
|
+
it "should create an identical table with an added column" do
|
38
|
+
|
39
|
+
ActiveRecord::Migration.create_table_like :my_table, :my_copied_table do |t|
|
40
|
+
t.integer :added_column
|
41
|
+
end
|
42
|
+
|
43
|
+
@connection.columns("my_copied_table").all? do |c|
|
44
|
+
["id", "an_integer", "a_string", "a_name","old_name", "added_column"].include?(c.name.to_s)
|
45
|
+
end.should eq(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
36
49
|
describe "#fast_add_indexes, #disable_indexes, #enable_indexes" do
|
37
50
|
it "should add index, remove it then put it back" do
|
38
51
|
ActiveRecord::Migration.fast_add_indexes :my_table do |t|
|
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: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.5.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-15 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|