Module: Capistrano::Container::DB::Helper

Defined in:
lib/db/helper.rb

Class Method Summary collapse

Class Method Details

.append_stage_to_filename(file_name, stage = 'local') ⇒ Object



26
27
28
29
30
31
# File 'lib/db/helper.rb', line 26

def self.append_stage_to_filename(file_name, stage = 'local')
  splitted  = file_name.split('.')
  extension = splitted.pop
  splitted.push stage, extension
  splitted.join('.')
end

.duplicate_local_dump_to_staged_dumpObject



33
34
35
36
37
# File 'lib/db/helper.rb', line 33

def self.duplicate_local_dump_to_staged_dump()
  staged_file = append_stage_to_filename(fetch(:db_local_dump), fetch(:stage))

  FileUtils.cp(fetch(:db_local_dump), staged_file)
end

.execute_db_command_autodetect(cmd) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/db/helper.rb', line 43

def self.execute_db_command_autodetect(cmd)
  cmd = "mysql #{Helper::mysql_auth_args} -e \"#{cmd}\""

  if fetch(:db_is_container)
    db_container = container_by_name fetch(:db_container_name)
    on_container db_container do |container|
      container.execute cmd
    end
  else
    execute_local_or_remote cmd
  end
end

.local_stage?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/db/helper.rb', line 39

def self.local_stage?
  fetch(:local_stage_name).to_sym == fetch(:stage).to_sym
end

.mysql_auth_argsObject



19
20
21
22
23
24
# File 'lib/db/helper.rb', line 19

def self.mysql_auth_args
  command = " -u #{fetch(:db_user)}"
  command+= " -p#{fetch(:db_pass)}" unless fetch(:db_pass).empty?
  command+= " #{fetch(:db_additional_auth_args).join(' ')} "
  command
end

.mysql_dump_argsObject



5
6
7
8
9
10
# File 'lib/db/helper.rb', line 5

def self.mysql_dump_args
  command = mysql_auth_args
  command+= " #{fetch(:db_additional_dump_args).join(' ')} "
  command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
  command
end

.mysql_restore_argsObject



12
13
14
15
16
17
# File 'lib/db/helper.rb', line 12

def self.mysql_restore_args
  command = mysql_auth_args
  command+= " #{fetch(:db_additional_restore_args).join(' ')} "
  command+= " #{fetch(:db_name)}" unless fetch(:db_name).empty?
  command
end