Class: Ferry::Dumper
Instance Method Summary
collapse
Methods inherited from Utilities
#check_valid_db, #check_valid_filetype, #db_connect, #execute, #print_version
Instance Method Details
#create_dirs ⇒ Object
24
25
26
27
28
|
# File 'lib/ferry/dumper.rb', line 24
def create_dirs
homedir = "db/sql_dumps/#{@dbname}/#{@dbadapter}/#{@dbenv}"
FileUtils.mkpath homedir unless Dir[homedir].present?
FileUtils.touch(@outfile_path) unless File.exist?(@outfile_path)
end
|
#dump(environment) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/ferry/dumper.rb', line 6
def dump(environment)
@dbadapter = db_connect(environment)
@dbenv = environment
@dbname = YAML::load(IO.read("config/database.yml"))[@dbenv]["database"]
@outfile_path = "db/sql_dumps/#{@dbname}/#{@dbadapter}/#{@dbenv}/dumpfile.sql"
@commands = { "sqlite3" => "sqlite3 db/#{@dbenv}.sqlite3 .dump > #{@outfile_path}",
"postgresql" => "pg_dump #{@dbname} > #{@outfile_path}",
"mysql2" => "mysqldump #{@dbname} > #{@outfile_path}"
}
if check_valid_db(@dbadapter)
create_dirs
execute(@commands[@dbadapter])
else
raise "Dump failed: #{@dbadapter} is not supported by ferry at this time"
return false
end
end
|