Module: Dkdeploy::Helpers::DB

Defined in:
lib/dkdeploy/helpers/db.rb

Overview

DB related helpers

Instance Method Summary collapse

Instance Method Details

#db_dump_file(infix = '') ⇒ Object



9
10
11
12
# File 'lib/dkdeploy/helpers/db.rb', line 9

def db_dump_file(infix = '')
  date = DateTime.now.strftime(datetime_format)
  ['database', fetch(:stage), infix, date].join('-') << '.sql'
end

#db_dump_file_content(table_name = nil) ⇒ Object



14
15
16
# File 'lib/dkdeploy/helpers/db.rb', line 14

def db_dump_file_content(table_name = nil)
  db_dump_file ['content', table_name].compact.join('-')
end

#db_dump_file_structure(table_name = nil) ⇒ Object



18
19
20
# File 'lib/dkdeploy/helpers/db.rb', line 18

def db_dump_file_structure(table_name = nil)
  db_dump_file ['structure', table_name].compact.join('-')
end

#db_settings_hashObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dkdeploy/helpers/db.rb', line 22

def db_settings_hash
  {
    'database' => {
      'host'     => fetch(:db_host),
      'port'     => fetch(:db_port),
      'name'     => fetch(:db_name),
      'username' => fetch(:db_username),
      'password' => fetch(:db_password),
      'charset'  => fetch(:db_charset)
    }
  }
end

#read_db_settings_for_context(context) ⇒ Hash

Read db settings for given context

Parameters:

  • context (SSHKit::Backend::Netssh)

    SSHKit context

Returns:

  • (Hash)

    Hash with database settings



39
40
41
42
43
44
45
46
# File 'lib/dkdeploy/helpers/db.rb', line 39

def read_db_settings_for_context(context)
  unless context.test("[ -f #{remote_database_config_path} ]")
    context.error I18n.t('errors.database_config_file_missing', scope: :dkdeploy)
    return
  end
  json_string = context.download! remote_database_config_path
  YAML.safe_load(json_string).fetch('database')
end