-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
We are using postgres instead of mysql. Currently, the mysqldump command is hardcoded in the the default ExportService.
Here's what we did to support postgres export / import:
ExportService:php
public function exportDatabase()
{
$command =
"PGPASSWORD=" . escapeshellarg($this->databasePassword) . " pg_dump -h " . escapeshellarg($this->databaseHost) .
" -U " . escapeshellarg($this->databaseUser) .
" -d " . escapeshellarg($this->databaseName) .
" -F c -b -v -f " . escapeshellarg($this->exportDirectory . \DIRECTORY_SEPARATOR . ImportExportDefaultMap::FILENAME_SQL);
$process = Process::fromShellCommandline($command);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
ImportService.php:
public function importDatabase()
{
$command =
"PGPASSWORD=" . escapeshellarg($this->databasePassword) . " pg_restore -h " . escapeshellarg($this->databaseHost) .
" -U " . escapeshellarg($this->databaseUser) .
" -d " . escapeshellarg($this->databaseName) .
" --clean --if-exists -v " . escapeshellarg($this->importDirectory . \DIRECTORY_SEPARATOR . ImportExportDefaultMap::FILENAME_SQL);
$process = Process::fromShellCommandline($command);
$process->run();
if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
}
this adds a dependency on the pg_dump and pg_restore binaries. On Mac, you usually install them like this:
brew install libpq
brew link --force libpq
Metadata
Metadata
Assignees
Labels
No labels