exodus 1.1.6 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.md +5 -1
- data/lib/exodus.rb +9 -9
- data/lib/exodus/config/migration_info.rb +4 -2
- data/lib/exodus/version.rb +1 -1
- data/spec/exodus/exodus_spec.rb +81 -116
- data/spec/exodus/migration_spec.rb +35 -67
- data/spec/spec_helper.rb +42 -0
- data/spec/support/test_class_definition.rb +67 -0
- metadata +7 -15
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDA1ZTUwNDNiYzRhYTE5NGU5ZGM1N2EyM2RhODFjZjBmMGY5NTcyNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjMyZDNiOTE0ZWZiNjBiM2QzYzY2MTMyNmQxOTJmZjRhZmE1YWYxZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODg2NTU5Yjg1MmRiMWVkMjBlN2Q5OWY0YWRkYTU4YTIzNTA4MjQzYjhhNzkw
|
10
|
+
MTU0ZmEwMDZlMTE5NGE0ZTgxODFhYjI5NjliNTM5MzlmMTY2MTA4NjVhOTAw
|
11
|
+
NzQzNTlhYmJmOTM3YmMxMDRjOWVjODA0ZjdiZmUwZWUyYTNlOTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjU1MTU1ZjFhY2VlOGU3OWUxNTNkYmNkZjY3NDdiMGI5MjdjZGQwOGU4Yzhh
|
14
|
+
YzgzNzM3N2RlYTQzYjYyN2ZmYzgyZGRlM2RhNzQxOTgzNTliNjhlYTlkNDNi
|
15
|
+
M2JmN2NjN2ViM2RjNGMzZTFjMDQ5Y2M0Zjg4Yjg2ODA0MzE0ZjU=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## v1.1.7
|
2
|
+
|
3
|
+
* Added MongoMapper pre 0.13.0 inheritance compatibility
|
4
|
+
|
1
5
|
## v1.1.6
|
2
6
|
|
3
7
|
* Rerunnable migration is now a class property
|
@@ -25,7 +29,7 @@
|
|
25
29
|
|
26
30
|
## v1.1.0
|
27
31
|
|
28
|
-
* Changed the way migration are executed
|
32
|
+
* Changed the way migration are executed
|
29
33
|
* Cleaner output
|
30
34
|
* Ability to see which migration will be executed before rake db:migrate and db:rollback with rake db:migrate:show and db:rollback:show
|
31
35
|
* Fixed a text formatter issue
|
data/lib/exodus.rb
CHANGED
@@ -23,18 +23,18 @@ module Exodus
|
|
23
23
|
Dir[migrations_info.migrations_directory + '/*.rb'].each { |file| require file}
|
24
24
|
end
|
25
25
|
|
26
|
-
# Returns the path of the rake file
|
26
|
+
# Returns the path of the rake file
|
27
27
|
def tasks
|
28
28
|
File.dirname(__FILE__) + '/../tasks/exodus.rake'
|
29
29
|
end
|
30
30
|
|
31
31
|
# Sorts and executes a number of migrations equal to step (or all of them if step is nil)
|
32
|
-
def sort_and_run_migrations(direction, migrations_info, step = nil, show_characteristic = false)
|
32
|
+
def sort_and_run_migrations(direction, migrations_info, step = nil, show_characteristic = false)
|
33
33
|
if migrations_info
|
34
34
|
sorted_migrations_info = order_with_direction(migrations_info, direction)
|
35
35
|
runnable_migrations = find_runable_migrations(direction, sorted_migrations_info, step)
|
36
36
|
|
37
|
-
if show_characteristic
|
37
|
+
if show_characteristic
|
38
38
|
runnable_migrations.map(&:characteristic)
|
39
39
|
else
|
40
40
|
run_migrations(direction, runnable_migrations)
|
@@ -46,7 +46,7 @@ module Exodus
|
|
46
46
|
|
47
47
|
# Instanciates all of the migrations and returns the ones that are runnable
|
48
48
|
def find_runable_migrations(direction, migrations_info, step)
|
49
|
-
runnable_migrations = migrations_info.map do |migration_class, args|
|
49
|
+
runnable_migrations = migrations_info.map do |migration_class, args|
|
50
50
|
migration = instanciate_migration(migration_class, args)
|
51
51
|
migration if migration.is_runnable?(direction)
|
52
52
|
end.compact.uniq
|
@@ -54,11 +54,11 @@ module Exodus
|
|
54
54
|
step ? runnable_migrations.shift(step.to_i) : runnable_migrations
|
55
55
|
end
|
56
56
|
|
57
|
-
# Migrations order need to be reverted if the direction is down
|
57
|
+
# Migrations order need to be reverted if the direction is down
|
58
58
|
# (we want the latest executed migration to be the first reverted)
|
59
59
|
def order_with_direction(migrations_info, direction)
|
60
60
|
sorted_migrations = sort_migrations(migrations_info)
|
61
|
-
direction == Migration::UP ? sorted_migrations : sorted_migrations.reverse
|
61
|
+
direction == Migration::UP ? sorted_migrations : sorted_migrations.reverse
|
62
62
|
end
|
63
63
|
|
64
64
|
# Sorts migrations using the migration number
|
@@ -72,7 +72,7 @@ module Exodus
|
|
72
72
|
print_tabulation { run_one_migration(migration, direction) }
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# Runs the migration and save the current status into mongo
|
77
77
|
def run_one_migration(migration, direction)
|
78
78
|
begin
|
@@ -88,7 +88,7 @@ module Exodus
|
|
88
88
|
end
|
89
89
|
|
90
90
|
# Database lookup to find a migration given its class and its arguments
|
91
|
-
# Instanciates it if the migration is not present in the database
|
91
|
+
# Instanciates it if the migration is not present in the database
|
92
92
|
def instanciate_migration(migration_class, args)
|
93
93
|
args ||= {}
|
94
94
|
find_existing_migration(migration_class, args) || migration_class.new(:status => {:arguments => args})
|
@@ -99,7 +99,7 @@ module Exodus
|
|
99
99
|
def find_existing_migration(migration_class, args)
|
100
100
|
existing_migrations = migration_class.collection.find('status.arguments' => args)
|
101
101
|
existing_migrations.detect do |migration|
|
102
|
-
existing_migration =
|
102
|
+
existing_migration = Migration.load(migration)
|
103
103
|
|
104
104
|
return existing_migration if existing_migration.is_a?(migration_class)
|
105
105
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Exodus
|
2
4
|
class MigrationInfo
|
3
5
|
attr_accessor :info, :migrations_directory
|
4
6
|
attr_reader :config_file, :db, :connection, :rake_namespace
|
5
7
|
|
6
8
|
def initialize(file = nil)
|
7
|
-
config_file = file if file
|
9
|
+
config_file = file if file
|
8
10
|
end
|
9
11
|
|
10
12
|
def db=(database)
|
@@ -49,7 +51,7 @@ module Exodus
|
|
49
51
|
@info
|
50
52
|
end
|
51
53
|
|
52
|
-
private
|
54
|
+
private
|
53
55
|
|
54
56
|
def verify_yml_syntax
|
55
57
|
Raise StandardError, "No configuration file specified" unless self.config_file
|
data/lib/exodus/version.rb
CHANGED
data/spec/exodus/exodus_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Exodus do
|
4
|
-
describe Exodus::MigrationInfo do
|
5
|
-
describe "#rake_namespace" do
|
6
|
-
it "should use the namespace provided in the yml file" do
|
3
|
+
describe Exodus do
|
4
|
+
describe Exodus::MigrationInfo do
|
5
|
+
describe "#rake_namespace" do
|
6
|
+
it "should use the namespace provided in the yml file" do
|
7
7
|
Exodus.configuration.rake_namespace.should == 'test:'
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should be blank when no namespace is given" do
|
10
|
+
it "should be blank when no namespace is given" do
|
11
11
|
Exodus.configuration.rake_namespace = nil
|
12
12
|
Exodus.configuration.rake_namespace.should == ''
|
13
13
|
|
@@ -15,7 +15,7 @@ describe Exodus do
|
|
15
15
|
Exodus.configuration.rake_namespace.should == ''
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should end with ':' when a namespace is given" do
|
18
|
+
it "should end with ':' when a namespace is given" do
|
19
19
|
Exodus.configuration.rake_namespace = 'test1'
|
20
20
|
Exodus.configuration.rake_namespace.should == 'test1:'
|
21
21
|
|
@@ -25,41 +25,41 @@ describe Exodus do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
before do
|
28
|
+
before :all do
|
29
29
|
Exodus::Migration.collection.drop
|
30
30
|
end
|
31
31
|
|
32
|
-
describe "sort_migrations" do
|
32
|
+
describe "#sort_migrations" do
|
33
33
|
before do
|
34
|
-
|
35
|
-
|
34
|
+
create_dynamic_class('Migration_test4')
|
35
|
+
create_dynamic_class('Migration_test3')
|
36
36
|
|
37
37
|
Migration_test3.migration_number = 3
|
38
38
|
Migration_test4.migration_number = 4
|
39
39
|
end
|
40
40
|
|
41
|
-
it "migrations should not be sorted by default" do
|
41
|
+
it "migrations should not be sorted by default" do
|
42
42
|
unsorted_migrations = Exodus::Migration.load_all([])
|
43
43
|
migrations_numbers = unsorted_migrations.map {|migration, args| migration.migration_number }
|
44
44
|
|
45
|
-
migrations_numbers.should_not == migrations_numbers.sort
|
45
|
+
migrations_numbers.should_not == migrations_numbers.sort
|
46
46
|
end
|
47
47
|
|
48
|
-
it "should return the migrations sorted by migration number" do
|
48
|
+
it "should return the migrations sorted by migration number" do
|
49
49
|
unsorted_migrations = Exodus::Migration.load_all([])
|
50
50
|
migrations_numbers = unsorted_migrations.map {|migration, args| migration.migration_number }
|
51
51
|
|
52
52
|
sorted_migrations = Exodus::sort_migrations(unsorted_migrations)
|
53
53
|
sorted_migrations_numbers = sorted_migrations.map {|migration, args| migration.migration_number }
|
54
|
-
sorted_migrations_numbers.should == migrations_numbers.sort
|
54
|
+
sorted_migrations_numbers.should == migrations_numbers.sort
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
describe "order_with_direction" do
|
58
|
+
describe "#order_with_direction" do
|
59
59
|
before do
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
create_dynamic_class('Migration_test4')
|
61
|
+
create_dynamic_class('Migration_test3')
|
62
|
+
create_dynamic_class('Migration_test5')
|
63
63
|
|
64
64
|
Migration_test3.migration_number = 3
|
65
65
|
Migration_test4.migration_number = 4
|
@@ -76,67 +76,59 @@ describe Exodus do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
describe "when direction is UP" do
|
79
|
-
it "should be sorted ascendingly" do
|
80
|
-
@ordered_up.should == @migrations_numbers.sort
|
79
|
+
it "should be sorted ascendingly" do
|
80
|
+
@ordered_up.should == @migrations_numbers.sort
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe "when direction is UP" do
|
85
|
-
it "should be sorted ascendingly" do
|
86
|
-
@ordered_down.should == @migrations_numbers.sort.reverse
|
85
|
+
it "should be sorted ascendingly" do
|
86
|
+
@ordered_down.should == @migrations_numbers.sort.reverse
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
describe "tasks" do
|
91
|
+
describe "#tasks" do
|
92
92
|
it "should return the current path of exodus.rake" do
|
93
93
|
rake_file = Pathname.new(File.dirname(__FILE__) + '/../../tasks/exodus.rake')
|
94
94
|
Pathname.new(Exodus.tasks).realpath.to_s.should == rake_file.realpath.to_s
|
95
|
-
end
|
95
|
+
end
|
96
96
|
end
|
97
97
|
|
98
|
-
describe "run_one_migration" do
|
98
|
+
describe "#run_one_migration" do
|
99
99
|
before do
|
100
|
-
|
101
|
-
|
102
|
-
'valid'
|
103
|
-
end
|
104
|
-
end
|
105
|
-
class Migration_test7 < Exodus::Migration
|
106
|
-
def up
|
107
|
-
raise StandardError, "the current migration failed"
|
108
|
-
end
|
109
|
-
end
|
100
|
+
create_dynamic_class('Migration_test6')
|
101
|
+
create_dynamic_class('Migration_test7')
|
110
102
|
end
|
111
103
|
|
112
104
|
before :each do
|
113
105
|
Exodus::Migration.collection.drop
|
114
106
|
end
|
115
107
|
|
116
|
-
describe "When the migration has not been ran" do
|
117
|
-
describe "with a valid migration" do
|
118
|
-
it "should successfully create the migration" do
|
108
|
+
describe "When the migration has not been ran" do
|
109
|
+
describe "with a valid migration" do
|
110
|
+
it "should successfully create the migration" do
|
119
111
|
migration = Exodus.instanciate_migration(Migration_test6, {})
|
120
112
|
lambda{ Exodus.run_one_migration(migration, 'up')}.should change(Exodus::Migration, :count).by(1)
|
121
113
|
end
|
122
114
|
end
|
123
115
|
|
124
|
-
describe "with a failing migration" do
|
116
|
+
describe "with a failing migration" do
|
125
117
|
let(:migration) {Exodus.instanciate_migration(Migration_test7, {})}
|
126
118
|
|
127
|
-
it "should raise an error" do
|
128
|
-
lambda {Exodus.run_one_migration(migration, 'up')}.should raise_error(StandardError)
|
119
|
+
it "should raise an error" do
|
120
|
+
lambda {Exodus.run_one_migration(migration, 'up')}.should raise_error(StandardError)
|
129
121
|
end
|
130
122
|
|
131
|
-
it "should still create the migration" do
|
123
|
+
it "should still create the migration" do
|
132
124
|
lambda {Exodus.run_one_migration(migration, 'up') rescue nil}.should change(Exodus::Migration, :count).by(1)
|
133
125
|
end
|
134
126
|
end
|
135
127
|
end
|
136
128
|
|
137
|
-
describe "When the migration has been ran" do
|
138
|
-
describe "with a valid migration" do
|
139
|
-
it "should not create a new migration" do
|
129
|
+
describe "When the migration has been ran" do
|
130
|
+
describe "with a valid migration" do
|
131
|
+
it "should not create a new migration" do
|
140
132
|
migration = Exodus.instanciate_migration(Migration_test6, {})
|
141
133
|
Exodus.run_one_migration(migration, 'up')
|
142
134
|
|
@@ -144,8 +136,8 @@ describe Exodus do
|
|
144
136
|
end
|
145
137
|
end
|
146
138
|
|
147
|
-
describe "with a failing migration" do
|
148
|
-
it "should not create a new migration" do
|
139
|
+
describe "with a failing migration" do
|
140
|
+
it "should not create a new migration" do
|
149
141
|
migration = Exodus.instanciate_migration(Migration_test7, {})
|
150
142
|
Exodus.run_one_migration(migration, 'up') rescue nil
|
151
143
|
|
@@ -155,41 +147,41 @@ describe Exodus do
|
|
155
147
|
end
|
156
148
|
end
|
157
149
|
|
158
|
-
describe "find_existing_migration" do
|
150
|
+
describe "#find_existing_migration" do
|
159
151
|
before do
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
164
|
-
end
|
165
|
-
class Migration_test8 < Exodus::Migration
|
166
|
-
def up
|
167
|
-
'valid'
|
168
|
-
end
|
169
|
-
end
|
152
|
+
create_dynamic_class('Migration_test6')
|
153
|
+
create_dynamic_class('Migration_test8')
|
154
|
+
create_dynamic_class('RerunnableMigrationTest')
|
170
155
|
end
|
171
156
|
|
172
157
|
before :each do
|
173
158
|
Exodus::Migration.collection.drop
|
174
159
|
end
|
175
160
|
|
176
|
-
describe "When no migrations have been ran" do
|
177
|
-
it "should not find any migration" do
|
161
|
+
describe "When no migrations have been ran" do
|
162
|
+
it "should not find any migration" do
|
178
163
|
Exodus.find_existing_migration(Migration_test8, {}).should be_nil
|
179
164
|
end
|
180
165
|
end
|
181
166
|
|
182
|
-
describe "When a different migration has been ran" do
|
183
|
-
it "should not find any migration" do
|
167
|
+
describe "When a different migration has been ran" do
|
168
|
+
it "should not find any migration" do
|
184
169
|
migration = Exodus.instanciate_migration(Migration_test6, {})
|
185
170
|
Exodus.run_one_migration(migration, 'up')
|
186
171
|
|
187
172
|
Exodus.find_existing_migration(Migration_test8, {}).should be_nil
|
188
173
|
end
|
174
|
+
|
175
|
+
it "should not find any migration with rerunnable migration either" do
|
176
|
+
migration = Exodus.instanciate_migration(Migration_test6, {})
|
177
|
+
Exodus.run_one_migration(migration, 'up')
|
178
|
+
|
179
|
+
Exodus.find_existing_migration(RerunnableMigrationTest, {}).should be_nil
|
180
|
+
end
|
189
181
|
end
|
190
182
|
|
191
|
-
describe "When the migration has been ran" do
|
192
|
-
it "should find the migration" do
|
183
|
+
describe "When the migration has been ran" do
|
184
|
+
it "should find the migration" do
|
193
185
|
migration = Exodus.instanciate_migration(Migration_test8, {})
|
194
186
|
Exodus.run_one_migration(migration, 'up')
|
195
187
|
|
@@ -197,8 +189,8 @@ describe Exodus do
|
|
197
189
|
end
|
198
190
|
end
|
199
191
|
|
200
|
-
describe "When all migrations have been ran" do
|
201
|
-
it "should find the migration" do
|
192
|
+
describe "When all migrations have been ran" do
|
193
|
+
it "should find the migration" do
|
202
194
|
migration6 = Exodus.instanciate_migration(Migration_test6, {})
|
203
195
|
migration8 = Exodus.instanciate_migration(Migration_test8, {})
|
204
196
|
Exodus.run_one_migration(migration6, 'up')
|
@@ -211,84 +203,57 @@ describe Exodus do
|
|
211
203
|
|
212
204
|
describe "run_migrations and sort_and_run_migrations" do
|
213
205
|
before do
|
214
|
-
|
215
|
-
|
216
|
-
def up
|
217
|
-
UserSupport.create!({:name => "Thomas"})
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
class Migration_test10 < Exodus::Migration
|
222
|
-
@migration_number = 10
|
223
|
-
def up
|
224
|
-
UserSupport.create!({:name => "Tester"})
|
225
|
-
end
|
226
|
-
end
|
206
|
+
create_dynamic_class('Migration_test9')
|
207
|
+
create_dynamic_class('Migration_test10')
|
227
208
|
end
|
228
209
|
|
229
|
-
before :each do
|
230
|
-
UserSupport
|
231
|
-
Exodus::Migration.collection.drop
|
210
|
+
before :each do
|
211
|
+
reset_collections(UserSupport,Exodus::Migration)
|
232
212
|
end
|
233
213
|
|
234
|
-
|
235
|
-
it "should successfully run them in different order" do
|
236
|
-
migrations_info = [[Migration_test9, {}], [Migration_test10, {}]]
|
237
|
-
migrations = migrations_info.map{|migration_info| Exodus.instanciate_migration(*migration_info)}
|
238
|
-
|
239
|
-
Exodus.run_migrations('up', migrations)
|
240
|
-
users = UserSupport.all
|
214
|
+
let(:migrations_info) { [[Migration_test9, {}], [Migration_test10, {}]]}
|
241
215
|
|
242
|
-
|
243
|
-
|
216
|
+
describe "running the same migration in a different order with run_migrations" do
|
217
|
+
it "should successfully run them in different order" do
|
218
|
+
instanciate_and_run_up_migrations(*migrations_info)
|
219
|
+
get_users_names.should == ["Thomas", "Tester"]
|
244
220
|
|
245
|
-
UserSupport
|
246
|
-
Exodus
|
221
|
+
reset_collections(UserSupport, Exodus::Migration)
|
222
|
+
migrations = migrations_info.map{|migration_info| Exodus.instanciate_migration(*migration_info)}
|
247
223
|
Exodus.run_migrations('up', migrations.reverse)
|
248
|
-
|
249
|
-
|
250
|
-
users.first.name.should == "Tester"
|
251
|
-
users.last.name.should == "Thomas"
|
224
|
+
get_users_names.should == ["Tester", "Thomas"]
|
252
225
|
end
|
253
226
|
end
|
254
227
|
|
255
|
-
describe "running the same migration in a different order with sort_and_run_migrations" do
|
228
|
+
describe "running the same migration in a different order with sort_and_run_migrations" do
|
256
229
|
it "should successfully run them in the same order" do
|
257
|
-
|
258
|
-
|
259
|
-
users = UserSupport.all
|
260
|
-
|
261
|
-
users.first.name.should == "Thomas"
|
262
|
-
users.last.name.should == "Tester"
|
263
|
-
|
264
|
-
UserSupport.collection.drop
|
265
|
-
Exodus::Migration.collection.drop
|
266
|
-
Exodus.sort_and_run_migrations('up', migrations.reverse)
|
267
|
-
users = UserSupport.all
|
230
|
+
Exodus.sort_and_run_migrations('up', migrations_info)
|
231
|
+
get_users_names.should == ["Thomas", "Tester"]
|
268
232
|
|
269
|
-
|
270
|
-
|
233
|
+
reset_collections(UserSupport, Exodus::Migration)
|
234
|
+
Exodus.sort_and_run_migrations('up', migrations_info.reverse)
|
235
|
+
get_users_names.should == ["Thomas", "Tester"]
|
271
236
|
end
|
272
237
|
end
|
273
238
|
|
274
239
|
it "should run only one time the same migration" do
|
275
|
-
migrations = [[Migration_test9, {}], [Migration_test9, {}]]
|
240
|
+
migrations = [[Migration_test9, {}], [Migration_test9, {}]]
|
276
241
|
lambda {Exodus.sort_and_run_migrations('up', migrations)}.should change(Exodus::Migration, :count).by(1)
|
277
242
|
end
|
278
243
|
|
279
244
|
it "should run successfully only one time when specifying the step option" do
|
280
|
-
migrations = [[Migration_test9, {}], [Migration_test10, {}]]
|
245
|
+
migrations = [[Migration_test9, {}], [Migration_test10, {}]]
|
281
246
|
lambda {Exodus.sort_and_run_migrations('up', migrations, 1)}.should change(Exodus::Migration, :count).by(1)
|
282
247
|
end
|
283
248
|
|
284
|
-
describe "Getting migration information" do
|
249
|
+
describe "Getting migration information" do
|
285
250
|
it "should successfully print the migrations information" do
|
286
|
-
migrations = [[Migration_test9, {}], [Migration_test10, {}]]
|
251
|
+
migrations = [[Migration_test9, {}], [Migration_test10, {}]]
|
287
252
|
Exodus.sort_and_run_migrations('up', migrations, nil, true).should == ["Migration_test9: #{{}}", "Migration_test10: #{{}}"]
|
288
253
|
end
|
289
254
|
|
290
255
|
it "should successfully print the first migration information" do
|
291
|
-
migrations = [[Migration_test9, {}], [Migration_test10, {}]]
|
256
|
+
migrations = [[Migration_test9, {}], [Migration_test10, {}]]
|
292
257
|
Exodus.sort_and_run_migrations('up', migrations, 1, true).should == ["Migration_test9: #{{}}"]
|
293
258
|
end
|
294
259
|
end
|
@@ -2,6 +2,11 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Exodus::Migration do
|
4
4
|
|
5
|
+
before :all do
|
6
|
+
create_dynamic_class('Migration_test1')
|
7
|
+
end
|
8
|
+
|
9
|
+
|
5
10
|
describe "New Oject" do
|
6
11
|
subject { Exodus::Migration.new }
|
7
12
|
|
@@ -21,23 +26,27 @@ describe Exodus::Migration do
|
|
21
26
|
describe "#inherited" do
|
22
27
|
it "should add a new migrations when a new migration class is created" do
|
23
28
|
migration_size = subject.class.load_all([]).size.to_i
|
24
|
-
|
25
|
-
|
29
|
+
create_dynamic_class('Migration_test2')
|
30
|
+
|
26
31
|
subject.class.load_all([]).size.should == migration_size + 1
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
30
35
|
describe "#load_all" do
|
36
|
+
before :all do
|
37
|
+
create_dynamic_class('CompleteNewMigration')
|
38
|
+
end
|
39
|
+
|
31
40
|
it "should override migrations" do
|
32
41
|
first_migration = subject.class.load_all([]).first.first
|
33
|
-
|
42
|
+
override_migration = [first_migration, {:test_args => ['some', 'test', 'arguments']}]
|
43
|
+
subject.class.load_all([override_migration]).should include override_migration
|
34
44
|
end
|
35
45
|
|
36
46
|
it "should add a new migrations if the migration is not present" do
|
37
47
|
migration_classes = subject.class.load_all([]).map{|migration, args| migration}
|
38
|
-
class CompleteNewMigration < Exodus::Migration; end
|
39
|
-
|
40
48
|
reloaded_migration_classes = subject.class.load_all([[CompleteNewMigration.name]]).map{|migration, args| migration}
|
49
|
+
|
41
50
|
reloaded_migration_classes.should include CompleteNewMigration
|
42
51
|
end
|
43
52
|
end
|
@@ -45,80 +54,36 @@ describe Exodus::Migration do
|
|
45
54
|
|
46
55
|
describe "instance methods" do
|
47
56
|
before do
|
48
|
-
|
49
|
-
|
50
|
-
step("Creating new APIUser entity", 1) {UserSupport.create(:name =>'testor')}
|
51
|
-
end
|
52
|
-
|
53
|
-
def down
|
54
|
-
step("Droping APIUser entity", 0) do
|
55
|
-
user = UserSupport.first
|
56
|
-
user.destroy if user
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class RerunnableMigrationTest < Exodus::Migration
|
62
|
-
self.rerunnable_safe = true
|
63
|
-
|
64
|
-
def initialize(args = {})
|
65
|
-
super(args)
|
66
|
-
end
|
67
|
-
|
68
|
-
def up
|
69
|
-
step("Creating new APIUser entity", 1) {UserSupport.first_or_create(:name =>'testor')}
|
70
|
-
end
|
71
|
-
|
72
|
-
def down
|
73
|
-
step("Droping APIUser entity", 0) do
|
74
|
-
user = UserSupport.first
|
75
|
-
user.destroy if user
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
57
|
+
create_dynamic_class('Migration_test1')
|
58
|
+
create_dynamic_class('RerunnableMigrationTest')
|
79
59
|
end
|
80
60
|
|
81
61
|
subject { Migration_test1.first_or_create({}) }
|
82
62
|
|
83
63
|
describe "#run" do
|
84
|
-
|
85
|
-
Migration_test1
|
86
|
-
|
64
|
+
before :each do
|
65
|
+
reset_collections(Migration_test1, UserSupport)
|
66
|
+
end
|
87
67
|
|
68
|
+
it "should create a new APIUser when running it up" do
|
88
69
|
lambda{ subject.run('up')}.should change { UserSupport.count }.by(1)
|
89
|
-
subject
|
90
|
-
subject.status.current_status.should == 1
|
91
|
-
subject.status.direction.should == 'up'
|
92
|
-
subject.status.execution_time.should > 0
|
93
|
-
subject.status.last_succesful_completion.should
|
70
|
+
migration_should_be_up(subject)
|
94
71
|
subject.status.message.should == 'Creating new APIUser entity'
|
95
72
|
end
|
96
73
|
|
97
74
|
it "should delete an APIUser when running it down" do
|
98
|
-
Migration_test1.collection.drop
|
99
|
-
UserSupport.collection.drop
|
100
75
|
subject.run('up')
|
101
76
|
|
102
77
|
lambda{ subject.run('down')}.should change { UserSupport.count }.by(-1)
|
103
|
-
subject
|
104
|
-
subject.status.current_status.should == 0
|
105
|
-
subject.status.direction.should == 'down'
|
106
|
-
subject.status.execution_time.should > 0
|
78
|
+
migration_should_be_down(subject)
|
107
79
|
subject.status.message.should == 'Droping APIUser entity'
|
108
80
|
end
|
109
81
|
|
110
82
|
it "should run and rerun when the migration is rerunnable safe" do
|
111
|
-
RerunnableMigrationTest.collection.drop
|
112
|
-
UserSupport.collection.drop
|
113
|
-
|
114
83
|
migration = RerunnableMigrationTest.first_or_create({})
|
115
84
|
|
116
85
|
lambda{ migration.run('up')}.should change { UserSupport.count }.by(1)
|
117
|
-
migration
|
118
|
-
migration.status.current_status.should == 1
|
119
|
-
migration.status.direction.should == 'up'
|
120
|
-
migration.status.execution_time.should > 0
|
121
|
-
migration.status.last_succesful_completion.should
|
86
|
+
migration_should_be_up(migration)
|
122
87
|
migration.status.message.should == 'Creating new APIUser entity'
|
123
88
|
|
124
89
|
UserSupport.first.destroy
|
@@ -145,10 +110,11 @@ describe Exodus::Migration do
|
|
145
110
|
end
|
146
111
|
|
147
112
|
describe "#time_it" do
|
148
|
-
|
149
|
-
Migration_test1
|
150
|
-
|
113
|
+
before :all do
|
114
|
+
reset_collections(Migration_test1, UserSupport)
|
115
|
+
end
|
151
116
|
|
117
|
+
it "should execute a block and set the execution_time" do
|
152
118
|
lambda do
|
153
119
|
time = subject.send(:time_it) {UserSupport.create(:name => 'testor')}
|
154
120
|
end.should change { UserSupport.count }.by(1)
|
@@ -156,10 +122,11 @@ describe Exodus::Migration do
|
|
156
122
|
end
|
157
123
|
|
158
124
|
describe "#completed?" do
|
159
|
-
|
160
|
-
Migration_test1
|
161
|
-
|
125
|
+
before :all do
|
126
|
+
reset_collections(Migration_test1, UserSupport)
|
127
|
+
end
|
162
128
|
|
129
|
+
it "should be false when the job is not completed" do
|
163
130
|
subject.completed?('up').should be_false
|
164
131
|
subject.completed?('down').should be_false
|
165
132
|
end
|
@@ -180,10 +147,11 @@ describe Exodus::Migration do
|
|
180
147
|
end
|
181
148
|
|
182
149
|
describe "#is_runnable?" do
|
183
|
-
|
184
|
-
Migration_test1
|
185
|
-
|
150
|
+
before :all do
|
151
|
+
reset_collections(Migration_test1, UserSupport)
|
152
|
+
end
|
186
153
|
|
154
|
+
it "should only be runable up when it has never run before" do
|
187
155
|
subject.is_runnable?('up').should be_true
|
188
156
|
subject.is_runnable?('down').should be_false
|
189
157
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../lib/exodus'
|
2
|
+
require File.dirname(__FILE__) + '/support/test_class_definition'
|
3
|
+
include Exodus::Testing
|
4
|
+
|
2
5
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
3
6
|
mongo_uri = 'mongodb://exodus:exodus@dharma.mongohq.com:10048/Exodus-test'
|
4
7
|
local_uri = 'mongodb://localhost:27017/Exodus-test'
|
@@ -15,3 +18,42 @@ Exodus.configure do |config|
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
21
|
+
|
22
|
+
module Exodus::Testing
|
23
|
+
|
24
|
+
# Need to create dynamic classes in order to fully test the migration framework
|
25
|
+
def create_dynamic_class(class_name)
|
26
|
+
unless Object.const_defined?(class_name.to_sym)
|
27
|
+
Object.const_set(class_name, Class.new(Exodus::Migration))
|
28
|
+
class_name.constantize.class_eval(CLASS_CONTENT["@#{class_name}".to_sym].to_s)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def migration_should_be_up(migration)
|
33
|
+
migration.status.arguments.should be_empty
|
34
|
+
migration.status.current_status.should == 1
|
35
|
+
migration.status.direction.should == 'up'
|
36
|
+
migration.status.execution_time.should > 0
|
37
|
+
migration.status.last_succesful_completion.should_not be nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def migration_should_be_down(migration)
|
41
|
+
migration.status.arguments.should be_empty
|
42
|
+
migration.status.current_status.should == 0
|
43
|
+
migration.status.direction.should == 'down'
|
44
|
+
migration.status.execution_time.should > 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def reset_collections(*classes)
|
48
|
+
classes.each {|c| c.collection.drop}
|
49
|
+
end
|
50
|
+
|
51
|
+
def instanciate_and_run_up_migrations(*migrations_info)
|
52
|
+
migrations = migrations_info.map {|klass,arguments| Exodus.instanciate_migration(klass,arguments)}
|
53
|
+
Exodus.run_migrations('up', migrations)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_users_names
|
57
|
+
UserSupport.all.map(&:name)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Exodus::Testing
|
2
|
+
@Migration_test1 = <<CLASS_DEFINITION
|
3
|
+
def up
|
4
|
+
step("Creating new APIUser entity", 1) {UserSupport.create(:name =>'testor')}
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
step("Droping APIUser entity", 0) do
|
9
|
+
user = UserSupport.first
|
10
|
+
user.destroy if user
|
11
|
+
end
|
12
|
+
end
|
13
|
+
CLASS_DEFINITION
|
14
|
+
|
15
|
+
@RerunnableMigrationTest = <<CLASS_DEFINITION
|
16
|
+
self.rerunnable_safe = true
|
17
|
+
|
18
|
+
def initialize(args = {})
|
19
|
+
super(args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def up
|
23
|
+
step("Creating new APIUser entity", 1) {UserSupport.first_or_create(:name =>'testor')}
|
24
|
+
end
|
25
|
+
|
26
|
+
def down
|
27
|
+
step("Droping APIUser entity", 0) do
|
28
|
+
user = UserSupport.first
|
29
|
+
user.destroy if user
|
30
|
+
end
|
31
|
+
end
|
32
|
+
CLASS_DEFINITION
|
33
|
+
|
34
|
+
@Migration_test3 = "@migration_number = 3"
|
35
|
+
@Migration_test4 = "@migration_number = 4"
|
36
|
+
@Migration_test5 = "@migration_number = 5"
|
37
|
+
|
38
|
+
@Migration_test6 = <<CLASS_DEFINITION
|
39
|
+
def up
|
40
|
+
'valid'
|
41
|
+
end
|
42
|
+
CLASS_DEFINITION
|
43
|
+
|
44
|
+
@Migration_test7 = <<CLASS_DEFINITION
|
45
|
+
def up
|
46
|
+
raise StandardError, "the current migration failed"
|
47
|
+
end
|
48
|
+
CLASS_DEFINITION
|
49
|
+
|
50
|
+
@Migration_test8 = @Migration_test6
|
51
|
+
|
52
|
+
@Migration_test9 = <<CLASS_DEFINITION
|
53
|
+
@migration_number = 9
|
54
|
+
def up
|
55
|
+
UserSupport.create!({:name => "Thomas"})
|
56
|
+
end
|
57
|
+
CLASS_DEFINITION
|
58
|
+
|
59
|
+
@Migration_test10 = <<CLASS_DEFINITION
|
60
|
+
@migration_number = 10
|
61
|
+
def up
|
62
|
+
UserSupport.create!({:name => "Tester"})
|
63
|
+
end
|
64
|
+
CLASS_DEFINITION
|
65
|
+
|
66
|
+
CLASS_CONTENT = instance_variables.each_with_object({}) {|v, hash| hash[v.to_sym] = instance_variable_get(v)}
|
67
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exodus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Thomas Dmytryk
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongo_mapper
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bson_ext
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,7 +55,6 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -106,32 +97,32 @@ files:
|
|
106
97
|
- spec/exodus/migration_status_spec.rb
|
107
98
|
- spec/spec_helper.rb
|
108
99
|
- spec/support/config.yml
|
100
|
+
- spec/support/test_class_definition.rb
|
109
101
|
- spec/support/user_support.rb
|
110
102
|
- tasks/exodus.rake
|
111
103
|
homepage: https://github.com/ThomasAlxDmy/Exodus
|
112
104
|
licenses:
|
113
105
|
- MIT
|
106
|
+
metadata: {}
|
114
107
|
post_install_message:
|
115
108
|
rdoc_options: []
|
116
109
|
require_paths:
|
117
110
|
- lib
|
118
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
112
|
requirements:
|
121
113
|
- - ! '>='
|
122
114
|
- !ruby/object:Gem::Version
|
123
115
|
version: '0'
|
124
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
117
|
requirements:
|
127
118
|
- - ! '>='
|
128
119
|
- !ruby/object:Gem::Version
|
129
120
|
version: '0'
|
130
121
|
requirements: []
|
131
122
|
rubyforge_project:
|
132
|
-
rubygems_version:
|
123
|
+
rubygems_version: 2.2.2
|
133
124
|
signing_key:
|
134
|
-
specification_version:
|
125
|
+
specification_version: 4
|
135
126
|
summary: Exodus uses mongomapper to provide a complete migration framework
|
136
127
|
test_files:
|
137
128
|
- spec/exodus/exodus_spec.rb
|
@@ -139,4 +130,5 @@ test_files:
|
|
139
130
|
- spec/exodus/migration_status_spec.rb
|
140
131
|
- spec/spec_helper.rb
|
141
132
|
- spec/support/config.yml
|
133
|
+
- spec/support/test_class_definition.rb
|
142
134
|
- spec/support/user_support.rb
|