Class: DeployMongo::DbSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_mongo/db_schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, repository) ⇒ DbSchema

Returns a new instance of DbSchema.



5
6
7
8
# File 'lib/deploy_mongo/db_schema.rb', line 5

def initialize(schema,repository)
  @schema = schema
  @repository = repository
end

Class Method Details

.load_or_create(config, repository) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/deploy_mongo/db_schema.rb', line 10

def self.load_or_create(config,repository)
  default_schema = {"_id"=>"schema__schema_document_key__", 'applied_deltas'=>[]}
  schema = repository.get_schema
  if (schema.nil?)
     repository.save_schema(default_schema)
     schema = repository.get_schema
  end
  DbSchema.new(schema,repository)
end

Instance Method Details

#applied_deltasObject



20
21
22
# File 'lib/deploy_mongo/db_schema.rb', line 20

def applied_deltas
  @schema["applied_deltas"]
end

#completed(delta) ⇒ Object



24
25
26
27
28
# File 'lib/deploy_mongo/db_schema.rb', line 24

def completed(delta)
  @schema['applied_deltas'].push(delta.id)
  @repository.save_schema(@schema)
  @schema = @repository.get_schema
end

#rollback(delta) ⇒ Object



30
31
32
33
34
# File 'lib/deploy_mongo/db_schema.rb', line 30

def rollback(delta)
  @schema['applied_deltas'].delete(delta.id)
  @repository.save_schema(@schema)
  @schema = @repository.get_schema
end