Module: MongoMapper::Migration
- Defined in:
- lib/mongo_mapper_ext/migration.rb
Defined Under Namespace
Classes: Logger, MigrationDefinition
Class Method Summary
collapse
Class Method Details
.define(database_alias, version, &block) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/mongo_mapper_ext/migration.rb', line 41
def define database_alias, version, &block
database_alias = database_alias.to_s
version.should! :be_a, Integer
definition = MigrationDefinition.new
block.call definition
definitions[database_alias][version] = definition
end
|
.definitions ⇒ Object
71
72
73
|
# File 'lib/mongo_mapper_ext/migration.rb', line 71
def definitions
@definitions ||= Hash.new{|h, k| h[k] = []}
end
|
.logger ⇒ Object
39
|
# File 'lib/mongo_mapper_ext/migration.rb', line 39
def logger; @logger ||= Logger.new end
|
.logger=(logger) ⇒ Object
35
36
37
|
# File 'lib/mongo_mapper_ext/migration.rb', line 35
def logger= logger
@logger = logger ? logger : Logger.new(false)
end
|
66
67
68
69
|
# File 'lib/mongo_mapper_ext/migration.rb', line 66
def metadata db
col = db.collection 'db_metadata'
metadata = (col.find_one || {:version => 0}).to_openobject
end
|
.update(database_alias, version) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/mongo_mapper_ext/migration.rb', line 50
def update database_alias, version
database_alias = database_alias.to_s
db = MongoMapper.databases[database_alias]
if metadata(db).version == version
logger.info "Database '#{database_alias}' already is of #{version} version, no migration needed."
return false
else
logger.info "Migration for '#{database_alias}' Database:"
end
increase_db_version database_alias, db while metadata(db).version < version
decrease_db_version database_alias, db while metadata(db).version > version
true
end
|