exodus 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +25 -3
- data/exodus.gemspec +1 -1
- data/lib/exodus.rb +13 -2
- data/lib/exodus/config/migration_info.rb +1 -1
- data/lib/exodus/migrations/migration.rb +14 -7
- data/lib/exodus/version.rb +1 -1
- data/tasks/exodus.rake +12 -6
- metadata +3 -3
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -15,19 +15,36 @@ Exodus - a migration framework for MongoDb
|
|
15
15
|
|
16
16
|
|
17
17
|
# Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
18
20
|
|
19
|
-
|
21
|
+
$ gem 'exodus'
|
22
|
+
|
23
|
+
And then execute bundle install:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install exodus
|
20
30
|
|
21
31
|
# Configuration
|
22
32
|
|
23
|
-
You need to configure
|
33
|
+
You need to configure 4 things before using Exodus: the database name, the mongodb connection, the config file location and the path to the directory that will include your migrations:
|
34
|
+
|
35
|
+
require 'exodus'
|
24
36
|
|
25
37
|
Exodus.configure do |config|
|
26
38
|
config.db = 'migration_db'
|
27
39
|
config.connection = Mongo::MongoClient.new("127.0.0.1", 27017, :pool_size => 5, :pool_timeout => 5)
|
28
40
|
config.config_file = File.dirname(__FILE__) + '/config/config.yml'
|
41
|
+
config.migrations_directory = File.dirname(__FILE__) + '/models/migrations'
|
29
42
|
end
|
30
43
|
|
44
|
+
Then you just need to loads the migrations tasks by adding the following line to your rakefile:
|
45
|
+
|
46
|
+
load Exodus.tasks
|
47
|
+
|
31
48
|
... And you're all set!
|
32
49
|
|
33
50
|
|
@@ -140,6 +157,11 @@ Exodus - a migration framework for MongoDb
|
|
140
157
|
## db:migrate:yml_status
|
141
158
|
Prints on the screen the content of the yml configuration file
|
142
159
|
|
143
|
-
rake db:migrate:
|
160
|
+
rake db:migrate:yml_status
|
161
|
+
|
162
|
+
## db:mongo_info
|
163
|
+
Prints on the screen information about the current mongo connection
|
164
|
+
|
165
|
+
rake db:mongo_info
|
144
166
|
|
145
167
|
|
data/exodus.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ['thomas@fanhattan.com', 'thomas.dmytryk@supinfo.com']
|
7
7
|
gem.description = %q{Exodus is a migration framework for MongoDb}
|
8
8
|
gem.summary = %q{Exodus uses mongomapper to provide a complete migration framework}
|
9
|
-
gem.homepage = ''
|
9
|
+
gem.homepage = 'https://github.com/ThomasAlxDmy/Exodus'
|
10
10
|
gem.license = 'MIT'
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split($\)
|
data/lib/exodus.rb
CHANGED
@@ -16,13 +16,24 @@ module Exodus
|
|
16
16
|
yield(configuration) if block_given?
|
17
17
|
end
|
18
18
|
|
19
|
+
# Loads existing migrations into memory
|
20
|
+
def load_migrations
|
21
|
+
raise StandardError, 'A migrations directory is needed in order to load migrations.' unless migrations_info.migrations_directory
|
22
|
+
Dir[migrations_info.migrations_directory + '/*.rb'].each { |file| require file}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the path of the rake file
|
26
|
+
def tasks
|
27
|
+
File.dirname(__FILE__) + '/../tasks/exodus.rake'
|
28
|
+
end
|
29
|
+
|
19
30
|
# Executes a number of migrations equal to step (or all of them if step is nil)
|
20
31
|
def run_migrations(direction, migrations, step = nil)
|
21
32
|
if migrations
|
22
|
-
sorted_migrations = order_with_direction(
|
33
|
+
sorted_migrations = order_with_direction(migrations, direction)
|
23
34
|
sorted_migrations = sorted_migrations.shift(step.to_i) if step
|
24
35
|
|
25
|
-
run_each(sorted_migrations)
|
36
|
+
run_each(direction, sorted_migrations)
|
26
37
|
else
|
27
38
|
puts "no migrations given in argument!"
|
28
39
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
module Exodus
|
2
2
|
class Migration
|
3
3
|
include MongoMapper::Document
|
4
|
+
set_collection_name 'migrations'
|
5
|
+
|
4
6
|
UP = 'up'
|
5
7
|
DOWN = 'down'
|
6
|
-
@
|
8
|
+
@migrations = []
|
7
9
|
|
8
10
|
timestamps!
|
9
11
|
|
@@ -21,10 +23,15 @@ module Exodus
|
|
21
23
|
def inherited(klass)
|
22
24
|
klass.embedded_callbacks_on if defined?(MongoMapper::Plugins::EmbeddedCallbacks::ClassMethods) #MongoMapper version compatibility
|
23
25
|
klass.migration_number = 0
|
24
|
-
@
|
26
|
+
@migrations << [klass]
|
25
27
|
super(klass)
|
26
28
|
end
|
27
29
|
|
30
|
+
# Sorts all migrations by migration number
|
31
|
+
def sort_all
|
32
|
+
@migrations.sort_by {|migration,args| migration.migration_number }
|
33
|
+
end
|
34
|
+
|
28
35
|
# Using a list of migrations
|
29
36
|
# Formats and overrides migrations without arguments using ones that have given arguments
|
30
37
|
# Removes duplicates
|
@@ -36,15 +43,15 @@ module Exodus
|
|
36
43
|
formated_migration = format(migration, args)
|
37
44
|
migration, args = formated_migration
|
38
45
|
|
39
|
-
unless @
|
40
|
-
@
|
41
|
-
@
|
46
|
+
unless @migrations.include?(formated_migration)
|
47
|
+
@migrations.delete_if {|loaded_migration, loaded_args| migration == loaded_migration && (loaded_args.nil? || loaded_args.empty?) }
|
48
|
+
@migrations << formated_migration
|
42
49
|
end
|
43
50
|
end
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
47
|
-
@
|
54
|
+
@migrations
|
48
55
|
end
|
49
56
|
|
50
57
|
# Using a list of migrations formats them and removes duplicates
|
@@ -65,7 +72,7 @@ module Exodus
|
|
65
72
|
puts "\n Migration n#: \t\t Name: \t\t\t\t Description:"
|
66
73
|
puts '-' * 100, "\n"
|
67
74
|
|
68
|
-
|
75
|
+
Migration.sort_all.map do|migration, args|
|
69
76
|
m = migration.new
|
70
77
|
puts "\t#{migration.migration_number} \t\t #{migration.name} \t\t #{m.description}"
|
71
78
|
end
|
data/lib/exodus/version.rb
CHANGED
data/tasks/exodus.rake
CHANGED
@@ -12,13 +12,14 @@ end
|
|
12
12
|
task :require_env do
|
13
13
|
require 'csv'
|
14
14
|
require File.dirname(__FILE__) + '/../lib/exodus'
|
15
|
+
Exodus.load_migrations
|
15
16
|
end
|
16
17
|
|
17
18
|
namespace :db do
|
18
19
|
desc "Migrate the database"
|
19
20
|
task :migrate => :require_env do
|
20
21
|
time_it "db:migrate#{" step #{step}" if step}" do
|
21
|
-
migrations = Migration.load_all(Exodus.migrations_info.migrate)
|
22
|
+
migrations = Exodus::Migration.load_all(Exodus.migrations_info.migrate)
|
22
23
|
Exodus::run_migrations('up', migrations, step)
|
23
24
|
end
|
24
25
|
end
|
@@ -26,11 +27,16 @@ namespace :db do
|
|
26
27
|
desc "Rolls the database back to the previous version"
|
27
28
|
task :rollback => :require_env do
|
28
29
|
time_it "db:rollback#{" step #{step}" if step}" do
|
29
|
-
migrations = Migration.load_all(Exodus.migrations_info.rollback)
|
30
|
+
migrations = Exodus::Migration.load_all(Exodus.migrations_info.rollback)
|
30
31
|
Exodus::run_migrations('down', migrations, step)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
desc "Shows informations about the current mongo connection"
|
36
|
+
task :mongo_info => :require_env do
|
37
|
+
p MongoMapper.database
|
38
|
+
end
|
39
|
+
|
34
40
|
namespace :migrate do
|
35
41
|
desc "Manually migrates specified migrations (specify migrations or use config/migration.yml)"
|
36
42
|
task :custom, [:migrations_info] => :require_env do |t, args|
|
@@ -38,7 +44,7 @@ namespace :db do
|
|
38
44
|
migrations = if args[:migrations_info]
|
39
45
|
YAML.load(args[:migrations_info])
|
40
46
|
else
|
41
|
-
Migration.load_custom(Exodus.migrations_info.migrate_custom)
|
47
|
+
Exodus::Migration.load_custom(Exodus.migrations_info.migrate_custom)
|
42
48
|
end
|
43
49
|
|
44
50
|
Exodus::run_migrations('up', migrations, step)
|
@@ -47,7 +53,7 @@ namespace :db do
|
|
47
53
|
|
48
54
|
desc "Lists all the migrations"
|
49
55
|
task :list => :require_env do
|
50
|
-
Migration.list
|
56
|
+
Exodus::Migration.list
|
51
57
|
end
|
52
58
|
|
53
59
|
desc "Loads migration.yml and displays it"
|
@@ -57,7 +63,7 @@ namespace :db do
|
|
57
63
|
|
58
64
|
desc "Displays the current status of migrations"
|
59
65
|
task :status => :require_env do
|
60
|
-
Migration.db_status
|
66
|
+
Exodus::Migration.db_status
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
@@ -68,7 +74,7 @@ namespace :db do
|
|
68
74
|
migrations = if args[:migrations_info]
|
69
75
|
YAML.load(args[:migrations_info])
|
70
76
|
else
|
71
|
-
Migration.load_custom(Exodus.migrations_info.rollback_custom)
|
77
|
+
Exodus::Migration.load_custom(Exodus.migrations_info.rollback_custom)
|
72
78
|
end
|
73
79
|
|
74
80
|
Exodus::run_migrations('down', migrations, step)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exodus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongo_mapper
|
@@ -104,7 +104,7 @@ files:
|
|
104
104
|
- spec/support/config.yml
|
105
105
|
- spec/support/user_support.rb
|
106
106
|
- tasks/exodus.rake
|
107
|
-
homepage:
|
107
|
+
homepage: https://github.com/ThomasAlxDmy/Exodus
|
108
108
|
licenses:
|
109
109
|
- MIT
|
110
110
|
post_install_message:
|