class Seed::Mysql

Public Class Methods

allow_tables_option(tables) click to toggle source
# File lib/seed/mysql.rb, line 15
def self.allow_tables_option(tables)
  tables.join(' ')
end
dump(file_path, username:, password:, host:, port:, database:, tables:, ignore_tables:) click to toggle source
# File lib/seed/mysql.rb, line 3
def self.dump(file_path, username:, password:, host:, port:, database:, tables:, ignore_tables:)
  host = 'localhost' unless host
  cmd = "MYSQL_PWD=#{password} mysqldump -u #{username} -h #{host} #{database} -t #{allow_tables_option(tables)} #{ignore_tables_option(ignore_tables)} > #{file_path}"
  system cmd
end
ignore_tables_option(tables) click to toggle source
# File lib/seed/mysql.rb, line 19
def self.ignore_tables_option(tables)
  tables.map { |table| "--ignore-table=#{table}" }.join(' ')
end
restore(file_path, username:, password:, host:, port:, database:) click to toggle source
# File lib/seed/mysql.rb, line 9
def self.restore(file_path, username:, password:, host:, port:, database:)
  host = 'localhost' unless host
  cmd = "MYSQL_PWD=#{password} mysql -u #{username} -h #{host} #{database} < #{file_path}"
  system cmd
end