Module: Dkdeploy::Helpers::DB
- Defined in:
- lib/dkdeploy/helpers/db.rb
Overview
DB related helpers
Instance Method Summary collapse
- #db_dump_file(infix = '') ⇒ Object
- #db_dump_file_content(table_name = nil) ⇒ Object
- #db_dump_file_structure(table_name = nil) ⇒ Object
- #db_settings_hash ⇒ Object
-
#read_db_settings_for_context(context) ⇒ Hash
Read db settings for given context.
Instance Method Details
#db_dump_file(infix = '') ⇒ Object
11 12 13 14 |
# File 'lib/dkdeploy/helpers/db.rb', line 11 def db_dump_file(infix = '') date = Time.now.strftime(datetime_format) ['database', fetch(:stage), infix, date].join('-') << '.sql' end |
#db_dump_file_content(table_name = nil) ⇒ Object
16 17 18 |
# File 'lib/dkdeploy/helpers/db.rb', line 16 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
20 21 22 |
# File 'lib/dkdeploy/helpers/db.rb', line 20 def db_dump_file_structure(table_name = nil) db_dump_file ['structure', table_name].compact.join('-') end |
#db_settings_hash ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dkdeploy/helpers/db.rb', line 24 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
41 42 43 44 45 46 47 48 |
# File 'lib/dkdeploy/helpers/db.rb', line 41 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 |