mongoid_migration 0.0.4 → 0.0.8

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.
@@ -39,7 +39,7 @@ module MongoidMigration
39
39
  # until they are needed
40
40
  class MigrationProxy
41
41
 
42
- attr_accessor :name, :version, :filename
42
+ attr_accessor :name, :version, :filename, :basename, :scope
43
43
 
44
44
  delegate :migrate, :announce, :write, :to=>:migration
45
45
 
@@ -65,12 +65,51 @@ module MongoidMigration
65
65
 
66
66
  field :version
67
67
 
68
- index :version
68
+ index(version: 1)
69
69
 
70
70
  @@verbose = true
71
71
  cattr_accessor :verbose
72
72
 
73
73
  class << self
74
+ def copy(destination, sources, options = {})
75
+ copied = []
76
+ FileUtils.mkdir_p(destination) unless File.exists?(destination)
77
+
78
+ destination_migrations = MongoidMigration::Migrator.new(:up, destination).migrations
79
+ last = destination_migrations.last
80
+ sources.each do |scope, path|
81
+ source_migrations = MongoidMigration::Migrator.new(:up, path).migrations
82
+
83
+ source_migrations.each do |migration|
84
+ source = File.read(migration.filename)
85
+ source = "# This migration comes from #{scope} (originally #{migration.version})\n#{source}"
86
+
87
+ if duplicate = destination_migrations.detect { |m| m.name == migration.name }
88
+ if options[:on_skip] && duplicate.scope != scope.to_s
89
+ options[:on_skip].call(scope, migration)
90
+ end
91
+ next
92
+ end
93
+
94
+ migration.version = next_migration_number(last ? last.version + 1 : 0).to_i
95
+ new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.#{scope}.rb")
96
+ old_path, migration.filename = migration.filename, new_path
97
+ last = migration
98
+
99
+ File.open(migration.filename, "w") { |f| f.write source }
100
+ copied << migration
101
+ options[:on_copy].call(scope, migration, old_path) if options[:on_copy]
102
+ destination_migrations << migration
103
+ end
104
+ end
105
+
106
+ copied
107
+ end
108
+
109
+ def next_migration_number(number)
110
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % number].max
111
+ end
112
+
74
113
  def up_with_benchmarks #:nodoc:
75
114
  migrate(:up)
76
115
  end
@@ -274,7 +313,7 @@ module MongoidMigration
274
313
  files = Dir["#{@migrations_path}/[0-9]*_*.rb"]
275
314
 
276
315
  migrations = files.inject([]) do |klasses, file|
277
- version, name = file.scan(/([0-9]+)_([_a-z0-9]*).rb/).first
316
+ version, name, scope = file.scan(/([0-9]+)_([_a-z0-9]*)\.?([a-z]*).rb/).first
278
317
 
279
318
  raise IllegalMigrationNameError.new(file) unless version
280
319
  version = version.to_i
@@ -288,9 +327,11 @@ module MongoidMigration
288
327
  end
289
328
 
290
329
  migration = MigrationProxy.new
330
+ migration.basename = File.basename(file)
291
331
  migration.name = name.camelize
292
332
  migration.version = version
293
333
  migration.filename = file
334
+ migration.scope = scope unless scope.blank?
294
335
  klasses << migration
295
336
  end
296
337
 
@@ -1,3 +1,3 @@
1
1
  module MongoidMigration
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -1,7 +1,30 @@
1
1
  namespace :db do
2
2
  namespace :mongoid do
3
-
4
3
  namespace :migration do
4
+ desc 'Installs migrations from engines into current application'
5
+ task :install => :environment do
6
+ to_load = ENV['FROM'].blank? ? :all : ENV['FROM'].split(",").map {|n| n.strip }
7
+ railties = {}
8
+
9
+ Rails.application.railties.all do |railtie|
10
+ next unless to_load == :all || to_load.include?(railtie.railtie_name)
11
+
12
+ if railtie.respond_to?(:paths) && railtie.paths['mongodb/migrate'].respond_to?(:first) && (path = railtie.paths['mongodb/migrate'].first)
13
+ railties[railtie.railtie_name] = path
14
+ end
15
+ end
16
+
17
+ on_skip = Proc.new do |name, migration|
18
+ puts "NOTE: Migration #{migration.basename} from #{name} has been skipped. Migration with the same name already exists."
19
+ end
20
+
21
+ on_copy = Proc.new do |name, migration, old_path|
22
+ puts "Copied migration #{migration.basename} from #{name}"
23
+ end
24
+
25
+ MongoidMigration::Migration.copy(Rails.root.join('mongodb/migrate'), railties, :on_skip => on_skip, :on_copy => on_copy)
26
+ end
27
+
5
28
  desc 'Runs the "up" for a given migration VERSION.'
6
29
  task :up => :environment do
7
30
  version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
@@ -1,10 +1,16 @@
1
1
  development:
2
- host: localhost
3
- database: dummy_development
2
+ sessions:
3
+ default:
4
+ database: mongoid_migrations_dev
5
+ hosts:
6
+ - localhost: 27017
4
7
 
5
8
  test:
6
- host: localhost
7
- database: dummy_test
9
+ sessions:
10
+ default:
11
+ database: mongoid_migrations_test
12
+ hosts:
13
+ - localhost: 27017
8
14
 
9
15
  # set these environment variables on your prod server
10
16
  production:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,56 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.1
21
+ version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.0.1
29
+ version: '3.2'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mongoid
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ! '>'
36
36
  - !ruby/object:Gem::Version
37
- version: 2.0.1
37
+ version: '2.4'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: 2.0.1
46
- - !ruby/object:Gem::Dependency
47
- name: rails
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - '='
52
- - !ruby/object:Gem::Version
53
- version: 3.1.1
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - '='
43
+ - - ! '>'
60
44
  - !ruby/object:Gem::Version
61
- version: 3.1.1
45
+ version: '2.4'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: bson_ext
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
130
  version: '0'
147
131
  segments:
148
132
  - 0
149
- hash: 1269953636149721865
133
+ hash: -4153209918740686442
150
134
  required_rubygems_version: !ruby/object:Gem::Requirement
151
135
  none: false
152
136
  requirements:
@@ -155,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
139
  version: '0'
156
140
  segments:
157
141
  - 0
158
- hash: 1269953636149721865
142
+ hash: -4153209918740686442
159
143
  requirements: []
160
144
  rubyforge_project:
161
145
  rubygems_version: 1.8.23