Class: Bootstrap::Db::Mysql
- Defined in:
- lib/bootstrap/db/adapter/mysql.rb
Constant Summary collapse
- CONNECTION_MAP =
Config -> command line parameter
{ :username => :u, :password => :p, :host => :h }
Instance Attribute Summary
Attributes inherited from Adapter
#config, #file_name, #file_path
Instance Method Summary collapse
-
#connection_string ⇒ Object
Compile connection string.
- #dump! ⇒ Object
- #load! ⇒ Object
Methods inherited from Adapter
#additional_parameters, #command_string, #current_db_time, #ignore_tables, #initialize
Methods included from Command
#display_and_execute, #execute_command
Constructor Details
This class inherits a constructor from Bootstrap::Db::Adapter
Instance Method Details
#connection_string ⇒ Object
Compile connection string
12 13 14 15 16 17 18 19 20 |
# File 'lib/bootstrap/db/adapter/mysql.rb', line 12 def connection_string @connection_string ||= begin CONNECTION_MAP.inject([]) do |result, (config_name, command_name)| config_value = config.settings[config_name.to_s] result << "-#{command_name} '#{config_value}'" if config_value result end.join(' ') end end |
#dump! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bootstrap/db/adapter/mysql.rb', line 22 def dump! #mysqldump --help dump_command = [ "mysqldump", "-q --add-drop-table --add-locks", "--extended-insert --lock-tables", "--single-transaction", connection_string ] if ignore_tables.present? ignore_tables.each do |table_name| dump_command << "--ignore-table='#{config.settings["database"]}.#{table_name.strip}'" end end if additional_parameters.present? additional_parameters.each do |param| dump_command << param end end dump_command << "#{config.settings['database']} > #{file_path}" display_and_execute(dump_command.join(' ')) end |
#load! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bootstrap/db/adapter/mysql.rb', line 49 def load! #mysql --help load_command = [ "mysql", "-f", connection_string, "#{config.settings["database"]} < #{file_path}" ] display_and_execute(load_command.join(' ')) end |