Class: DbAgent::DbHandler::MySQL

Inherits:
DbAgent::DbHandler show all
Defined in:
lib/db_agent/db_handler/mysql.rb

Instance Attribute Summary

Attributes inherited from DbAgent::DbHandler

#backup_folder, #config, #data_folder, #migrations_folder, #schema_folder, #superconfig, #viewpoints_folder

Instance Method Summary collapse

Methods inherited from DbAgent::DbHandler

factor, #initialize, #migrate, #ping, #require_viewpoints!, #sequel_db, #sequel_superdb, #system, #wait, #wait_server

Constructor Details

This class inherits a constructor from DbAgent::DbHandler

Instance Method Details

#backupObject



14
15
16
17
# File 'lib/db_agent/db_handler/mysql.rb', line 14

def backup
  datetime = Time.now.strftime('%Y%m%dT%H%M%S')
  shell mysqldump(config[:database], "> #{backup_folder}/backup-#{datetime}.sql")
end

#createObject



6
7
8
# File 'lib/db_agent/db_handler/mysql.rb', line 6

def create
  raise
end

#dropObject



10
11
12
# File 'lib/db_agent/db_handler/mysql.rb', line 10

def drop
  raise
end

#replObject



19
20
21
# File 'lib/db_agent/db_handler/mysql.rb', line 19

def repl
  shell mysql(config[:database])
end

#restore(_t, args) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/db_agent/db_handler/mysql.rb', line 29

def restore(_t, args)
  candidates = backup_folder.glob('*.sql').sort
  if args[:pattern] && rx = Regexp.new(args[:pattern])
    candidates = candidates.select { |f| f.basename.to_s =~ rx }
  end
  file = candidates.last
  shell mysql(config[:database], '<', file.to_s)
end

#spyObject



23
24
25
26
27
# File 'lib/db_agent/db_handler/mysql.rb', line 23

def spy
  jdbc_jar = (Path.dir.parent / 'vendor').glob('mysql*.jar').first
  system %(java -jar vendor/schemaSpy_5.0.0.jar -dp #{jdbc_jar} -t mysql -host #{config[:host]} -u #{config[:user]} -p #{config[:password]} -db #{config[:database]} -s public -o #{schema_folder}/spy)
  system %(open #{schema_folder}/spy/index.html)
end