Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL support #15

Open
davidgorges opened this issue Sep 2, 2024 · 0 comments
Open

PostgreSQL support #15

davidgorges opened this issue Sep 2, 2024 · 0 comments

Comments

@davidgorges
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant