class MysqlFork

Public Instance Methods

connection_parameters() click to toggle source
# File lib/database_fork/mysql_fork.rb, line 16
def connection_parameters
  @connection_parameters ||= MysqlConnection.new(@connection).params
end
create_database() click to toggle source
# File lib/database_fork/mysql_fork.rb, line 28
def create_database
  record_command %Q{mysql #{connection_parameters} -e "CREATE DATABASE IF NOT EXISTS #{target_name} CHARACTER SET '#{character_set}' COLLATE '#{collation}';"}, "create database #{@fork_db_name}"
end
create_dump() click to toggle source
# File lib/database_fork/mysql_fork.rb, line 20
def create_dump
  record_command %Q{mysqldump #{connection_parameters} --routines --triggers -C #{source_db} > #{dump_file}}, "dumping #{source_db}"
end
exists?(dry_run = false) click to toggle source
# File lib/database_fork/mysql_fork.rb, line 6
def exists?(dry_run = false)
  command = %Q{mysql #{connection_parameters} -s -N -e "SHOW DATABASES LIKE '#{target_name}';" }
  if dry_run
    reset_commands!
    record_command command, 'query default character set and collation'
  else
    !`#{command}`.empty?
  end
end
import_dump() click to toggle source
# File lib/database_fork/mysql_fork.rb, line 32
def import_dump
  record_command %Q{mysql #{connection_parameters} -C -A -D#{target_name} < #{dump_file}}, 'importing dump'
end
query_default_settings(dry_run = false) click to toggle source
# File lib/database_fork/mysql_fork.rb, line 36
def query_default_settings(dry_run = false)
  command = %Q{mysql #{connection_parameters} -s -N -e "SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA S WHERE schema_name = 'papersmart_dev';"}
  if dry_run
    reset_commands!
    record_command command, 'query default character set and collation'
  else
    @character_set, @collation = *(`#{command}`.("\t"))
  end
end
source_db() click to toggle source
# File lib/database_fork/mysql_fork.rb, line 24
def source_db
  @connection['database']
end