Class: MysqlFork

Inherits:
DBFork show all
Defined in:
lib/database_fork/mysql_fork.rb

Instance Attribute Summary

Attributes inherited from DBFork

#commands

Instance Method Summary collapse

Methods inherited from DBFork

#character_set, #collation, #delete_dump_file, #dump_file, #export_env, #fork, #initialize, #reset_env, #target_name

Methods included from Commands

#execute_commands, #record_command, #reset_commands!

Methods included from Logging

#log_debug, #log_info

Constructor Details

This class inherits a constructor from DBFork

Instance Method Details

#connection_parametersObject



16
17
18
# File 'lib/database_fork/mysql_fork.rb', line 16

def connection_parameters
  @connection_parameters ||= MysqlConnection.new(@connection).params
end

#create_databaseObject



28
29
30
# 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_dumpObject



20
21
22
# 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) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
# 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_dumpObject



32
33
34
# 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) ⇒ Object



36
37
38
39
40
41
42
43
44
# 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_dbObject



24
25
26
# File 'lib/database_fork/mysql_fork.rb', line 24

def source_db
  @connection['database']
end