Module: UffDbLoader::Mysql

Defined in:
lib/uff_db_loader/mysql.rb

Class Method Summary collapse

Class Method Details

.create_database(database_name) ⇒ Object



21
22
23
# File 'lib/uff_db_loader/mysql.rb', line 21

def self.create_database(database_name)
  ActiveRecord::Base.connection.execute("CREATE DATABASE #{database_name};")
end

.drop_database(database_name) ⇒ Object



25
26
27
# File 'lib/uff_db_loader/mysql.rb', line 25

def self.drop_database(database_name)
  ActiveRecord::Base.connection.execute("DROP DATABASE IF EXISTS #{database_name};")
end

.dump_command_templateObject



9
10
11
# File 'lib/uff_db_loader/mysql.rb', line 9

def self.dump_command_template
  "ssh %user%@%host% \"docker exec -i %container_name% sh -c 'exec mysqldump --opt --single-transaction --routines --triggers --events --no-tablespaces -uroot -p\"\\$MYSQL_ROOT_PASSWORD\" %database%'\" > %target%"
end

.dump_extensionObject



5
6
7
# File 'lib/uff_db_loader/mysql.rb', line 5

def self.dump_extension
  "sql"
end

.list_databasesObject



17
18
19
# File 'lib/uff_db_loader/mysql.rb', line 17

def self.list_databases
  ActiveRecord::Base.connection.execute("SHOW DATABASES;").to_a.flatten
end

.restore_command(database_name, result_file_path, config) ⇒ Object



13
14
15
# File 'lib/uff_db_loader/mysql.rb', line 13

def self.restore_command(database_name, result_file_path, config)
  "#{File.join(config.local_restore_command_path || "mysql")} -uroot #{database_name} < #{result_file_path}"
end