mongration 0.0.2.1.pre.alpha → 0.0.3.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tailor +1 -1
- data/Gemfile +4 -0
- data/Guardfile +2 -1
- data/README.md +1 -1
- data/lib/mongration/create_migration.rb +48 -0
- data/lib/mongration/data_store/mongoid/migration.rb +11 -1
- data/lib/mongration/file.rb +2 -6
- data/lib/mongration/migrate.rb +52 -0
- data/lib/mongration/rake_task.rb +3 -3
- data/lib/mongration/{migration.rb → rollback.rb} +10 -8
- data/lib/mongration/version.rb +1 -1
- data/lib/mongration.rb +16 -50
- data/mongration.gemspec +1 -0
- data/spec/.coveralls.yml +1 -0
- data/spec/fixtures/integration.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/mongration/data_store/mongoid/migration_spec.rb +25 -0
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 884560384ec483986492aefbb946cda15136075b
|
4
|
+
data.tar.gz: c40a5ede37782728919819f17c133935e728e637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d0b356f35a8109db96d91ec16a55a2679d054fff3447436957572fcccc19576cae9b4a0cb304240c3a2592e1c81291716c2658127f5dee4426773f060698b7
|
7
|
+
data.tar.gz: ff3da3716f89e2676c5351c05bc3eaece5049ea2ac17f52a22b3c9e75a2999b5ca78fac7e1565703a6848be1f92b963dd525bcad42af05f383e2667acf628d2b
|
data/.tailor
CHANGED
@@ -123,7 +123,7 @@ Tailor.config do |config|
|
|
123
123
|
style.max_code_lines_in_class 300, level: :error
|
124
124
|
style.max_code_lines_in_method 30, level: :error
|
125
125
|
style.max_line_length 80, level: :off
|
126
|
-
style.spaces_after_comma 1, level: :
|
126
|
+
style.spaces_after_comma 1, level: :off
|
127
127
|
style.spaces_after_conditional 1, level: :error
|
128
128
|
style.spaces_after_lbrace 1, level: :error
|
129
129
|
style.spaces_after_lbracket 0, level: :error
|
data/Gemfile
CHANGED
@@ -2,7 +2,11 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
group :test do
|
4
4
|
gem 'guard-rspec', '4.3.1', require: false
|
5
|
+
gem 'rantly', github: 'hayeah/rantly'
|
5
6
|
end
|
6
7
|
|
8
|
+
#gem 'rspec-legacy_formatters'
|
9
|
+
#gem 'rspec-nc'
|
10
|
+
|
7
11
|
# Specify your gem's dependencies in mongration.gemspec
|
8
12
|
gemspec
|
data/Guardfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
guard :rspec, cmd: 'bundle exec rspec' do
|
2
2
|
watch(%r{^spec/.+_spec\.rb$})
|
3
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
|
3
|
+
#watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
|
4
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
4
5
|
watch('spec/spec_helper.rb') { "spec" }
|
5
6
|
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
6
7
|
watch(%r{^spec/fixtures/(.+)\.rb$}) { "spec" }
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Mongration [![Build Status](https://travis-ci.org/kcdragon/mongration.svg?branch=master)](https://travis-ci.org/kcdragon/mongration) [![Code Climate](https://codeclimate.com/github/kcdragon/mongration/badges/gpa.svg)](https://codeclimate.com/github/kcdragon/mongration)
|
1
|
+
# Mongration [![Build Status](https://travis-ci.org/kcdragon/mongration.svg?branch=master)](https://travis-ci.org/kcdragon/mongration) [![Code Climate](https://codeclimate.com/github/kcdragon/mongration/badges/gpa.svg)](https://codeclimate.com/github/kcdragon/mongration) [![Coverage Status](https://coveralls.io/repos/kcdragon/mongration/badge.png)](https://coveralls.io/r/kcdragon/mongration)
|
2
2
|
|
3
3
|
**ActiveRecord-like Migrations for Mongoid**
|
4
4
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Mongration
|
2
|
+
|
3
|
+
# @private
|
4
|
+
class CreateMigration
|
5
|
+
|
6
|
+
def self.perform(name, options = {})
|
7
|
+
new(name, options, Mongration.configuration).perform
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(name, options, configuration)
|
11
|
+
@name = name
|
12
|
+
@options = options
|
13
|
+
@configuration = configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform
|
17
|
+
MigrationFileWriter.write(
|
18
|
+
file_name,
|
19
|
+
{ dir: @configuration.dir }.merge(@options)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def file_name
|
26
|
+
"#{next_migration_number}_#{snakecase}.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def next_migration_number
|
30
|
+
if @configuration.timestamps?
|
31
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S').to_i
|
32
|
+
else
|
33
|
+
latest_file = Mongration::File.latest
|
34
|
+
|
35
|
+
number = if latest_file
|
36
|
+
latest_file.number + 1
|
37
|
+
else
|
38
|
+
1
|
39
|
+
end
|
40
|
+
'%.3d' % number
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def snakecase
|
45
|
+
@name.gsub(/([a-z])([A-Z0-9])/, '\1_\2').downcase
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -6,8 +6,18 @@ module Mongration
|
|
6
6
|
class Migration
|
7
7
|
include ::Mongoid::Document
|
8
8
|
|
9
|
-
field :version,
|
9
|
+
field :version, type: Integer
|
10
10
|
field :file_names, type: Array
|
11
|
+
|
12
|
+
field :created_at, type: Time, default: -> { Time.now }
|
13
|
+
field :deleted_at, type: Time
|
14
|
+
|
15
|
+
default_scope -> { where(deleted_at: nil) }
|
16
|
+
|
17
|
+
def destroy(*)
|
18
|
+
self.deleted_at = Time.now
|
19
|
+
save!
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
13
23
|
end
|
data/lib/mongration/file.rb
CHANGED
@@ -5,7 +5,7 @@ module Mongration
|
|
5
5
|
include Comparable
|
6
6
|
|
7
7
|
def self.all
|
8
|
-
Dir[::File.join(Mongration.dir, '*.rb')].map do |path|
|
8
|
+
Dir[::File.join(Mongration.configuration.dir, '*.rb')].map do |path|
|
9
9
|
path.pathmap('%f')
|
10
10
|
end.map { |file_name| new(file_name) }
|
11
11
|
end
|
@@ -45,11 +45,7 @@ module Mongration
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def load_file
|
48
|
-
load(::File.join(Dir.pwd, dir, @file_name))
|
49
|
-
end
|
50
|
-
|
51
|
-
def dir
|
52
|
-
Mongration.dir
|
48
|
+
load(::File.join(Dir.pwd, Mongration.configuration.dir, @file_name))
|
53
49
|
end
|
54
50
|
|
55
51
|
def klass
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Mongration
|
2
|
+
|
3
|
+
# @private
|
4
|
+
class Migrate
|
5
|
+
|
6
|
+
def self.perform(version)
|
7
|
+
new(version, Mongration.configuration.data_store).perform
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(version, data_store)
|
11
|
+
@version = version
|
12
|
+
@data_store = data_store
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform
|
16
|
+
files_to_migrate.sort.each(&:up)
|
17
|
+
migration.save
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def files_to_migrate
|
23
|
+
migration.file_names.map do |file_name|
|
24
|
+
Mongration::File.new(file_name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def migration
|
29
|
+
@migration ||=
|
30
|
+
if file_names.present?
|
31
|
+
@data_store.build_migration(
|
32
|
+
@version,
|
33
|
+
file_names
|
34
|
+
)
|
35
|
+
else
|
36
|
+
NullMigration.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def file_names
|
41
|
+
all_file_names - migrated_file_names
|
42
|
+
end
|
43
|
+
|
44
|
+
def all_file_names
|
45
|
+
Mongration::File.all.map(&:file_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
def migrated_file_names
|
49
|
+
@data_store.migrations.flat_map(&:file_names)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/mongration/rake_task.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'rake'
|
2
2
|
|
3
3
|
namespace :db do
|
4
|
-
task :
|
4
|
+
task migrate: :environment do
|
5
5
|
Mongration.migrate
|
6
6
|
end
|
7
7
|
|
8
8
|
namespace :migrate do
|
9
|
-
task :
|
9
|
+
task rollback: :environment do
|
10
10
|
Mongration.rollback
|
11
11
|
end
|
12
12
|
|
13
|
-
task :create, [:name] do |t, args|
|
13
|
+
task :create, [:name] => [:environment] do |t, args|
|
14
14
|
name = args[:name]
|
15
15
|
Mongration.create_migration(name)
|
16
16
|
end
|
@@ -1,22 +1,24 @@
|
|
1
1
|
module Mongration
|
2
2
|
|
3
3
|
# @private
|
4
|
-
class
|
5
|
-
|
6
|
-
|
4
|
+
class Rollback
|
5
|
+
|
6
|
+
def self.perform(migration)
|
7
|
+
new(migration).perform
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
|
10
|
+
def initialize(migration)
|
11
|
+
@migration = migration
|
11
12
|
end
|
12
13
|
|
13
|
-
def
|
14
|
-
|
14
|
+
def perform
|
15
|
+
files_to_rollback.sort.reverse.each(&:down)
|
16
|
+
@migration.destroy
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
def
|
21
|
+
def files_to_rollback
|
20
22
|
@migration.file_names.map do |file_name|
|
21
23
|
Mongration::File.new(file_name)
|
22
24
|
end
|
data/lib/mongration/version.rb
CHANGED
data/lib/mongration.rb
CHANGED
@@ -3,11 +3,13 @@ require 'mongration/version'
|
|
3
3
|
require 'mongration/errors'
|
4
4
|
|
5
5
|
require 'mongration/configuration'
|
6
|
+
require 'mongration/create_migration'
|
6
7
|
require 'mongration/file'
|
7
|
-
require 'mongration/
|
8
|
+
require 'mongration/migrate'
|
8
9
|
require 'mongration/migration_file_writer'
|
9
10
|
require 'mongration/null_migration'
|
10
11
|
require 'mongration/rake_task'
|
12
|
+
require 'mongration/rollback'
|
11
13
|
|
12
14
|
require 'mongration/data_store/mongoid/store'
|
13
15
|
require 'mongration/data_store/in_memory/store'
|
@@ -16,72 +18,36 @@ module Mongration
|
|
16
18
|
extend self
|
17
19
|
|
18
20
|
def migrate
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
data_store.build_migration(
|
23
|
-
latest_migration.version + 1,
|
24
|
-
file_names
|
25
|
-
)
|
26
|
-
else
|
27
|
-
NullMigration.new
|
28
|
-
end
|
29
|
-
|
30
|
-
Migration.new(migration).up
|
31
|
-
migration.save
|
21
|
+
Migrate.perform(
|
22
|
+
latest_migration.version + 1
|
23
|
+
)
|
32
24
|
end
|
33
25
|
|
34
26
|
def rollback
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
Rollback.perform(
|
28
|
+
latest_migration
|
29
|
+
)
|
38
30
|
end
|
39
31
|
|
40
32
|
def create_migration(name, options = {})
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
CreateMigration.perform(
|
34
|
+
name,
|
35
|
+
options
|
36
|
+
)
|
44
37
|
end
|
45
38
|
|
46
39
|
def configure
|
47
40
|
yield configuration if block_given?
|
48
41
|
end
|
49
42
|
|
50
|
-
private
|
51
|
-
|
52
|
-
def next_migration_number
|
53
|
-
if timestamps?
|
54
|
-
Time.now.utc.strftime('%Y%m%d%H%M%S').to_i
|
55
|
-
else
|
56
|
-
latest_file = Mongration::File.latest
|
57
|
-
|
58
|
-
number = if latest_file
|
59
|
-
latest_file.number + 1
|
60
|
-
else
|
61
|
-
1
|
62
|
-
end
|
63
|
-
'%.3d' % number
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def latest_migration
|
68
|
-
data_store.migrations.max_by(&:version) || NullMigration.new
|
69
|
-
end
|
70
|
-
|
71
43
|
def configuration
|
72
44
|
@configuration ||= Configuration.new
|
73
45
|
end
|
74
46
|
|
75
|
-
|
76
|
-
if configuration.respond_to?(method, *args)
|
77
|
-
configuration.send(method, *args)
|
78
|
-
else
|
79
|
-
super
|
80
|
-
end
|
81
|
-
end
|
47
|
+
private
|
82
48
|
|
83
|
-
def
|
84
|
-
|
49
|
+
def latest_migration
|
50
|
+
configuration.data_store.migrations.max_by(&:version) || NullMigration.new
|
85
51
|
end
|
86
52
|
end
|
87
53
|
|
data/mongration.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "rake"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "coveralls", "= 0.7.0"
|
25
26
|
spec.add_development_dependency "rspec", "= 3.0"
|
26
27
|
spec.add_development_dependency "tailor", "= 1.4.0"
|
27
28
|
spec.add_development_dependency "timecop", "= 0.7.1"
|
data/spec/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: gu8IfCgZJvGW4RSqxnNSxtZHYE82zikmS
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
|
4
7
|
require 'timecop'
|
5
8
|
|
9
|
+
require 'rantly/rspec_extensions'
|
10
|
+
|
6
11
|
require 'mongration'
|
7
12
|
Mongration.configure do |config|
|
8
13
|
config.data_store = Mongration::DataStore::Mongoid::Store.new(config_path: File.join('spec', 'config', 'mongoid.yml'))
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongration::DataStore::Mongoid do
|
4
|
+
|
5
|
+
let(:migration) { Mongration::DataStore::Mongoid::Migration.create! }
|
6
|
+
|
7
|
+
describe '#create' do
|
8
|
+
it 'sets created at timestamp' do
|
9
|
+
expect(migration.created_at).to be_present
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#destroy' do
|
14
|
+
before { migration.destroy }
|
15
|
+
|
16
|
+
it 'sets deleted at field' do
|
17
|
+
migration.reload
|
18
|
+
expect(migration.deleted_at).to be_present
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'document is not returned in query' do
|
22
|
+
expect(Mongration::DataStore::Mongoid::Migration.count).to eq(0)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
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.3.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-08-
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,17 +129,20 @@ files:
|
|
115
129
|
- Rakefile
|
116
130
|
- lib/mongration.rb
|
117
131
|
- lib/mongration/configuration.rb
|
132
|
+
- lib/mongration/create_migration.rb
|
118
133
|
- lib/mongration/data_store/in_memory/store.rb
|
119
134
|
- lib/mongration/data_store/mongoid/migration.rb
|
120
135
|
- lib/mongration/data_store/mongoid/store.rb
|
121
136
|
- lib/mongration/errors.rb
|
122
137
|
- lib/mongration/file.rb
|
123
|
-
- lib/mongration/
|
138
|
+
- lib/mongration/migrate.rb
|
124
139
|
- lib/mongration/migration_file_writer.rb
|
125
140
|
- lib/mongration/null_migration.rb
|
126
141
|
- lib/mongration/rake_task.rb
|
142
|
+
- lib/mongration/rollback.rb
|
127
143
|
- lib/mongration/version.rb
|
128
144
|
- mongration.gemspec
|
145
|
+
- spec/.coveralls.yml
|
129
146
|
- spec/config/mongoid.yml
|
130
147
|
- spec/db/migrate/.gitkeep
|
131
148
|
- spec/fixtures/integration.rb
|
@@ -134,6 +151,7 @@ files:
|
|
134
151
|
- spec/spec_helper.rb
|
135
152
|
- spec/support/store_interface.rb
|
136
153
|
- spec/unit/mongration/data_store/in_memory/store_spec.rb
|
154
|
+
- spec/unit/mongration/data_store/mongoid/migration_spec.rb
|
137
155
|
- spec/unit/mongration/data_store/mongoid/store_spec.rb
|
138
156
|
- spec/unit/mongration/file_spec.rb
|
139
157
|
homepage: https://github.com/kcdragon/mongration
|
@@ -161,6 +179,7 @@ signing_key:
|
|
161
179
|
specification_version: 4
|
162
180
|
summary: ActiveRecord-like Migrations for Mongoid
|
163
181
|
test_files:
|
182
|
+
- spec/.coveralls.yml
|
164
183
|
- spec/config/mongoid.yml
|
165
184
|
- spec/db/migrate/.gitkeep
|
166
185
|
- spec/fixtures/integration.rb
|
@@ -169,6 +188,7 @@ test_files:
|
|
169
188
|
- spec/spec_helper.rb
|
170
189
|
- spec/support/store_interface.rb
|
171
190
|
- spec/unit/mongration/data_store/in_memory/store_spec.rb
|
191
|
+
- spec/unit/mongration/data_store/mongoid/migration_spec.rb
|
172
192
|
- spec/unit/mongration/data_store/mongoid/store_spec.rb
|
173
193
|
- spec/unit/mongration/file_spec.rb
|
174
194
|
has_rdoc:
|