Skip to content

PostgreSQL support #15

@davidgorges

Description

@davidgorges

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions