lib/dbcp/databases/postgres_database.rb in dbcp-0.0.1 vs lib/dbcp/databases/postgres_database.rb in dbcp-0.1.0
- old
+ new
@@ -1,11 +1,38 @@
module Dbcp
class PostgresDatabase < Database
def export_command(snapshot_file)
- %W[export PGPASSWORD=#{password}].shelljoin + '; ' + %W[pg_dump --host #{host} --username #{username} --file #{snapshot_file.path} --format c #{database}].shelljoin
+ build_password + [
+ 'pg_dump',
+ '--host', host,
+ build_port,
+ '--username', username,
+ '--file', snapshot_file.path,
+ '--format', 'c',
+ database
+ ].flatten.compact.shelljoin
end
def import_command(snapshot_file)
- %W[export PGPASSWORD=#{password}].shelljoin + '; ' + %W[pg_restore --host #{host} --username #{username} --clean --dbname #{database} #{snapshot_file.path}].shelljoin
+ build_password + [
+ 'pg_restore',
+ '--host', host,
+ build_port,
+ '--username', username,
+ '--dbname', database,
+ '--clean',
+ snapshot_file.path
+ ].flatten.compact.shelljoin
end
+
+ private
+
+ def build_password
+ %W[export PGPASSWORD=#{password}].shelljoin + '; '
+ end
+
+ def build_port
+ ['--port', port] if host && port
+ end
+
end
end