sequel_migration_builder 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -101,7 +101,7 @@ module Sequel
|
|
101
101
|
def alter_table_statement(table_name, operations, direction)
|
102
102
|
add_line "alter_table #{table_name.inspect} do"
|
103
103
|
indent do
|
104
|
-
operations.
|
104
|
+
operations.map {|op| op.__send__(direction) }.compact.each {|op| add_line op }
|
105
105
|
end
|
106
106
|
add_line "end"
|
107
107
|
end
|
@@ -26,18 +26,26 @@ module Sequel
|
|
26
26
|
db_indexes = db_table[:indexes] || {}
|
27
27
|
new_indexes = new_table[:indexes] || {}
|
28
28
|
|
29
|
-
operations += (db_indexes.keys - new_indexes.keys).
|
30
|
-
db_indexes[index_name][:columns].size == 1 && dropped_columns.include?(db_indexes[index_name][:columns].first)
|
31
|
-
|
29
|
+
operations += (db_indexes.keys - new_indexes.keys).map do |index_name|
|
30
|
+
dropped_column = db_indexes[index_name][:columns].size == 1 && dropped_columns.include?(db_indexes[index_name][:columns].first)
|
31
|
+
|
32
32
|
DropIndex.new(index_name,
|
33
33
|
db_indexes[index_name][:columns],
|
34
|
-
db_indexes[index_name][:unique]
|
34
|
+
db_indexes[index_name][:unique],
|
35
|
+
! dropped_column)
|
35
36
|
end
|
36
37
|
|
37
38
|
operations += (new_indexes.keys - db_indexes.keys).map do |index_name|
|
39
|
+
if new_indexes[index_name][:columns].kind_of?(Symbol)
|
40
|
+
dropped_column = dropped_columns.include?(new_indexes[index_name][:columns])
|
41
|
+
else
|
42
|
+
dropped_column = new_indexes[index_name][:columns].size == 1 && dropped_columns.include?(new_indexes[index_name][:columns].first)
|
43
|
+
end
|
44
|
+
|
38
45
|
AddIndex.new(index_name,
|
39
46
|
new_indexes[index_name][:columns],
|
40
|
-
new_indexes[index_name][:unique]
|
47
|
+
new_indexes[index_name][:unique],
|
48
|
+
! dropped_column)
|
41
49
|
end
|
42
50
|
|
43
51
|
operations
|
@@ -94,17 +102,21 @@ module Sequel
|
|
94
102
|
|
95
103
|
# Adds an index.
|
96
104
|
class AddIndex < Operation
|
97
|
-
def initialize(name, columns, unique)
|
105
|
+
def initialize(name, columns, unique, include_drop_index=true)
|
98
106
|
@up = "add_index #{columns.inspect}, :name => #{name.inspect}"
|
99
107
|
@up << ", :unique => true" if unique
|
100
|
-
|
108
|
+
if include_drop_index
|
109
|
+
@down = "drop_index #{columns.inspect}, :name => #{name.inspect}"
|
110
|
+
end
|
101
111
|
end
|
102
112
|
end
|
103
113
|
|
104
114
|
# Drops an index.
|
105
115
|
class DropIndex < Operation
|
106
|
-
def initialize(name, columns, unique)
|
107
|
-
|
116
|
+
def initialize(name, columns, unique, include_drop_index=true)
|
117
|
+
if include_drop_index
|
118
|
+
@up = "drop_index #{columns.inspect}, :name => #{name.inspect}"
|
119
|
+
end
|
108
120
|
@down = "add_index #{columns.inspect}, :name => #{name.inspect}"
|
109
121
|
@down << ", :unique => true" if unique
|
110
122
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sequel_migration_builder}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Roland Swingler"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-13}
|
13
13
|
s.description = %q{Build Sequel Migrations based on the differences between two schemas}
|
14
14
|
s.email = %q{roland.swingler@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -114,15 +114,28 @@ describe "Sequel::Schema::AlterTableOperations.build" do
|
|
114
114
|
ops.first.should be_kind_of(Sequel::Schema::AlterTableOperations::ChangeColumn)
|
115
115
|
end
|
116
116
|
|
117
|
-
it "should not output a drop index if the index's column is also removed" do
|
117
|
+
it "should not output a drop index statement in #up if the index's column is also removed" do
|
118
118
|
table_a = {:name => :example_table,
|
119
119
|
:indexes => {:foo_idx => {:columns => [:foo]}},
|
120
120
|
:columns => [build_column(:name => :foo, :column_type => :integer)]}
|
121
121
|
table_b = {:name => :example_table, :indexes => {}, :columns => []}
|
122
122
|
ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
|
123
123
|
|
124
|
-
ops.
|
125
|
-
ops.
|
124
|
+
ops.last.should be_kind_of(Sequel::Schema::AlterTableOperations::DropIndex)
|
125
|
+
ops.last.up.should be_nil
|
126
|
+
ops.last.down.should == "add_index [:foo], :name => :foo_idx"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not output a drop index statement in #down if the index's column is also added" do
|
130
|
+
table_a = {:name => :example_table,
|
131
|
+
:indexes => {},
|
132
|
+
:columns => [build_column(:name => :foo, :column_type => :integer)]}
|
133
|
+
table_b = {:name => :example_table, :indexes => {:foo_idx => {:columns => [:foo]}}, :columns => []}
|
134
|
+
ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
|
135
|
+
|
136
|
+
ops.last.should be_kind_of(Sequel::Schema::AlterTableOperations::AddIndex)
|
137
|
+
ops.last.up.should == "add_index [:foo], :name => :foo_idx"
|
138
|
+
ops.last.down.should be_nil
|
126
139
|
end
|
127
140
|
end
|
128
141
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Roland Swingler
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-13 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|