Class: Branchbot::Adapters::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/branchbot/adapters/abstract.rb

Direct Known Subclasses

MySQL, PostgreSQL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, dump_folder) ⇒ Abstract

Returns a new instance of Abstract.



18
19
20
21
22
23
# File 'lib/branchbot/adapters/abstract.rb', line 18

def initialize(config, dump_folder)
  @config = config
  @database_name = config['database']

  @dump_folder = dump_folder
end

Class Method Details

.build(config, dump_folder) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/branchbot/adapters/abstract.rb', line 5

def self.build(config, dump_folder)
  klass = case config['adapter']
  when 'postgresql'
    PostgreSQL
  when 'mysql2'
    MySQL
  else
    raise UnsupportedDatabase.new(config['adapter'])
  end

  klass.new(config, dump_folder)
end

Instance Method Details

#dump(branch_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/branchbot/adapters/abstract.rb', line 25

def dump(branch_name)
  print "Saving state of database on '#{branch_name}' branch..."

  if system(dump_cmd(branch_name))
    print "done!\n"
    true
  else
    print "failed!\n"
    false
  end
end

#dump_exists?(branch_name) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/branchbot/adapters/abstract.rb', line 37

def dump_exists?(branch_name)
  File.exists?(dump_file(branch_name))
end

#restore(branch_name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/branchbot/adapters/abstract.rb', line 41

def restore(branch_name)
  print "Restoring #{database_name} to its previous state on this branch..."

  if system(restore_cmd(branch_name))
    print "done!\n"
    true
  else
    print "failed!\n"
    false
  end
end