mongration 0.0.4.pre.beta → 0.0.5.pre.beta
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.
- checksums.yaml +4 -4
- data/lib/mongration.rb +11 -13
- data/lib/mongration/file.rb +8 -25
- data/lib/mongration/migrate.rb +7 -0
- data/lib/mongration/migrate/direction.rb +42 -0
- data/lib/mongration/migrate/down.rb +26 -0
- data/lib/mongration/migrate/move.rb +6 -0
- data/lib/mongration/migrate/up.rb +26 -0
- data/lib/mongration/version.rb +1 -1
- data/spec/integration/migrate_spec.rb +6 -2
- data/spec/integration/rollback_spec.rb +33 -5
- metadata +7 -5
- data/lib/mongration/migrate_all_up.rb +0 -20
- data/lib/mongration/migrate_down.rb +0 -20
- data/lib/mongration/migrate_up.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f71d2e5d3c7e355445796dab1273bae59e0391
|
4
|
+
data.tar.gz: b894bde28c6d7af02bbc3ccba842f135dfce8bc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8700887b66be864d7246255249c160bd4a128b0aae90de3eaa2ff50ee99f1ed8ec0946565bc7a1328bb8a32838ff8c8bb3fc815c104b8d0ab80c3265c2ff710c
|
7
|
+
data.tar.gz: 8c50e8a7405c20581a2fdcf6795d2b24208bc08916732c9c9a36188a52890bd5d811a445d20c8627ad63af51151d460186dc9e37f82d0e21c92817d6eb87a7c2
|
data/lib/mongration.rb
CHANGED
@@ -3,10 +3,6 @@ require 'rake'
|
|
3
3
|
|
4
4
|
require 'mongration/version'
|
5
5
|
require 'mongration/errors'
|
6
|
-
|
7
|
-
require 'mongration/file'
|
8
|
-
require 'mongration/migration'
|
9
|
-
|
10
6
|
require 'mongration/rake_tasks'
|
11
7
|
require 'mongration/configuration'
|
12
8
|
|
@@ -14,9 +10,9 @@ module Mongration
|
|
14
10
|
extend self
|
15
11
|
|
16
12
|
autoload :CreateMigration, 'mongration/create_migration'
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
13
|
+
autoload :File, 'mongration/file'
|
14
|
+
autoload :Migrate, 'mongration/migrate'
|
15
|
+
autoload :Migration, 'mongration/migration'
|
20
16
|
autoload :NullOutput, 'mongration/null_output'
|
21
17
|
autoload :Rollback, 'mongration/rollback'
|
22
18
|
autoload :Status, 'mongration/status'
|
@@ -33,13 +29,16 @@ module Mongration
|
|
33
29
|
|
34
30
|
case version
|
35
31
|
when nil
|
36
|
-
|
32
|
+
files = File.pending
|
33
|
+
Migrate::Up.new(files).perform
|
37
34
|
|
38
35
|
when pending
|
39
|
-
|
36
|
+
files = File.pending.select { |f| f.version <= version }
|
37
|
+
Migrate::Up.new(files).perform
|
40
38
|
|
41
39
|
when migrated
|
42
|
-
|
40
|
+
files = File.migrated.select { |f| f.version > version }.reverse
|
41
|
+
Migrate::Down.new(files).perform
|
43
42
|
|
44
43
|
else
|
45
44
|
out.puts("Invalid Version: #{version} does not exist.")
|
@@ -53,9 +52,8 @@ module Mongration
|
|
53
52
|
# @return [void]
|
54
53
|
#
|
55
54
|
def rollback(step = 1)
|
56
|
-
step
|
57
|
-
|
58
|
-
end
|
55
|
+
files = File.migrated.reverse.first(step)
|
56
|
+
Migrate::Down.new(files).perform
|
59
57
|
end
|
60
58
|
|
61
59
|
# Creates a migration with the given name
|
data/lib/mongration/file.rb
CHANGED
@@ -3,6 +3,9 @@ module Mongration
|
|
3
3
|
# @private
|
4
4
|
class File
|
5
5
|
include Comparable
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegators :klass, :up, :down
|
6
9
|
|
7
10
|
def self.all_file_names
|
8
11
|
Dir[::File.join(Mongration.configuration.dir, '*.rb')].map do |path|
|
@@ -40,27 +43,6 @@ module Mongration
|
|
40
43
|
@file_name = file_name
|
41
44
|
end
|
42
45
|
|
43
|
-
def up
|
44
|
-
Mongration.out.puts("#{version} #{class_name}: migrating")
|
45
|
-
|
46
|
-
load_file
|
47
|
-
klass.up
|
48
|
-
|
49
|
-
Migration.create_by_file_name(file_name)
|
50
|
-
Mongration.out.puts("#{version} #{class_name}: migrated")
|
51
|
-
true
|
52
|
-
|
53
|
-
rescue => e
|
54
|
-
Mongration.out.puts("#{e.class}: An error has occured, this and all later migrations cancelled")
|
55
|
-
false
|
56
|
-
end
|
57
|
-
|
58
|
-
def down
|
59
|
-
load_file
|
60
|
-
klass.down
|
61
|
-
Migration.destroy_by_file_name(file_name)
|
62
|
-
end
|
63
|
-
|
64
46
|
def name
|
65
47
|
underscored_name.gsub('_', ' ')
|
66
48
|
end
|
@@ -81,16 +63,17 @@ module Mongration
|
|
81
63
|
number <=> other.number
|
82
64
|
end
|
83
65
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
load(::File.join(Mongration.configuration.dir, @file_name))
|
66
|
+
alias_method :_load, :load
|
67
|
+
def load
|
68
|
+
_load(::File.join(Mongration.configuration.dir, @file_name))
|
88
69
|
end
|
89
70
|
|
90
71
|
def klass
|
91
72
|
class_name.constantize
|
92
73
|
end
|
93
74
|
|
75
|
+
private
|
76
|
+
|
94
77
|
def underscored_name
|
95
78
|
@file_name.chomp('.rb').gsub(/^\d+_/, '')
|
96
79
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Mongration
|
2
|
+
module Migrate
|
3
|
+
class Direction
|
4
|
+
|
5
|
+
def initialize(files)
|
6
|
+
@files = files
|
7
|
+
end
|
8
|
+
|
9
|
+
def perform
|
10
|
+
@files.each do |file|
|
11
|
+
file.load
|
12
|
+
|
13
|
+
summarize(description_for(file)) do
|
14
|
+
migrate(file)
|
15
|
+
end
|
16
|
+
|
17
|
+
persist(file)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def summarize(description)
|
24
|
+
Mongration.out.puts("#{description}: #{before_text}")
|
25
|
+
|
26
|
+
begin
|
27
|
+
yield
|
28
|
+
rescue => e
|
29
|
+
Mongration.out.puts("#{e.inspect}: An error has occured, this and all later migrations cancelled")
|
30
|
+
raise e
|
31
|
+
end
|
32
|
+
|
33
|
+
Mongration.out.puts("#{description}: #{after_text}")
|
34
|
+
Mongration.out.puts
|
35
|
+
end
|
36
|
+
|
37
|
+
def description_for(file)
|
38
|
+
"#{file.version} #{file.class_name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mongration
|
2
|
+
module Migrate
|
3
|
+
|
4
|
+
# @private
|
5
|
+
class Down < Direction
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def migrate(file)
|
10
|
+
file.down
|
11
|
+
end
|
12
|
+
|
13
|
+
def persist(file)
|
14
|
+
Migration.destroy_by_file_name(file.file_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def before_text
|
18
|
+
'reverting'
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_text
|
22
|
+
'reverted'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mongration
|
2
|
+
module Migrate
|
3
|
+
|
4
|
+
# @private
|
5
|
+
class Up < Direction
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def migrate(file)
|
10
|
+
file.up
|
11
|
+
end
|
12
|
+
|
13
|
+
def persist(file)
|
14
|
+
Migration.create_by_file_name(file.file_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def before_text
|
18
|
+
'migrating'
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_text
|
22
|
+
'migrated'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/mongration/version.rb
CHANGED
@@ -17,6 +17,7 @@ describe 'Mongration.migrate' do
|
|
17
17
|
it 'includes success message' do
|
18
18
|
expect(Mongration.out).to receive(:puts).with('001 AddFoo: migrating')
|
19
19
|
expect(Mongration.out).to receive(:puts).with('001 AddFoo: migrated')
|
20
|
+
allow(Mongration.out).to receive(:puts)
|
20
21
|
migrate
|
21
22
|
end
|
22
23
|
end
|
@@ -33,7 +34,9 @@ describe 'Mongration.migrate' do
|
|
33
34
|
)
|
34
35
|
end
|
35
36
|
|
36
|
-
let(:migrate)
|
37
|
+
let(:migrate) do
|
38
|
+
expect { Mongration.migrate }.to raise_error
|
39
|
+
end
|
37
40
|
|
38
41
|
it 'does not run later migrations' do
|
39
42
|
migrate
|
@@ -42,7 +45,8 @@ describe 'Mongration.migrate' do
|
|
42
45
|
|
43
46
|
it 'includes failed message' do
|
44
47
|
expect(Mongration.out).to receive(:puts).with('1 MigrationWithError: migrating')
|
45
|
-
expect(Mongration.out).to receive(:puts).with(
|
48
|
+
expect(Mongration.out).to receive(:puts).with('#<StandardError: StandardError>: An error has occured, this and all later migrations cancelled')
|
49
|
+
allow(Mongration.out).to receive(:puts)
|
46
50
|
migrate
|
47
51
|
end
|
48
52
|
end
|
@@ -2,12 +2,40 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Mongration.rollback' do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
context 'when the rollback is successful' do
|
6
|
+
before do
|
7
|
+
foo_create_migration
|
8
|
+
Mongration.migrate
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
it 'rollsback a migration' do
|
12
|
+
Mongration.rollback
|
13
|
+
expect(Foo.count).to eq(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'outputs messaging when starting and finishing the rollback' do
|
17
|
+
expect(Mongration.out).to receive(:puts).with('001 AddFoo: reverting')
|
18
|
+
expect(Mongration.out).to receive(:puts).with('001 AddFoo: reverted')
|
19
|
+
allow(Mongration.out).to receive(:puts)
|
20
|
+
Mongration.rollback
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when the rollback is not successful' do
|
25
|
+
before do
|
26
|
+
create_migration(
|
27
|
+
'1_migration_with_error',
|
28
|
+
down: 'raise StandardError'
|
29
|
+
)
|
30
|
+
Mongration.migrate
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'outputs messaging when rollback raises an error' do
|
34
|
+
expect(Mongration.out).to receive(:puts).with('1 MigrationWithError: reverting')
|
35
|
+
expect(Mongration.out).to receive(:puts).with('#<StandardError: StandardError>: An error has occured, this and all later migrations cancelled')
|
36
|
+
allow(Mongration.out).to receive(:puts)
|
37
|
+
expect { Mongration.rollback }.to raise_error
|
38
|
+
end
|
11
39
|
end
|
12
40
|
|
13
41
|
it 'can rollback twice' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5.pre.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Dalton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -133,9 +133,11 @@ files:
|
|
133
133
|
- lib/mongration/create_migration/migration_file_writer.rb
|
134
134
|
- lib/mongration/errors.rb
|
135
135
|
- lib/mongration/file.rb
|
136
|
-
- lib/mongration/
|
137
|
-
- lib/mongration/
|
138
|
-
- lib/mongration/
|
136
|
+
- lib/mongration/migrate.rb
|
137
|
+
- lib/mongration/migrate/direction.rb
|
138
|
+
- lib/mongration/migrate/down.rb
|
139
|
+
- lib/mongration/migrate/move.rb
|
140
|
+
- lib/mongration/migrate/up.rb
|
139
141
|
- lib/mongration/migration.rb
|
140
142
|
- lib/mongration/null_output.rb
|
141
143
|
- lib/mongration/rake_tasks.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Mongration
|
2
|
-
|
3
|
-
# @private
|
4
|
-
class MigrateDown
|
5
|
-
|
6
|
-
def initialize(version)
|
7
|
-
@version = version
|
8
|
-
end
|
9
|
-
|
10
|
-
def perform
|
11
|
-
files_to_rollback.each(&:down)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def files_to_rollback
|
17
|
-
File.migrated.select { |f| f.version > @version }.reverse
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Mongration
|
2
|
-
|
3
|
-
# @private
|
4
|
-
class MigrateUp
|
5
|
-
|
6
|
-
def initialize(version)
|
7
|
-
@version = version
|
8
|
-
end
|
9
|
-
|
10
|
-
def perform
|
11
|
-
files_to_migrate.take_while(&:up)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def files_to_migrate
|
17
|
-
File.pending.select { |f| f.version <= @version }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|