mongoid_rails_migrations 1.0.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8775f1eec59ab5b9b48253d924c225ef8f4a381e25e70b8666f1f5439a8db3d7
4
+ data.tar.gz: 896306d933de2c622e4ff3465801b300c16287a027edbb70c6881277c4643c41
5
+ SHA512:
6
+ metadata.gz: bf0e7d1b3827d1c2af5c1c5f564a84a038dc750f7d1834198e7bf9b7e9eba9c6e5d60924c56e799eb23a71c3c972c19bd6f3796a2196d38b6c6f35646990dc51
7
+ data.tar.gz: e4bad977cedcba39cc704c2ee23a765827a02834a6f45bbc65b52421a2b968f7fb174db82aeccd4b15e778c671a0232dfd65d21d185cb1348387470a04659eb4
@@ -1,13 +1,9 @@
1
1
  # encoding: utf-8
2
- require 'bundler/setup'
3
- Bundler.require(:mongoid_rails_migrations)
4
2
 
5
- # Add base to path incase not included as a gem
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
65
65
 
66
66
  class << self
67
67
  def up_with_benchmarks #:nodoc:
@@ -89,6 +89,11 @@ 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) if @@after_migrate
94
+ rescue => e
95
+ say("Error in after_migrate hook: #{e}")
96
+ end
92
97
  result
93
98
  end
94
99
 
@@ -103,7 +108,8 @@ module Mongoid #:nodoc
103
108
 
104
109
  case sym
105
110
  when :up, :down
106
- singleton_class.send(:alias_method_chain, sym, "benchmarks")
111
+ singleton_class.send(:alias_method, "#{sym}_without_benchmarks".to_sym, sym)
112
+ singleton_class.send(:alias_method, sym, "#{sym}_with_benchmarks".to_sym)
107
113
  end
108
114
  ensure
109
115
  @ignore_new_methods = false
@@ -111,6 +117,8 @@ module Mongoid #:nodoc
111
117
  end
112
118
 
113
119
  def write(text="")
120
+ @buffer_output ||= ""
121
+ @buffer_output += text + "\n"
114
122
  puts(text) if verbose
115
123
  end
116
124
 
@@ -144,7 +152,11 @@ module Mongoid #:nodoc
144
152
 
145
153
  def connection
146
154
  # ActiveRecord::Base.connection
147
- ::Mongoid.default_session
155
+ if ::Mongoid.respond_to?(:default_client)
156
+ ::Mongoid.default_client
157
+ else
158
+ ::Mongoid.default_session
159
+ end
148
160
  end
149
161
 
150
162
  def method_missing(method, *arguments, &block)
@@ -183,6 +195,8 @@ module Mongoid #:nodoc
183
195
 
184
196
  class Migrator#:nodoc:
185
197
  class << self
198
+ attr_writer :migrations_path
199
+
186
200
  def migrate(migrations_path, target_version = nil)
187
201
  case
188
202
  when target_version.nil? then up(migrations_path, target_version)
@@ -191,10 +205,21 @@ module Mongoid #:nodoc
191
205
  end
192
206
  end
193
207
 
208
+ def status(migrations_path)
209
+ new(:up, migrations_path).status
210
+ end
211
+
194
212
  def rollback(migrations_path, steps=1)
195
213
  move(:down, migrations_path, steps)
196
214
  end
197
215
 
216
+ def rollback_to(migrations_path, target_version)
217
+ all_versions = get_all_versions
218
+ rollback_to = all_versions.index(target_version.to_i) + 1
219
+ rollback_steps = all_versions.size - rollback_to
220
+ rollback migrations_path, rollback_steps
221
+ end
222
+
198
223
  def forward(migrations_path, steps=1)
199
224
  move(:up, migrations_path, steps)
200
225
  end
@@ -212,7 +237,7 @@ module Mongoid #:nodoc
212
237
  end
213
238
 
214
239
  def migrations_path
215
- 'db/migrate'
240
+ @migrations_path ||= ['db/migrate']
216
241
  end
217
242
 
218
243
  # def schema_migrations_table_name
@@ -223,7 +248,7 @@ module Mongoid #:nodoc
223
248
  def get_all_versions
224
249
  # table = Arel::Table.new(schema_migrations_table_name)
225
250
  # Base.connection.select_values(table.project(table['version']).to_sql).map(&:to_i).sort
226
- DataMigration.all.map {|datamigration| datamigration.version.to_i }.sort
251
+ DataMigration.all.map { |datamigration| datamigration.version.to_i }.sort
227
252
  end
228
253
 
229
254
  def current_version
@@ -280,19 +305,7 @@ module Mongoid #:nodoc
280
305
  end
281
306
 
282
307
  def migrate
283
- current = migrations.detect { |m| m.version == current_version }
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?
308
+ runnable = runnable_migrations
296
309
 
297
310
  runnable.each do |migration|
298
311
  Rails.logger.info "Migrating to #{migration.name} (#{migration.version})" if Rails.logger
@@ -324,9 +337,23 @@ module Mongoid #:nodoc
324
337
  end
325
338
  end
326
339
 
340
+ def status
341
+ database_name = Migration.connection.options[:database]
342
+ puts "\ndatabase: #{database_name}\n\n"
343
+ puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name"
344
+ puts "-" * 50
345
+ up_migrations = migrated.to_set
346
+ migrations.each do |migration|
347
+ status = up_migrations.include?(migration.version.to_i) ? 'up' : 'down'
348
+ puts "#{status.center(8)} #{migration.version.to_s.ljust(14)} #{migration.name}"
349
+ end
350
+ end
351
+
327
352
  def migrations
328
353
  @migrations ||= begin
329
- files = Dir["#{@migrations_path}/[0-9]*_*.rb"]
354
+ files = Array(@migrations_path).inject([]) do |files, path|
355
+ files += Dir["#{path}/[0-9]*_*.rb"]
356
+ end
330
357
 
331
358
  migrations = files.inject([]) do |klasses, file|
332
359
  version, name = file.scan(/([0-9]+)_([_a-z0-9]*).rb/).first
@@ -359,6 +386,24 @@ module Mongoid #:nodoc
359
386
  migrations.reject { |m| already_migrated.include?(m.version.to_i) }
360
387
  end
361
388
 
389
+ def runnable_migrations
390
+ current = migrations.detect { |m| m.version == current_version }
391
+ target = migrations.detect { |m| m.version == @target_version }
392
+
393
+ if target.nil? && !@target_version.nil? && @target_version > 0
394
+ raise UnknownMigrationVersionError.new(@target_version)
395
+ end
396
+
397
+ start = up? ? 0 : (migrations.index(current) || 0)
398
+ finish = migrations.index(target) || migrations.size - 1
399
+ runnable = migrations[start..finish]
400
+
401
+ # skip the last migration if we're headed down, but not ALL the way down
402
+ runnable.pop if down? && !target.nil?
403
+
404
+ runnable
405
+ end
406
+
362
407
  def migrated
363
408
  @migrated_versions ||= self.class.get_all_versions
364
409
  end
@@ -402,4 +447,4 @@ module Mongoid #:nodoc
402
447
  block.call
403
448
  end
404
449
  end
405
- end
450
+ end
@@ -15,9 +15,7 @@ module Mongoid
15
15
  end
16
16
  end
17
17
  else # module
18
- Config.module_eval do
19
- # newer mongoid style; >= 2.0.0.rc.1
20
- option :timestamped_migrations, :default => true
21
- end
18
+ # newer mongoid style; >= 2.0.0.rc.1
19
+ Config.option :timestamped_migrations, :default => true
22
20
  end
23
21
  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("db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
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, "db/migrate/", version)
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, "db/migrate/", version)
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('db/migrate/', step)
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.0.1'
3
- end
2
+ VERSION = '1.3.0'
3
+ end
@@ -1,32 +1,28 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'mongoid_rails_migrations', 'version')
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 |s|
4
- s.platform = Gem::Platform::RUBY
5
- s.name = 'mongoid_rails_migrations'
6
- s.version = MongoidRailsMigrations::VERSION
7
- s.summary = 'Data migrations for Mongoid in Active Record style, minus column input.'
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
- s.required_ruby_version = '>= 1.8.6'
12
- s.required_rubygems_version = '>= 1.3.6'
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
- s.author = 'Alan Da Costa'
15
- s.email = 'alandacosta@gmail.com'
16
- s.date = %q{2013-03-14}
17
- s.homepage = 'http://github.com/adacosta/mongoid_rails_migrations'
16
+ spec.files = Dir['README.rdoc', 'mongoid_rails_migrations.gemspec', 'lib/**/*']
17
+ spec.require_paths = ['lib']
18
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
19
+ rails_version = '>= 4.2.0'
23
20
 
24
- rails_version = '>= 3.2.0'
25
-
26
- s.add_dependency('bundler', '>= 1.0.0')
27
- s.add_dependency('rails', rails_version)
28
- s.add_dependency('railties', rails_version)
29
- s.add_dependency('activesupport', rails_version)
30
- s.add_development_dependency('mongoid', '>= 3.0.0')
31
- s.add_development_dependency('test-unit', '>= 2.5.0')
32
- end
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'
28
+ end
metadata CHANGED
@@ -1,177 +1,152 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_rails_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alan Da Costa
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-14 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.0.0
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
29
26
  version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rails
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
36
46
  - !ruby/object:Gem::Version
37
- version: 3.2.0
47
+ version: 4.2.0
38
48
  type: :runtime
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
- version: 3.2.0
54
+ version: 4.2.0
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: railties
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
- version: 3.2.0
61
+ version: 4.2.0
54
62
  type: :runtime
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - ">="
60
67
  - !ruby/object:Gem::Version
61
- version: 3.2.0
68
+ version: 4.2.0
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: activesupport
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ! '>='
73
+ - - ">="
68
74
  - !ruby/object:Gem::Version
69
- version: 3.2.0
75
+ version: 4.2.0
70
76
  type: :runtime
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ! '>='
80
+ - - ">="
76
81
  - !ruby/object:Gem::Version
77
- version: 3.2.0
82
+ version: 4.2.0
78
83
  - !ruby/object:Gem::Dependency
79
- name: mongoid
84
+ name: rake
80
85
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
86
  requirements:
83
- - - ! '>='
87
+ - - ">="
84
88
  - !ruby/object:Gem::Version
85
- version: 3.0.0
89
+ version: '0'
86
90
  type: :development
87
91
  prerelease: false
88
92
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
93
  requirements:
91
- - - ! '>='
94
+ - - ">="
92
95
  - !ruby/object:Gem::Version
93
- version: 3.0.0
96
+ version: '0'
94
97
  - !ruby/object:Gem::Dependency
95
- name: test-unit
98
+ name: minitest
96
99
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
100
  requirements:
99
- - - ! '>='
101
+ - - ">="
100
102
  - !ruby/object:Gem::Version
101
- version: 2.5.0
103
+ version: '0'
102
104
  type: :development
103
105
  prerelease: false
104
106
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
107
  requirements:
107
- - - ! '>='
108
+ - - ">="
108
109
  - !ruby/object:Gem::Version
109
- version: 2.5.0
110
- description: Migrations for the migrator.
111
- email: alandacosta@gmail.com
110
+ version: '0'
111
+ description: Data migrations for Mongoid in Active Record style, minus column input.
112
+ email:
113
+ - alandacosta@gmail.com
112
114
  executables: []
113
115
  extensions: []
114
116
  extra_rdoc_files: []
115
117
  files:
116
- - .gitignore
117
- - Gemfile
118
- - Gemfile.lock
119
- - Rakefile
120
- - README.rdoc
121
- - mongoid_rails_migrations.gemspec
118
+ - lib/mongoid_rails_migrations.rb
122
119
  - lib/mongoid_rails_migrations/active_record_ext/migrations.rb
123
120
  - lib/mongoid_rails_migrations/models/data_migration.rb
124
121
  - lib/mongoid_rails_migrations/mongoid_ext/mongoid.rb
125
122
  - lib/mongoid_rails_migrations/mongoid_ext/railtie.rb
126
123
  - lib/mongoid_rails_migrations/mongoid_ext/railties/database.rake
127
124
  - lib/mongoid_rails_migrations/version.rb
128
- - lib/mongoid_rails_migrations.rb
129
125
  - lib/rails/generators/mongoid/migration/migration_generator.rb
130
126
  - lib/rails/generators/mongoid/migration/templates/migration.rb
131
127
  - lib/rails/generators/mongoid/mongoid_generator.rb
132
- - test/config.rb
133
- - test/helper.rb
134
- - test/migration_test.rb
135
- - test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb
136
- - test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb
137
- - test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb
138
- - test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb
139
- - test/migrations/valid/20100513054656_add_baseline_survey_schema.rb
140
- - test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb
141
- - test/models/survey_schema.rb
128
+ - mongoid_rails_migrations.gemspec
142
129
  homepage: http://github.com/adacosta/mongoid_rails_migrations
143
130
  licenses:
144
131
  - MIT
132
+ metadata: {}
145
133
  post_install_message:
146
134
  rdoc_options: []
147
135
  require_paths:
148
136
  - lib
149
137
  required_ruby_version: !ruby/object:Gem::Requirement
150
- none: false
151
138
  requirements:
152
- - - ! '>='
139
+ - - ">="
153
140
  - !ruby/object:Gem::Version
154
- version: 1.8.6
141
+ version: '0'
155
142
  required_rubygems_version: !ruby/object:Gem::Requirement
156
- none: false
157
143
  requirements:
158
- - - ! '>='
144
+ - - ">="
159
145
  - !ruby/object:Gem::Version
160
- version: 1.3.6
146
+ version: '0'
161
147
  requirements: []
162
- rubyforge_project:
163
- rubygems_version: 1.8.24
148
+ rubygems_version: 3.1.2
164
149
  signing_key:
165
- specification_version: 3
166
- summary: Data migrations for Mongoid in Active Record style, minus column input.
167
- test_files:
168
- - test/config.rb
169
- - test/helper.rb
170
- - test/migration_test.rb
171
- - test/migrations/duplicate/names/20100513073457_add_duplicate_survey_schema.rb
172
- - test/migrations/duplicate/names/20100513073724_add_duplicate_survey_schema.rb
173
- - test/migrations/duplicate/versions/20100513073457_add_another_duplicate_survey_schema.rb
174
- - test/migrations/duplicate/versions/20100513073457_add_duplicate_survey_schema.rb
175
- - test/migrations/valid/20100513054656_add_baseline_survey_schema.rb
176
- - test/migrations/valid/20100513063902_add_improvement_plan_survey_schema.rb
177
- - test/models/survey_schema.rb
150
+ specification_version: 4
151
+ summary: Data migrations for Mongoid.
152
+ test_files: []
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- .bundle
2
- .DS_Store
3
- .rvmrc
4
- .idea
5
- log/
6
- .ruby-version
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in gem_test.gemspec
4
- gemspec :development_group => :development_mongoid_rails_migrations
5
- gemspec :test_group => :test_mongoid_rails_migrations
6
- gemspec :name => 'mongoid_rails_migrations'
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- mongoid_rails_migrations (1.0.1)
5
- activesupport (>= 3.2.0)
6
- bundler (>= 1.0.0)
7
- rails (>= 3.2.0)
8
- railties (>= 3.2.0)
9
-
10
- GEM
11
- remote: http://rubygems.org/
12
- specs:
13
- actionmailer (3.2.8)
14
- actionpack (= 3.2.8)
15
- mail (~> 2.4.4)
16
- actionpack (3.2.8)
17
- activemodel (= 3.2.8)
18
- activesupport (= 3.2.8)
19
- builder (~> 3.0.0)
20
- erubis (~> 2.7.0)
21
- journey (~> 1.0.4)
22
- rack (~> 1.4.0)
23
- rack-cache (~> 1.2)
24
- rack-test (~> 0.6.1)
25
- sprockets (~> 2.1.3)
26
- activemodel (3.2.8)
27
- activesupport (= 3.2.8)
28
- builder (~> 3.0.0)
29
- activerecord (3.2.8)
30
- activemodel (= 3.2.8)
31
- activesupport (= 3.2.8)
32
- arel (~> 3.0.2)
33
- tzinfo (~> 0.3.29)
34
- activeresource (3.2.8)
35
- activemodel (= 3.2.8)
36
- activesupport (= 3.2.8)
37
- activesupport (3.2.8)
38
- i18n (~> 0.6)
39
- multi_json (~> 1.0)
40
- arel (3.0.2)
41
- builder (3.0.0)
42
- erubis (2.7.0)
43
- hike (1.2.1)
44
- i18n (0.6.0)
45
- journey (1.0.4)
46
- json (1.7.7)
47
- mail (2.4.4)
48
- i18n (>= 0.4.0)
49
- mime-types (~> 1.16)
50
- treetop (~> 1.4.8)
51
- mime-types (1.21)
52
- mongoid (3.0.4)
53
- activemodel (~> 3.1)
54
- moped (~> 1.1)
55
- origin (~> 1.0)
56
- tzinfo (~> 0.3.22)
57
- moped (1.2.0)
58
- multi_json (1.3.6)
59
- origin (1.0.6)
60
- polyglot (0.3.3)
61
- rack (1.4.5)
62
- rack-cache (1.2)
63
- rack (>= 0.4)
64
- rack-ssl (1.3.3)
65
- rack
66
- rack-test (0.6.2)
67
- rack (>= 1.0)
68
- rails (3.2.8)
69
- actionmailer (= 3.2.8)
70
- actionpack (= 3.2.8)
71
- activerecord (= 3.2.8)
72
- activeresource (= 3.2.8)
73
- activesupport (= 3.2.8)
74
- bundler (~> 1.0)
75
- railties (= 3.2.8)
76
- railties (3.2.8)
77
- actionpack (= 3.2.8)
78
- activesupport (= 3.2.8)
79
- rack-ssl (~> 1.3.2)
80
- rake (>= 0.8.7)
81
- rdoc (~> 3.4)
82
- thor (>= 0.14.6, < 2.0)
83
- rake (10.0.3)
84
- rdoc (3.12.2)
85
- json (~> 1.4)
86
- sprockets (2.1.3)
87
- hike (~> 1.2)
88
- rack (~> 1.0)
89
- tilt (~> 1.1, != 1.3.0)
90
- test-unit (2.5.1)
91
- thor (0.17.0)
92
- tilt (1.3.5)
93
- treetop (1.4.12)
94
- polyglot
95
- polyglot (>= 0.3.1)
96
- tzinfo (0.3.33)
97
-
98
- PLATFORMS
99
- ruby
100
-
101
- DEPENDENCIES
102
- mongoid (>= 3.0.0)
103
- mongoid_rails_migrations!
104
- test-unit (>= 2.5.0)
@@ -1,52 +0,0 @@
1
- == RELEASE NOTES
2
- * For rails >= 3.2.0 and mongoid >= 3.0.0, use version 1.0.0
3
- * For rails >= 3.0.0 (but < 3.2.0) and mongoid >= 2.0.0, use version 0.0.14
4
-
5
- == SYNOPSIS
6
- * Data migrations for Mongoid.
7
-
8
- == MIGRATE WHEN ...
9
- * The migrating is good
10
-
11
- == INSTALL
12
- * gem install mongoid_rails_migrations
13
- * In your Gemfile, include (after including mongoid):
14
- gem "mongoid_rails_migrations", <version>
15
-
16
- == FEATURES AND HOW TO USE
17
- * generator:
18
- * rails generate mongoid:migration your_migration_name_here
19
-
20
- * migrations:
21
- * db:migrate
22
- * db:migrate:down
23
- * db:migrate:up
24
- * db:rollback
25
- * db:migrate:redo
26
- * db:migrate:reset
27
- * db:reseed (handled by mongoid)
28
- * db:version
29
-
30
- == CREDITS TO
31
- * rails
32
- * mongoid
33
- * contributions from the community (git log)
34
-
35
- Much of this gem simply modifies existing code from both projects.
36
- With that out of the way, on to the license.
37
-
38
- == LICENSE (MIT)
39
-
40
- Copyright © 2013: Alan Da Costa
41
-
42
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'),
43
- to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish,
44
- distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
45
- the following conditions:
46
-
47
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
48
-
49
- The software is provided 'as is', without warranty of any kind, express or implied, including but not limited to the warranties of
50
- merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any
51
- claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
52
- software or the use or other dealings in the software.
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__))
2
- namespace :test do
3
- require 'bundler/setup'
4
- Bundler.require(:development_mongoid_rails_migrations)
5
-
6
- namespace :mongoid do
7
- desc "Test mongoid rails migrations"
8
- task :migrations do
9
- require File.dirname(__FILE__) + "/test/config"
10
- require 'test/migration_test'
11
- end
12
- end
13
- end
@@ -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')
@@ -1,33 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- require 'bundler/setup'
5
- Bundler.require(:development_mongoid_rails_migrations)
6
-
7
- require 'config'
8
- require 'test/unit'
9
-
10
- require 'rake'
11
- require 'rake/testtask'
12
- require 'rdoc/task'
13
-
14
- # leave out active_record, in favor of a monogo adapter
15
- %w(
16
- action_controller
17
- action_mailer
18
- active_resource
19
- rails/test_unit
20
- mongoid
21
- ).each do |framework|
22
- begin
23
- require "#{framework}/railtie"
24
- rescue LoadError
25
- end
26
- end
27
-
28
- module TestMongoidRailsMigrations
29
- class Application < Rails::Application; end
30
- end
31
-
32
- # TestMongoidRailsMigrations::Application.initialize!
33
- TestMongoidRailsMigrations::Application.load_tasks
@@ -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
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class AddDuplicateSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Duplicate Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Duplicate Survey').first.destroy
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- class AddBaselineSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:id => '4c47bf87f3395c339c000001',
4
- :label => 'Baseline Survey')
5
- end
6
-
7
- def self.down
8
- SurveySchema.where(:label => 'Baseline Survey').first.destroy
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class AddImprovementPlanSurveySchema < Mongoid::Migration
2
- def self.up
3
- SurveySchema.create(:label => 'Improvement Plan Survey')
4
- end
5
-
6
- def self.down
7
- SurveySchema.where(:label => 'Improvement Plan Survey').first.destroy
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- class SurveySchema
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
-
5
- field :label
6
- end