mongoid_rails_migrations 1.1.0 → 1.4.0
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 +5 -5
- data/lib/mongoid_rails_migrations.rb +2 -6
- data/lib/mongoid_rails_migrations/active_record_ext/migrations.rb +76 -23
- data/lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake +17 -5
- data/lib/mongoid_rails_migrations/version.rb +2 -2
- data/mongoid_rails_migrations.gemspec +21 -25
- metadata +24 -35
- data/.gitignore +0 -6
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -137
- data/README.rdoc +0 -56
- data/Rakefile +0 -12
- data/test/config.rb +0 -9
- data/test/helper.rb +0 -34
- data/test/migration_test.rb +0 -141
- data/test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb +0 -9
- data/test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb +0 -9
- data/test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb +0 -9
- data/test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb +0 -9
- data/test/migrations/valid/20100513054656_add_baseline_survey_schema.rb +0 -10
- data/test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb +0 -9
- data/test/models/survey_schema.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42339e4043e1ab4647e09def69fbc4d2fc674486da3113a83d461696d50d1b0c
|
4
|
+
data.tar.gz: ec3472e01a1071ced5db4da967c6c6b1627a4d9219b8abda84b19871514766fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84b7956dcac388376845c973fd0c1744c396fa38bff504257c361bfdda9b6c00b618000f418fb2d20f0c6ffae9a3a1a6649d0ec9728c3639bef583252ad1f620
|
7
|
+
data.tar.gz: 54a713f8b7d3c3280e5b83a6233ffa8eecbef7254d20a55b08c705b85342511191fad0e9bd8fcf0162dd8e8ab3ff6b1fca296e58fbe9a779a436f06b1a18b61f
|
@@ -1,13 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'bundler/setup'
|
3
|
-
Bundler.require(:mongoid_rails_migrations)
|
4
2
|
|
5
|
-
|
6
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
7
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
require 'mongoid'
|
8
4
|
|
9
5
|
require 'mongoid_rails_migrations/version'
|
10
6
|
require 'mongoid_rails_migrations/models/data_migration'
|
11
7
|
require 'mongoid_rails_migrations/mongoid_ext/mongoid'
|
12
8
|
require 'mongoid_rails_migrations/mongoid_ext/railtie'
|
13
|
-
require 'mongoid_rails_migrations/active_record_ext/migrations'
|
9
|
+
require 'mongoid_rails_migrations/active_record_ext/migrations'
|
@@ -31,14 +31,14 @@ module Mongoid #:nodoc
|
|
31
31
|
|
32
32
|
# Data migrations can manage the modification of data. It's a solution to the common problem of modifying
|
33
33
|
# data between code revisions within a document oriented database.
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# Example of simple migration for a system dependency:
|
36
|
-
#
|
36
|
+
#
|
37
37
|
# class AddBaselineSurveySchema < Mongoid::Migration
|
38
38
|
# def self.up
|
39
39
|
# SurveySchema.create(:label => 'Baseline Survey')
|
40
40
|
# end
|
41
|
-
#
|
41
|
+
#
|
42
42
|
# def self.down
|
43
43
|
# SurveySchema.where(:label => 'Baseline Survey').first.destroy
|
44
44
|
# end
|
@@ -61,7 +61,7 @@ module Mongoid #:nodoc
|
|
61
61
|
#
|
62
62
|
class Migration
|
63
63
|
@@verbose = true
|
64
|
-
cattr_accessor :verbose
|
64
|
+
cattr_accessor :verbose, :after_migrate, :buffer_output
|
65
65
|
|
66
66
|
class << self
|
67
67
|
def up_with_benchmarks #:nodoc:
|
@@ -89,6 +89,12 @@ module Mongoid #:nodoc
|
|
89
89
|
when :down then announce "reverted (%.4fs)" % time.real; write
|
90
90
|
end
|
91
91
|
|
92
|
+
begin
|
93
|
+
@@after_migrate.call(@@buffer_output, name, direction, false) if @@after_migrate
|
94
|
+
@@buffer_output = nil
|
95
|
+
rescue => e
|
96
|
+
say("Error in after_migrate hook: #{e}")
|
97
|
+
end
|
92
98
|
result
|
93
99
|
end
|
94
100
|
|
@@ -103,7 +109,8 @@ module Mongoid #:nodoc
|
|
103
109
|
|
104
110
|
case sym
|
105
111
|
when :up, :down
|
106
|
-
singleton_class.send(:
|
112
|
+
singleton_class.send(:alias_method, "#{sym}_without_benchmarks".to_sym, sym)
|
113
|
+
singleton_class.send(:alias_method, sym, "#{sym}_with_benchmarks".to_sym)
|
107
114
|
end
|
108
115
|
ensure
|
109
116
|
@ignore_new_methods = false
|
@@ -111,6 +118,8 @@ module Mongoid #:nodoc
|
|
111
118
|
end
|
112
119
|
|
113
120
|
def write(text="")
|
121
|
+
@@buffer_output ||= ""
|
122
|
+
@@buffer_output += text + "\n"
|
114
123
|
puts(text) if verbose
|
115
124
|
end
|
116
125
|
|
@@ -144,7 +153,11 @@ module Mongoid #:nodoc
|
|
144
153
|
|
145
154
|
def connection
|
146
155
|
# ActiveRecord::Base.connection
|
147
|
-
::Mongoid.
|
156
|
+
if ::Mongoid.respond_to?(:default_client)
|
157
|
+
::Mongoid.default_client
|
158
|
+
else
|
159
|
+
::Mongoid.default_session
|
160
|
+
end
|
148
161
|
end
|
149
162
|
|
150
163
|
def method_missing(method, *arguments, &block)
|
@@ -183,6 +196,8 @@ module Mongoid #:nodoc
|
|
183
196
|
|
184
197
|
class Migrator#:nodoc:
|
185
198
|
class << self
|
199
|
+
attr_writer :migrations_path
|
200
|
+
|
186
201
|
def migrate(migrations_path, target_version = nil)
|
187
202
|
case
|
188
203
|
when target_version.nil? then up(migrations_path, target_version)
|
@@ -191,10 +206,21 @@ module Mongoid #:nodoc
|
|
191
206
|
end
|
192
207
|
end
|
193
208
|
|
209
|
+
def status(migrations_path)
|
210
|
+
new(:up, migrations_path).status
|
211
|
+
end
|
212
|
+
|
194
213
|
def rollback(migrations_path, steps=1)
|
195
214
|
move(:down, migrations_path, steps)
|
196
215
|
end
|
197
216
|
|
217
|
+
def rollback_to(migrations_path, target_version)
|
218
|
+
all_versions = get_all_versions
|
219
|
+
rollback_to = all_versions.index(target_version.to_i) + 1
|
220
|
+
rollback_steps = all_versions.size - rollback_to
|
221
|
+
rollback migrations_path, rollback_steps
|
222
|
+
end
|
223
|
+
|
198
224
|
def forward(migrations_path, steps=1)
|
199
225
|
move(:up, migrations_path, steps)
|
200
226
|
end
|
@@ -212,7 +238,7 @@ module Mongoid #:nodoc
|
|
212
238
|
end
|
213
239
|
|
214
240
|
def migrations_path
|
215
|
-
'db/migrate'
|
241
|
+
@migrations_path ||= ['db/migrate']
|
216
242
|
end
|
217
243
|
|
218
244
|
# def schema_migrations_table_name
|
@@ -223,7 +249,7 @@ module Mongoid #:nodoc
|
|
223
249
|
def get_all_versions
|
224
250
|
# table = Arel::Table.new(schema_migrations_table_name)
|
225
251
|
# Base.connection.select_values(table.project(table['version']).to_sql).map(&:to_i).sort
|
226
|
-
DataMigration.all.map {|datamigration| datamigration.version.to_i }.sort
|
252
|
+
DataMigration.all.map { |datamigration| datamigration.version.to_i }.sort
|
227
253
|
end
|
228
254
|
|
229
255
|
def current_version
|
@@ -280,19 +306,7 @@ module Mongoid #:nodoc
|
|
280
306
|
end
|
281
307
|
|
282
308
|
def migrate
|
283
|
-
|
284
|
-
target = migrations.detect { |m| m.version == @target_version }
|
285
|
-
|
286
|
-
if target.nil? && !@target_version.nil? && @target_version > 0
|
287
|
-
raise UnknownMigrationVersionError.new(@target_version)
|
288
|
-
end
|
289
|
-
|
290
|
-
start = up? ? 0 : (migrations.index(current) || 0)
|
291
|
-
finish = migrations.index(target) || migrations.size - 1
|
292
|
-
runnable = migrations[start..finish]
|
293
|
-
|
294
|
-
# skip the last migration if we're headed down, but not ALL the way down
|
295
|
-
runnable.pop if down? && !target.nil?
|
309
|
+
runnable = runnable_migrations
|
296
310
|
|
297
311
|
runnable.each do |migration|
|
298
312
|
Rails.logger.info "Migrating to #{migration.name} (#{migration.version})" if Rails.logger
|
@@ -319,14 +333,35 @@ module Mongoid #:nodoc
|
|
319
333
|
migration.migrate(@direction)
|
320
334
|
record_version_state_after_migrating(migration.version)
|
321
335
|
rescue => e
|
336
|
+
output = Migration.buffer_output + "An error has occurred, #{migration.version} and all later migrations canceled:\n\n#{e}\n#{e.backtrace.join("\n")}"
|
337
|
+
begin
|
338
|
+
Migration.after_migrate.call(output, migration.name, @direction, true) if Migration.after_migrate
|
339
|
+
Migration.buffer_output = nil
|
340
|
+
rescue => error
|
341
|
+
puts("Error in after_migrate hook: #{error}")
|
342
|
+
end
|
322
343
|
raise StandardError, "An error has occurred, #{migration.version} and all later migrations canceled:\n\n#{e}", e.backtrace
|
323
344
|
end
|
324
345
|
end
|
325
346
|
end
|
326
347
|
|
348
|
+
def status
|
349
|
+
database_name = Migration.connection.options[:database]
|
350
|
+
puts "\ndatabase: #{database_name}\n\n"
|
351
|
+
puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
|
352
|
+
puts "-" * 50
|
353
|
+
up_migrations = migrated.to_set
|
354
|
+
migrations.each do |migration|
|
355
|
+
status = up_migrations.include?(migration.version.to_i) ? 'up' : 'down'
|
356
|
+
puts "#{status.center(8)} #{migration.version.to_s.ljust(14)} #{migration.name}"
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
327
360
|
def migrations
|
328
361
|
@migrations ||= begin
|
329
|
-
files =
|
362
|
+
files = Array(@migrations_path).inject([]) do |files, path|
|
363
|
+
files += Dir["#{path}/[0-9]*_*.rb"]
|
364
|
+
end
|
330
365
|
|
331
366
|
migrations = files.inject([]) do |klasses, file|
|
332
367
|
version, name = file.scan(/([0-9]+)_([_a-z0-9]*).rb/).first
|
@@ -359,6 +394,24 @@ module Mongoid #:nodoc
|
|
359
394
|
migrations.reject { |m| already_migrated.include?(m.version.to_i) }
|
360
395
|
end
|
361
396
|
|
397
|
+
def runnable_migrations
|
398
|
+
current = migrations.detect { |m| m.version == current_version }
|
399
|
+
target = migrations.detect { |m| m.version == @target_version }
|
400
|
+
|
401
|
+
if target.nil? && !@target_version.nil? && @target_version > 0
|
402
|
+
raise UnknownMigrationVersionError.new(@target_version)
|
403
|
+
end
|
404
|
+
|
405
|
+
start = up? ? 0 : (migrations.index(current) || 0)
|
406
|
+
finish = migrations.index(target) || migrations.size - 1
|
407
|
+
runnable = migrations[start..finish]
|
408
|
+
|
409
|
+
# skip the last migration if we're headed down, but not ALL the way down
|
410
|
+
runnable.pop if down? && !target.nil?
|
411
|
+
|
412
|
+
runnable
|
413
|
+
end
|
414
|
+
|
362
415
|
def migrated
|
363
416
|
@migrated_versions ||= self.class.get_all_versions
|
364
417
|
end
|
@@ -402,4 +455,4 @@ module Mongoid #:nodoc
|
|
402
455
|
block.call
|
403
456
|
end
|
404
457
|
end
|
405
|
-
end
|
458
|
+
end
|
@@ -39,7 +39,7 @@ namespace :db do
|
|
39
39
|
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
40
40
|
task :migrate => :environment do
|
41
41
|
Mongoid::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
42
|
-
Mongoid::Migrator.migrate(
|
42
|
+
Mongoid::Migrator.migrate(Mongoid::Migrator.migrations_path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
43
43
|
end
|
44
44
|
|
45
45
|
namespace :migrate do
|
@@ -62,21 +62,33 @@ namespace :db do
|
|
62
62
|
task :up => :environment do
|
63
63
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
64
64
|
raise "VERSION is required" unless version
|
65
|
-
Mongoid::Migrator.run(:up,
|
65
|
+
Mongoid::Migrator.run(:up, Mongoid::Migrator.migrations_path, version)
|
66
66
|
end
|
67
67
|
|
68
68
|
desc 'Runs the "down" for a given migration VERSION.'
|
69
69
|
task :down => :environment do
|
70
70
|
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
71
71
|
raise "VERSION is required" unless version
|
72
|
-
Mongoid::Migrator.run(:down,
|
72
|
+
Mongoid::Migrator.run(:down, Mongoid::Migrator.migrations_path, version)
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'Display status of migrations'
|
76
|
+
task :status => :environment do
|
77
|
+
Mongoid::Migrator.status(Mongoid::Migrator.migrations_path)
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
76
81
|
desc 'Rolls the database back to the previous migration. Specify the number of steps with STEP=n'
|
77
82
|
task :rollback => :environment do
|
78
83
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
79
|
-
Mongoid::Migrator.rollback(
|
84
|
+
Mongoid::Migrator.rollback(Mongoid::Migrator.migrations_path, step)
|
85
|
+
end
|
86
|
+
|
87
|
+
desc 'Rolls the database back to the specified VERSION'
|
88
|
+
task :rollback_to => :environment do
|
89
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
90
|
+
raise "VERSION is required" unless version
|
91
|
+
Mongoid::Migrator.rollback_to(Mongoid::Migrator.migrations_path, version)
|
80
92
|
end
|
81
93
|
|
82
94
|
namespace :schema do
|
@@ -90,4 +102,4 @@ namespace :db do
|
|
90
102
|
# Stub out for MongoDB
|
91
103
|
end
|
92
104
|
end
|
93
|
-
end
|
105
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module MongoidRailsMigrations #:nodoc:
|
2
|
-
VERSION = '1.
|
3
|
-
end
|
2
|
+
VERSION = '1.4.0'
|
3
|
+
end
|
@@ -1,32 +1,28 @@
|
|
1
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'mongoid_rails_migrations/version'
|
2
4
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
s.license = 'MIT'
|
9
|
-
s.description = 'Migrations for the migrator.'
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mongoid_rails_migrations'
|
7
|
+
spec.version = MongoidRailsMigrations::VERSION
|
8
|
+
spec.authors = ['Alan Da Costa']
|
9
|
+
spec.email = ['alandacosta@gmail.com']
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
spec.summary = 'Data migrations for Mongoid.'
|
12
|
+
spec.description = 'Data migrations for Mongoid in Active Record style, minus column input.'
|
13
|
+
spec.homepage = 'http://github.com/adacosta/mongoid_rails_migrations'
|
14
|
+
spec.license = 'MIT'
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
s.date = %q{2015-01-01}
|
17
|
-
s.homepage = 'http://github.com/adacosta/mongoid_rails_migrations'
|
18
|
-
|
19
|
-
s.require_paths = ['lib']
|
20
|
-
s.files = Dir['.gitignore', 'Gemfile', 'Gemfile.lock', 'Rakefile', 'README.rdoc', 'mongoid_rails_migrations.gemspec', 'lib/**/*']
|
21
|
-
s.test_files = Dir['test/**/*']
|
22
|
-
s.has_rdoc = false
|
16
|
+
spec.files = Dir['README.rdoc', 'mongoid_rails_migrations.gemspec', 'lib/**/*']
|
17
|
+
spec.require_paths = ['lib']
|
23
18
|
|
24
19
|
rails_version = '>= 4.2.0'
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
spec.add_runtime_dependency('bundler', '>= 1.0.0')
|
22
|
+
spec.add_runtime_dependency('mongoid', '>= 4.0.0')
|
23
|
+
spec.add_runtime_dependency('rails', rails_version)
|
24
|
+
spec.add_runtime_dependency('railties', rails_version)
|
25
|
+
spec.add_runtime_dependency('activesupport', rails_version)
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'minitest'
|
32
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_rails_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Da Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,17 +94,27 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
|
98
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Data migrations for Mongoid in Active Record style, minus column input.
|
112
|
+
email:
|
113
|
+
- alandacosta@gmail.com
|
99
114
|
executables: []
|
100
115
|
extensions: []
|
101
116
|
extra_rdoc_files: []
|
102
117
|
files:
|
103
|
-
- ".gitignore"
|
104
|
-
- Gemfile
|
105
|
-
- Gemfile.lock
|
106
|
-
- README.rdoc
|
107
|
-
- Rakefile
|
108
118
|
- lib/mongoid_rails_migrations.rb
|
109
119
|
- lib/mongoid_rails_migrations/active_record_ext/migrations.rb
|
110
120
|
- lib/mongoid_rails_migrations/models/data_migration.rb
|
@@ -116,16 +126,6 @@ files:
|
|
116
126
|
- lib/rails/generators/mongoid/migration/templates/migration.rb
|
117
127
|
- lib/rails/generators/mongoid/mongoid_generator.rb
|
118
128
|
- mongoid_rails_migrations.gemspec
|
119
|
-
- test/config.rb
|
120
|
-
- test/helper.rb
|
121
|
-
- test/migration_test.rb
|
122
|
-
- test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb
|
123
|
-
- test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb
|
124
|
-
- test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb
|
125
|
-
- test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb
|
126
|
-
- test/migrations/valid/20100513054656_add_baseline_survey_schema.rb
|
127
|
-
- test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb
|
128
|
-
- test/models/survey_schema.rb
|
129
129
|
homepage: http://github.com/adacosta/mongoid_rails_migrations
|
130
130
|
licenses:
|
131
131
|
- MIT
|
@@ -138,26 +138,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
138
|
requirements:
|
139
139
|
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
141
|
+
version: '0'
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
146
|
+
version: '0'
|
147
147
|
requirements: []
|
148
|
-
|
149
|
-
rubygems_version: 2.2.2
|
148
|
+
rubygems_version: 3.1.2
|
150
149
|
signing_key:
|
151
150
|
specification_version: 4
|
152
|
-
summary: Data migrations for Mongoid
|
153
|
-
test_files:
|
154
|
-
- test/config.rb
|
155
|
-
- test/helper.rb
|
156
|
-
- test/migration_test.rb
|
157
|
-
- test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb
|
158
|
-
- test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb
|
159
|
-
- test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb
|
160
|
-
- test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb
|
161
|
-
- test/migrations/valid/20100513054656_add_baseline_survey_schema.rb
|
162
|
-
- test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb
|
163
|
-
- test/models/survey_schema.rb
|
151
|
+
summary: Data migrations for Mongoid.
|
152
|
+
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mongoid_rails_migrations (1.1.0)
|
5
|
-
activesupport (>= 4.2.0)
|
6
|
-
bundler (>= 1.0.0)
|
7
|
-
mongoid (>= 4.0.0)
|
8
|
-
rails (>= 4.2.0)
|
9
|
-
railties (>= 4.2.0)
|
10
|
-
|
11
|
-
GEM
|
12
|
-
remote: http://rubygems.org/
|
13
|
-
specs:
|
14
|
-
actionmailer (4.2.0)
|
15
|
-
actionpack (= 4.2.0)
|
16
|
-
actionview (= 4.2.0)
|
17
|
-
activejob (= 4.2.0)
|
18
|
-
mail (~> 2.5, >= 2.5.4)
|
19
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
20
|
-
actionpack (4.2.0)
|
21
|
-
actionview (= 4.2.0)
|
22
|
-
activesupport (= 4.2.0)
|
23
|
-
rack (~> 1.6.0)
|
24
|
-
rack-test (~> 0.6.2)
|
25
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
26
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
27
|
-
actionview (4.2.0)
|
28
|
-
activesupport (= 4.2.0)
|
29
|
-
builder (~> 3.1)
|
30
|
-
erubis (~> 2.7.0)
|
31
|
-
rails-dom-testing (~> 1.0, >= 1.0.5)
|
32
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
33
|
-
activejob (4.2.0)
|
34
|
-
activesupport (= 4.2.0)
|
35
|
-
globalid (>= 0.3.0)
|
36
|
-
activemodel (4.2.0)
|
37
|
-
activesupport (= 4.2.0)
|
38
|
-
builder (~> 3.1)
|
39
|
-
activerecord (4.2.0)
|
40
|
-
activemodel (= 4.2.0)
|
41
|
-
activesupport (= 4.2.0)
|
42
|
-
arel (~> 6.0)
|
43
|
-
activesupport (4.2.0)
|
44
|
-
i18n (~> 0.7)
|
45
|
-
json (~> 1.7, >= 1.7.7)
|
46
|
-
minitest (~> 5.1)
|
47
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
48
|
-
tzinfo (~> 1.1)
|
49
|
-
arel (6.0.0)
|
50
|
-
bson (2.3.0)
|
51
|
-
builder (3.2.2)
|
52
|
-
coderay (1.1.0)
|
53
|
-
connection_pool (2.1.0)
|
54
|
-
erubis (2.7.0)
|
55
|
-
globalid (0.3.0)
|
56
|
-
activesupport (>= 4.1.0)
|
57
|
-
hike (1.2.3)
|
58
|
-
i18n (0.7.0)
|
59
|
-
json (1.8.1)
|
60
|
-
loofah (2.0.1)
|
61
|
-
nokogiri (>= 1.5.9)
|
62
|
-
mail (2.6.3)
|
63
|
-
mime-types (>= 1.16, < 3)
|
64
|
-
method_source (0.8.2)
|
65
|
-
mime-types (2.4.3)
|
66
|
-
mini_portile (0.6.2)
|
67
|
-
minitest (5.5.0)
|
68
|
-
mongoid (4.0.0)
|
69
|
-
activemodel (~> 4.0)
|
70
|
-
moped (~> 2.0.0)
|
71
|
-
origin (~> 2.1)
|
72
|
-
tzinfo (>= 0.3.37)
|
73
|
-
moped (2.0.2)
|
74
|
-
bson (~> 2.2)
|
75
|
-
connection_pool (~> 2.0)
|
76
|
-
optionable (~> 0.2.0)
|
77
|
-
multi_json (1.10.1)
|
78
|
-
nokogiri (1.6.5)
|
79
|
-
mini_portile (~> 0.6.0)
|
80
|
-
optionable (0.2.0)
|
81
|
-
origin (2.1.1)
|
82
|
-
pry (0.10.1)
|
83
|
-
coderay (~> 1.1.0)
|
84
|
-
method_source (~> 0.8.1)
|
85
|
-
slop (~> 3.4)
|
86
|
-
rack (1.6.0)
|
87
|
-
rack-test (0.6.2)
|
88
|
-
rack (>= 1.0)
|
89
|
-
rails (4.2.0)
|
90
|
-
actionmailer (= 4.2.0)
|
91
|
-
actionpack (= 4.2.0)
|
92
|
-
actionview (= 4.2.0)
|
93
|
-
activejob (= 4.2.0)
|
94
|
-
activemodel (= 4.2.0)
|
95
|
-
activerecord (= 4.2.0)
|
96
|
-
activesupport (= 4.2.0)
|
97
|
-
bundler (>= 1.3.0, < 2.0)
|
98
|
-
railties (= 4.2.0)
|
99
|
-
sprockets-rails
|
100
|
-
rails-deprecated_sanitizer (1.0.3)
|
101
|
-
activesupport (>= 4.2.0.alpha)
|
102
|
-
rails-dom-testing (1.0.5)
|
103
|
-
activesupport (>= 4.2.0.beta, < 5.0)
|
104
|
-
nokogiri (~> 1.6.0)
|
105
|
-
rails-deprecated_sanitizer (>= 1.0.1)
|
106
|
-
rails-html-sanitizer (1.0.1)
|
107
|
-
loofah (~> 2.0)
|
108
|
-
railties (4.2.0)
|
109
|
-
actionpack (= 4.2.0)
|
110
|
-
activesupport (= 4.2.0)
|
111
|
-
rake (>= 0.8.7)
|
112
|
-
thor (>= 0.18.1, < 2.0)
|
113
|
-
rake (10.4.2)
|
114
|
-
slop (3.6.0)
|
115
|
-
sprockets (2.12.3)
|
116
|
-
hike (~> 1.2)
|
117
|
-
multi_json (~> 1.0)
|
118
|
-
rack (~> 1.0)
|
119
|
-
tilt (~> 1.1, != 1.3.0)
|
120
|
-
sprockets-rails (2.2.2)
|
121
|
-
actionpack (>= 3.0)
|
122
|
-
activesupport (>= 3.0)
|
123
|
-
sprockets (>= 2.8, < 4.0)
|
124
|
-
thor (0.19.1)
|
125
|
-
thread_safe (0.3.4)
|
126
|
-
tilt (1.4.1)
|
127
|
-
tzinfo (1.2.2)
|
128
|
-
thread_safe (~> 0.1)
|
129
|
-
|
130
|
-
PLATFORMS
|
131
|
-
ruby
|
132
|
-
|
133
|
-
DEPENDENCIES
|
134
|
-
minitest
|
135
|
-
mongoid_rails_migrations!
|
136
|
-
pry
|
137
|
-
rake
|
data/README.rdoc
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
== RELEASE NOTES
|
2
|
-
* The most current release, 1.1.x, targets Mongoid >= 4.0.0 and Rails >= 4.2.0 .
|
3
|
-
* For Rails >= 3.2.0 and Mongoid >= 3.0.0, use version 1.0.0 .
|
4
|
-
* For Rails >= 3.0.0 (but < 3.2.0) and Mongoid >= 2.0.0, use version 0.0.14 .
|
5
|
-
|
6
|
-
== SYNOPSIS
|
7
|
-
* Data migrations for Mongoid.
|
8
|
-
|
9
|
-
== MIGRATE WHEN ...
|
10
|
-
* The migrating is good
|
11
|
-
|
12
|
-
== INSTALL
|
13
|
-
* gem install mongoid_rails_migrations
|
14
|
-
* In your Gemfile, include (after including mongoid):
|
15
|
-
gem "mongoid_rails_migrations", <version>
|
16
|
-
|
17
|
-
== FEATURES AND HOW TO USE
|
18
|
-
* generator:
|
19
|
-
* rails generate mongoid:migration your_migration_name_here
|
20
|
-
|
21
|
-
* migrations:
|
22
|
-
* db:migrate
|
23
|
-
* db:migrate:down
|
24
|
-
* db:migrate:up
|
25
|
-
* db:rollback
|
26
|
-
* db:migrate:redo
|
27
|
-
* db:migrate:reset
|
28
|
-
* db:reseed (handled by mongoid)
|
29
|
-
* db:version
|
30
|
-
|
31
|
-
== TESTING
|
32
|
-
```rake test:mongoid:migrations```
|
33
|
-
|
34
|
-
== CREDITS TO
|
35
|
-
* rails
|
36
|
-
* mongoid
|
37
|
-
* contributions from the community (git log)
|
38
|
-
|
39
|
-
Much of this gem simply modifies existing code from both projects.
|
40
|
-
With that out of the way, on to the license.
|
41
|
-
|
42
|
-
== LICENSE (MIT)
|
43
|
-
|
44
|
-
Copyright © 2013: Alan Da Costa
|
45
|
-
|
46
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
|
47
|
-
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
48
|
-
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
|
49
|
-
the following conditions:
|
50
|
-
|
51
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
52
|
-
|
53
|
-
The software is provided 'as is', without warranty of any kind, express or implied, including but not limited to the warranties of
|
54
|
-
merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any
|
55
|
-
claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
|
56
|
-
software or the use or other dealings in the software.
|
data/Rakefile
DELETED
data/test/config.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'mongoid_rails_migrations')
|
2
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'rails', 'generators', 'mongoid', 'mongoid_generator')
|
3
|
-
|
4
|
-
Mongoid.configure.connect_to('mongoid_test')
|
5
|
-
|
6
|
-
# require all models
|
7
|
-
Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].each { |file| require file }
|
8
|
-
|
9
|
-
MIGRATIONS_ROOT = File.join(File.dirname(__FILE__), 'migrations')
|
data/test/helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__))
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
Bundler.require(:test)
|
5
|
-
|
6
|
-
require 'mongoid'
|
7
|
-
require 'config'
|
8
|
-
require 'minitest/autorun'
|
9
|
-
require 'rake'
|
10
|
-
require 'rake/testtask'
|
11
|
-
require 'rdoc/task'
|
12
|
-
|
13
|
-
# leave out active_record, in favor of a monogo adapter
|
14
|
-
%w(
|
15
|
-
action_controller
|
16
|
-
action_mailer
|
17
|
-
active_resource
|
18
|
-
rails/test_unit
|
19
|
-
mongoid
|
20
|
-
).each do |framework|
|
21
|
-
begin
|
22
|
-
require "#{framework}/railtie"
|
23
|
-
rescue LoadError
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
ActiveSupport.test_order = :sorted if ActiveSupport.respond_to?(:test_order)
|
29
|
-
|
30
|
-
module TestMongoidRailsMigrations
|
31
|
-
class Application < Rails::Application; end
|
32
|
-
end
|
33
|
-
|
34
|
-
TestMongoidRailsMigrations::Application.load_tasks
|
data/test/migration_test.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class Mongoid::Migration
|
4
|
-
class <<self
|
5
|
-
attr_accessor :message_count
|
6
|
-
|
7
|
-
def puts(text="")
|
8
|
-
self.message_count ||= 0
|
9
|
-
self.message_count += 1
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Mongoid
|
15
|
-
class TestCase < ActiveSupport::TestCase #:nodoc:
|
16
|
-
|
17
|
-
def setup
|
18
|
-
Mongoid::Migration.verbose = true
|
19
|
-
# same as db:drop command in lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake
|
20
|
-
Mongoid.default_session.drop
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown; end
|
24
|
-
|
25
|
-
def test_drop_works
|
26
|
-
assert_equal 0, Mongoid::Migrator.current_version, "db:drop should take us down to version 0"
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_finds_migrations
|
30
|
-
assert Mongoid::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations.size == 2
|
31
|
-
assert_equal 2, Mongoid::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").pending_migrations.size
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_migrator_current_version
|
35
|
-
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 20100513054656)
|
36
|
-
assert_equal(20100513054656, Mongoid::Migrator.current_version)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_migrator
|
40
|
-
assert SurveySchema.first.nil?, "All SurveySchemas should be clear before migration run"
|
41
|
-
|
42
|
-
Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid")
|
43
|
-
|
44
|
-
assert_equal 20100513063902, Mongoid::Migrator.current_version
|
45
|
-
assert !SurveySchema.first.nil?
|
46
|
-
|
47
|
-
Mongoid::Migrator.down(MIGRATIONS_ROOT + "/valid")
|
48
|
-
assert_equal 0, Mongoid::Migrator.current_version
|
49
|
-
|
50
|
-
assert SurveySchema.create(:label => 'Questionable Survey')
|
51
|
-
assert_equal 1, SurveySchema.all.size
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_migrator_two_up_and_one_down
|
55
|
-
assert SurveySchema.where(:label => 'Baseline Survey').first.nil?
|
56
|
-
assert_equal 0, SurveySchema.all.size
|
57
|
-
|
58
|
-
Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid", 20100513054656)
|
59
|
-
|
60
|
-
assert !SurveySchema.where(:label => 'Baseline Survey').first.nil?
|
61
|
-
assert_equal 1, SurveySchema.all.size
|
62
|
-
|
63
|
-
assert SurveySchema.where(:label => 'Improvement Plan Survey').first.nil?
|
64
|
-
|
65
|
-
Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid", 20100513063902)
|
66
|
-
assert_equal 20100513063902, Mongoid::Migrator.current_version
|
67
|
-
|
68
|
-
assert !SurveySchema.where(:label => 'Improvement Plan Survey').first.nil?
|
69
|
-
assert_equal 2, SurveySchema.all.size
|
70
|
-
|
71
|
-
Mongoid::Migrator.down(MIGRATIONS_ROOT + "/valid", 20100513054656)
|
72
|
-
assert_equal 20100513054656, Mongoid::Migrator.current_version
|
73
|
-
|
74
|
-
assert SurveySchema.where(:label => 'Improvement Plan Survey').first.nil?
|
75
|
-
assert !SurveySchema.where(:label => 'Baseline Survey').first.nil?
|
76
|
-
assert_equal 1, SurveySchema.all.size
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_finds_pending_migrations
|
80
|
-
Mongoid::Migrator.up(MIGRATIONS_ROOT + "/valid", 20100513054656)
|
81
|
-
pending_migrations = Mongoid::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").pending_migrations
|
82
|
-
|
83
|
-
assert_equal 1, pending_migrations.size
|
84
|
-
assert_equal pending_migrations[0].version, 20100513063902
|
85
|
-
assert_equal pending_migrations[0].name, 'AddImprovementPlanSurveySchema'
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_migrator_rollback
|
89
|
-
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid")
|
90
|
-
assert_equal(20100513063902, Mongoid::Migrator.current_version)
|
91
|
-
|
92
|
-
Mongoid::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
93
|
-
assert_equal(20100513054656, Mongoid::Migrator.current_version)
|
94
|
-
|
95
|
-
Mongoid::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
|
96
|
-
assert_equal(0, Mongoid::Migrator.current_version)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_migrator_forward
|
100
|
-
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 20100513054656)
|
101
|
-
assert_equal(20100513054656, Mongoid::Migrator.current_version)
|
102
|
-
|
103
|
-
Mongoid::Migrator.forward(MIGRATIONS_ROOT + "/valid", 20100513063902)
|
104
|
-
assert_equal(20100513063902, Mongoid::Migrator.current_version)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_migrator_with_duplicate_names
|
108
|
-
assert_raise(Mongoid::DuplicateMigrationNameError) do
|
109
|
-
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate/names", nil)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_migrator_with_duplicate_versions
|
114
|
-
assert_raise(Mongoid::DuplicateMigrationVersionError) do
|
115
|
-
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate/versions", nil)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_migrator_with_missing_version_numbers
|
120
|
-
assert_raise(Mongoid::UnknownMigrationVersionError) do
|
121
|
-
Mongoid::Migrator.migrate(MIGRATIONS_ROOT + "/valid", 500)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_default_state_of_timestamped_migrations
|
126
|
-
assert Mongoid.configure.timestamped_migrations, "Mongoid.configure.timestamped_migrations should default to true"
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_timestamped_migrations_generates_non_sequential_next_number
|
130
|
-
next_number = Mongoid::Generators::Base.next_migration_number(MIGRATIONS_ROOT + "/valid")
|
131
|
-
assert_not_equal "20100513063903", next_number
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_turning_off_timestamped_migrations
|
135
|
-
Mongoid.configure.timestamped_migrations = false
|
136
|
-
next_number = Mongoid::Generators::Base.next_migration_number(MIGRATIONS_ROOT + "/valid")
|
137
|
-
assert_equal "20100513063903", next_number
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|