mongration 0.0.3.pre.beta → 0.0.4.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +11 -4
- data/README.md +9 -2
- data/Rakefile +5 -0
- data/lib/mongration.rb +81 -26
- data/lib/mongration/configuration.rb +27 -4
- data/lib/mongration/create_migration.rb +11 -16
- data/lib/mongration/create_migration/migration_file_writer.rb +43 -0
- data/lib/mongration/file.rb +52 -9
- data/lib/mongration/migrate_all_up.rb +20 -0
- data/lib/mongration/migrate_down.rb +20 -0
- data/lib/mongration/migrate_up.rb +20 -0
- data/lib/mongration/migration.rb +37 -0
- data/lib/mongration/null_output.rb +6 -0
- data/lib/mongration/rake_tasks.rb +40 -0
- data/lib/mongration/rollback.rb +5 -16
- data/lib/mongration/status.rb +27 -0
- data/lib/mongration/version.rb +1 -1
- data/lib/os_check.rb +7 -0
- data/spec/fixtures/integration.rb +23 -27
- data/spec/integration/{template_spec.rb → create_migration_spec.rb} +5 -1
- data/spec/integration/migrate_spec.rb +76 -0
- data/spec/integration/migrate_with_version_spec.rb +38 -0
- data/spec/integration/{mongration_spec.rb → rollback_spec.rb} +11 -36
- data/spec/integration/status_spec.rb +61 -0
- data/spec/integration/version_spec.rb +20 -0
- data/spec/spec_helper.rb +16 -4
- data/spec/unit/mongration/{data_store/mongoid/migration_spec.rb → migration_spec.rb} +9 -3
- data/spec/unit/mongration/rake_tasks_spec.rb +95 -0
- metadata +40 -35
- data/lib/mongration/data_store/in_memory/store.rb +0 -32
- data/lib/mongration/data_store/mongoid/migration.rb +0 -24
- data/lib/mongration/data_store/mongoid/store.rb +0 -53
- data/lib/mongration/migrate.rb +0 -52
- data/lib/mongration/migration_file_writer.rb +0 -40
- data/lib/mongration/null_migration.rb +0 -16
- data/lib/mongration/rake_task.rb +0 -18
- data/spec/support/store_interface.rb +0 -18
- data/spec/unit/mongration/data_store/in_memory/store_spec.rb +0 -10
- data/spec/unit/mongration/data_store/mongoid/store_spec.rb +0 -12
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mongration.status' do
|
4
|
+
|
5
|
+
context 'when there are no migrations' do
|
6
|
+
it 'returns an empty array' do
|
7
|
+
expect(Mongration.status).to eq([])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when there is a pending migration' do
|
12
|
+
before do
|
13
|
+
Mongration.create_migration('AddFoo')
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:file_status) { Mongration.status.first }
|
17
|
+
|
18
|
+
it "file's status is down" do
|
19
|
+
expect(file_status.status).to eq('down')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "file's migration id 001" do
|
23
|
+
expect(file_status.migration_id).to eq('001')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "file's migration name is 'add foo'" do
|
27
|
+
expect(file_status.migration_name).to eq('add foo')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when there is a migration that is run' do
|
32
|
+
before do
|
33
|
+
Mongration.create_migration('AddFoo')
|
34
|
+
Mongration.migrate
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:file_status) { Mongration.status.first }
|
38
|
+
|
39
|
+
it "file's status is up" do
|
40
|
+
expect(file_status.status).to eq('up')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "file's migration id 001" do
|
44
|
+
expect(file_status.migration_id).to eq('001')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "file's migration name is 'add foo'" do
|
48
|
+
expect(file_status.migration_name).to eq('add foo')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sorted in ascending order by id' do
|
53
|
+
Mongration.create_migration('AddFoo')
|
54
|
+
Mongration.create_migration('AddFoo2')
|
55
|
+
Mongration.migrate
|
56
|
+
Mongration.create_migration('AddBar')
|
57
|
+
Mongration.create_migration('AddBar2')
|
58
|
+
|
59
|
+
expect(Mongration.status.map(&:migration_id)).to eq(%w(001 002 003 004))
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mongration.version' do
|
4
|
+
|
5
|
+
context 'when there are no migrations' do
|
6
|
+
it 'version is 0' do
|
7
|
+
expect(Mongration.version).to eq('0')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when there are migrations' do
|
12
|
+
it 'version is equal to the number of non-empty migrations run' do
|
13
|
+
foo_create_migration
|
14
|
+
Mongration.migrate # non-empty migration
|
15
|
+
Mongration.migrate # empty migration
|
16
|
+
|
17
|
+
expect(Mongration.version).to eq('001')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,19 +5,27 @@ require 'coveralls'
|
|
5
5
|
Coveralls.wear!
|
6
6
|
|
7
7
|
require 'timecop'
|
8
|
+
Timecop.safe_mode = true
|
8
9
|
|
9
|
-
|
10
|
+
if RUBY_PLATFORM == 'java'
|
11
|
+
require 'ruby-debug'
|
12
|
+
else
|
13
|
+
if RUBY_VERSION.to_f >= 2.0
|
14
|
+
require 'byebug'
|
15
|
+
elsif RUBY_VERSION.to_f >= 1.9
|
16
|
+
require 'debugger'
|
17
|
+
end
|
18
|
+
end
|
10
19
|
|
11
20
|
require 'mongration'
|
12
21
|
Mongration.configure do |config|
|
13
|
-
config.
|
22
|
+
config.config_path = File.join('spec', 'config', 'mongoid.yml')
|
23
|
+
config.silent = true
|
14
24
|
end
|
15
25
|
|
16
26
|
Dir[File.join(Dir.pwd, 'spec', 'support', '*.rb')].each { |f| require f }
|
17
27
|
Dir[File.join(Dir.pwd, 'spec', 'fixtures', '*.rb')].each { |f| require f }
|
18
28
|
|
19
|
-
Timecop.safe_mode = true
|
20
|
-
|
21
29
|
RSpec.configure do |config|
|
22
30
|
|
23
31
|
# These two settings work together to allow you to limit a spec run
|
@@ -43,6 +51,8 @@ RSpec.configure do |config|
|
|
43
51
|
# --seed 1234
|
44
52
|
config.order = :random
|
45
53
|
|
54
|
+
config.include(IntegrationFixtures)
|
55
|
+
|
46
56
|
# Seed global randomization in this process using the `--seed` CLI option.
|
47
57
|
# Setting this allows you to use `--seed` to deterministically reproduce
|
48
58
|
# test failures related to randomization by passing the same `--seed` value
|
@@ -96,3 +106,5 @@ RSpec.configure do |config|
|
|
96
106
|
clean_migration_files # prevents tailor from looking in this directory
|
97
107
|
end
|
98
108
|
end
|
109
|
+
|
110
|
+
require 'rantly/rspec_extensions'
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Mongration::
|
3
|
+
describe Mongration::Migration do
|
4
4
|
|
5
|
-
let(:migration) { Mongration::
|
5
|
+
let(:migration) { Mongration::Migration.create! }
|
6
|
+
|
7
|
+
describe 'collection name' do
|
8
|
+
it 'is mongration_migrations'do
|
9
|
+
expect(Mongration::Migration.collection.name).to eq('mongration_migrations')
|
10
|
+
end
|
11
|
+
end
|
6
12
|
|
7
13
|
describe '#create' do
|
8
14
|
it 'sets created at timestamp' do
|
@@ -19,7 +25,7 @@ describe Mongration::DataStore::Mongoid do
|
|
19
25
|
end
|
20
26
|
|
21
27
|
it 'document is not returned in query' do
|
22
|
-
expect(Mongration::
|
28
|
+
expect(Mongration::Migration.count).to eq(0)
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'rake tasks' do
|
4
|
+
|
5
|
+
def run_task(task, args = nil)
|
6
|
+
Rake::Task.define_task(:environment)
|
7
|
+
Rake::Task[task].reenable
|
8
|
+
|
9
|
+
if args
|
10
|
+
Rake::Task[task].invoke(args)
|
11
|
+
else
|
12
|
+
Rake::Task[task].invoke
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'db:migrate' do
|
17
|
+
context 'when no VERSION is set' do
|
18
|
+
it 'recives migrate with no args' do
|
19
|
+
expect(Mongration).to receive(:migrate).with(nil)
|
20
|
+
run_task('db:migrate')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when a VERSION is set' do
|
25
|
+
it 'passes the version to migrate' do
|
26
|
+
allow(ENV).to receive(:[]).with('VERSION').and_return('001')
|
27
|
+
expect(Mongration).to receive(:migrate).with('001')
|
28
|
+
run_task('db:migrate')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'db:rollback' do
|
34
|
+
context 'when not passed a STEP' do
|
35
|
+
it 'receives rollback' do
|
36
|
+
expect(Mongration).to receive(:rollback)
|
37
|
+
run_task('db:rollback')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when passed a STEP of 2' do
|
42
|
+
it 'calls rollback with 2' do
|
43
|
+
allow(ENV).to receive(:[]).with('STEP').and_return('2')
|
44
|
+
expect(Mongration).to receive(:rollback).with(2)
|
45
|
+
run_task('db:rollback')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'db:version' do
|
51
|
+
it 'prints version' do
|
52
|
+
allow(Mongration).to receive(:version).and_return(1)
|
53
|
+
expect(Mongration.out).to receive(:puts).with('Current version: 1')
|
54
|
+
run_task('db:version')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'db:migrate:create' do
|
59
|
+
it 'receives create_migration' do
|
60
|
+
allow(Mongration.out).to receive(:puts)
|
61
|
+
expect(Mongration).to receive(:create_migration).with('add_foo').and_return('')
|
62
|
+
run_task('db:migrate:create', 'add_foo')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'prints file name' do
|
66
|
+
allow(Mongration).to receive(:create_migration).and_return('spec/db/migrate/001_add_foo.rb')
|
67
|
+
expect(Mongration.out).to receive(:puts).with('Created spec/db/migrate/001_add_foo.rb')
|
68
|
+
run_task('db:migrate:create', 'add_foo')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'db:migrate:status' do
|
73
|
+
it 'receives status' do
|
74
|
+
allow(Mongration.out).to receive(:puts)
|
75
|
+
expect(Mongration).to receive(:status).and_return([])
|
76
|
+
run_task('db:migrate:status')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'prints migration info' do
|
80
|
+
output = []
|
81
|
+
allow(Mongration.out).to receive(:puts) do |arg|
|
82
|
+
output << arg
|
83
|
+
end
|
84
|
+
|
85
|
+
status = Mongration::Status::FileStatus.new(:down, '001', 'add foo')
|
86
|
+
allow(Mongration).to receive(:status).and_return([status])
|
87
|
+
|
88
|
+
run_task('db:migrate:status')
|
89
|
+
|
90
|
+
expect(output[0]).to match(/Status.*Migration ID.*Migration Name/)
|
91
|
+
expect(output[1]).to match(/-+/)
|
92
|
+
expect(output[2]).to match(/down.*001.*add foo/)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
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.4.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-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.6'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -117,11 +117,11 @@ executables: []
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
-
- .gitignore
|
121
|
-
- .rspec
|
122
|
-
- .ruby-version
|
123
|
-
- .tailor
|
124
|
-
- .travis.yml
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".ruby-version"
|
123
|
+
- ".tailor"
|
124
|
+
- ".travis.yml"
|
125
125
|
- Gemfile
|
126
126
|
- Guardfile
|
127
127
|
- LICENSE.txt
|
@@ -130,30 +130,34 @@ files:
|
|
130
130
|
- lib/mongration.rb
|
131
131
|
- lib/mongration/configuration.rb
|
132
132
|
- lib/mongration/create_migration.rb
|
133
|
-
- lib/mongration/
|
134
|
-
- lib/mongration/data_store/mongoid/migration.rb
|
135
|
-
- lib/mongration/data_store/mongoid/store.rb
|
133
|
+
- lib/mongration/create_migration/migration_file_writer.rb
|
136
134
|
- lib/mongration/errors.rb
|
137
135
|
- lib/mongration/file.rb
|
138
|
-
- lib/mongration/
|
139
|
-
- lib/mongration/
|
140
|
-
- lib/mongration/
|
141
|
-
- lib/mongration/
|
136
|
+
- lib/mongration/migrate_all_up.rb
|
137
|
+
- lib/mongration/migrate_down.rb
|
138
|
+
- lib/mongration/migrate_up.rb
|
139
|
+
- lib/mongration/migration.rb
|
140
|
+
- lib/mongration/null_output.rb
|
141
|
+
- lib/mongration/rake_tasks.rb
|
142
142
|
- lib/mongration/rollback.rb
|
143
|
+
- lib/mongration/status.rb
|
143
144
|
- lib/mongration/version.rb
|
145
|
+
- lib/os_check.rb
|
144
146
|
- mongration.gemspec
|
145
147
|
- spec/.coveralls.yml
|
146
148
|
- spec/config/mongoid.yml
|
147
149
|
- spec/db/migrate/.gitkeep
|
148
150
|
- spec/fixtures/integration.rb
|
149
|
-
- spec/integration/
|
150
|
-
- spec/integration/
|
151
|
+
- spec/integration/create_migration_spec.rb
|
152
|
+
- spec/integration/migrate_spec.rb
|
153
|
+
- spec/integration/migrate_with_version_spec.rb
|
154
|
+
- spec/integration/rollback_spec.rb
|
155
|
+
- spec/integration/status_spec.rb
|
156
|
+
- spec/integration/version_spec.rb
|
151
157
|
- spec/spec_helper.rb
|
152
|
-
- spec/support/store_interface.rb
|
153
|
-
- spec/unit/mongration/data_store/in_memory/store_spec.rb
|
154
|
-
- spec/unit/mongration/data_store/mongoid/migration_spec.rb
|
155
|
-
- spec/unit/mongration/data_store/mongoid/store_spec.rb
|
156
158
|
- spec/unit/mongration/file_spec.rb
|
159
|
+
- spec/unit/mongration/migration_spec.rb
|
160
|
+
- spec/unit/mongration/rake_tasks_spec.rb
|
157
161
|
homepage: https://github.com/kcdragon/mongration
|
158
162
|
licenses:
|
159
163
|
- MIT
|
@@ -164,12 +168,12 @@ require_paths:
|
|
164
168
|
- lib
|
165
169
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
170
|
requirements:
|
167
|
-
- -
|
171
|
+
- - ">="
|
168
172
|
- !ruby/object:Gem::Version
|
169
173
|
version: '0'
|
170
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
175
|
requirements:
|
172
|
-
- -
|
176
|
+
- - ">"
|
173
177
|
- !ruby/object:Gem::Version
|
174
178
|
version: 1.3.1
|
175
179
|
requirements: []
|
@@ -183,12 +187,13 @@ test_files:
|
|
183
187
|
- spec/config/mongoid.yml
|
184
188
|
- spec/db/migrate/.gitkeep
|
185
189
|
- spec/fixtures/integration.rb
|
186
|
-
- spec/integration/
|
187
|
-
- spec/integration/
|
190
|
+
- spec/integration/create_migration_spec.rb
|
191
|
+
- spec/integration/migrate_spec.rb
|
192
|
+
- spec/integration/migrate_with_version_spec.rb
|
193
|
+
- spec/integration/rollback_spec.rb
|
194
|
+
- spec/integration/status_spec.rb
|
195
|
+
- spec/integration/version_spec.rb
|
188
196
|
- spec/spec_helper.rb
|
189
|
-
- spec/support/store_interface.rb
|
190
|
-
- spec/unit/mongration/data_store/in_memory/store_spec.rb
|
191
|
-
- spec/unit/mongration/data_store/mongoid/migration_spec.rb
|
192
|
-
- spec/unit/mongration/data_store/mongoid/store_spec.rb
|
193
197
|
- spec/unit/mongration/file_spec.rb
|
194
|
-
|
198
|
+
- spec/unit/mongration/migration_spec.rb
|
199
|
+
- spec/unit/mongration/rake_tasks_spec.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Mongration
|
2
|
-
module DataStore
|
3
|
-
module InMemory
|
4
|
-
class Store
|
5
|
-
|
6
|
-
class Migration < Struct.new(:version, :file_names)
|
7
|
-
attr_reader :destroyed
|
8
|
-
|
9
|
-
def save; end
|
10
|
-
|
11
|
-
def destroy
|
12
|
-
@destroyed = true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
@migrations = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def migrations
|
21
|
-
@migrations.reject(&:destroyed)
|
22
|
-
end
|
23
|
-
|
24
|
-
def build_migration(version, file_names)
|
25
|
-
migration = Migration.new(version, file_names)
|
26
|
-
@migrations << migration
|
27
|
-
migration
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|