Top Level Namespace

Defined Under Namespace

Modules: Mina

Constant Summary collapse

ARGUMENTS =
<<-RUBY
  dc = YAML.load(ERB.new(File.read(ARGV[0])).result)[ARGV[1]]
  adapter = dc["adapter"]
  database = dc["database"]
  host = dc["host"]
  username = dc["username"]
  password = dc["password"]
  port = dc["port"]
  arguments = ""
  case adapter.to_s
  when "postgresql"
    arguments += " -d " + database if database
    arguments += " -h " + host if host
    arguments += " -U " + username if username
    arguments += " -p " + port.to_s if port
  when "mysql2"
    arguments += " " + database if database
    arguments += " -h " + host if host
    arguments += " -u " + username if username
    arguments += " --password=" + password if password
    arguments += " -P " + port.to_s if port
  end
  puts arguments
RUBY
CONF =
<<-BASH
  function conf {
    ruby -ryaml -rerb -e '#{ARGUMENTS}' "$@"
  };
BASH

Instance Method Summary collapse

Instance Method Details

#backup_file ⇒ Object



36
37
38
# File 'lib/mina/data_sync/helpers.rb', line 36

def backup_file
  "#{@conf['database']}-#{Date.today}.sql"
end

#dump ⇒ Object



40
41
42
43
44
45
# File 'lib/mina/data_sync/helpers.rb', line 40

def dump
  case @conf['adapter']
  when 'postgresql' then 'pg_dump'
  when 'mysql2' then 'mysqldump'
  end
end

#options ⇒ Object



54
55
56
57
58
59
# File 'lib/mina/data_sync/helpers.rb', line 54

def options
  case @conf['adapter']
  when 'postgresql' then '-O -c'
  when 'mysql2' then ''
  end
end

#read_conf(path, rails_env) ⇒ Object



32
33
34
# File 'lib/mina/data_sync/helpers.rb', line 32

def read_conf(path, rails_env)
  @conf ||= YAML.load(ERB.new(File.read(path)).result)[rails_env]
end

#restore ⇒ Object



47
48
49
50
51
52
# File 'lib/mina/data_sync/helpers.rb', line 47

def restore
  case @conf['adapter']
  when 'postgresql' then 'psql -q'
  when 'mysql2' then 'mysql --verbose'
  end
end