Class: DeployMongo::Deploy

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Deploy

Returns a new instance of Deploy.



4
5
6
# File 'lib/deploy_mongo/deploy.rb', line 4

def initialize(config)
  @config = config    
end

Instance Method Details

#rollback(no_of_deltas_to_rollback = 0) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/deploy_mongo/deploy.rb', line 41

def rollback (no_of_deltas_to_rollback = 0)
  
  repository = Repository.new(@config)
  delta_loader = DeltaLoader.new(@config.delta_path)
  deltas_map = delta_loader.get_deltas
  couch_schema = DbSchema.load_or_create(@config,repository)
  applied_deltas = couch_schema.applied_deltas.sort.reverse
  no_of_deltas_to_rollback = applied_deltas.length if no_of_deltas_to_rollback == 0

  deltas = []
  puts "Already applied deltas #{applied_deltas}"
  puts "Rolling back deltas #{applied_deltas[0..(no_of_deltas_to_rollback-1)]}"
  puts ""
  puts "Start rolling back deltas"

  applied_deltas[0..(no_of_deltas_to_rollback-1)].each do |key|
    delta = deltas_map[key]
    DeltaProcessor.new(@config,delta).rollback
    couch_schema.rollback(delta)
    deltas.push(delta)
    puts "rollback delta #{delta.file_name}"
  end

  puts "Finished rolling back deltas"    
  deltas      
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/deploy_mongo/deploy.rb', line 8

def run
  repository = Repository.new(@config)
  delta_loader = DeltaLoader.new(@config.delta_path)
  deltas_map = delta_loader.get_deltas
  db_schema = DbSchema.load_or_create(@config,repository)
  all_delta_keys = deltas_map.keys.sort
  applied_deltas = db_schema.applied_deltas.sort
  last_applied_delta_id = 0
  last_applied_delta_id = applied_deltas[-1] if applied_deltas.count > 0
  delta_keys_to_apply = all_delta_keys.select {|key| key > last_applied_delta_id }

  deltas = []
  puts "Deltas #{all_delta_keys} found"
  puts "Already applied deltas #{applied_deltas}"
  puts "Applying deltas #{delta_keys_to_apply}"
  puts ""
  puts "Start applying deltas"

  delta_keys_to_apply.each do |key|
    delta = deltas_map[key]
    DeltaProcessor.new(@config,delta).apply
    db_schema.completed(delta)
    deltas.push(delta)
    puts "applied delta #{delta.file_name}"
  end

  puts "Finished applying deltas"
  puts ""
  puts "Deltas #{all_delta_keys - applied_deltas - delta_keys_to_apply} where skiped"

  deltas
end