Skip to content

Commit

Permalink
Set PGPASSWORD for sql (restore command) too
Browse files Browse the repository at this point in the history
resolves #2741
  • Loading branch information
brandonkelly committed Apr 13, 2018
1 parent f6f9895 commit 9a637eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fixed a bug where deprecation errors for some date formatting methods were not escaping backslashes.
- Fixed a bug where plugins’ “Last update” timestamps in the Plugin Store weren’t getting formatted correctly in Safari. ([#2733](https://github.com/craftcms/cms/issues/2733))
- Fixed references to a nonexistant `Craft.eot` file in the Control Panel CSS. ([#2740](https://github.com/craftcms/cms/issues/2740))
- Fixed a bug where the default PostgreSQL database restore command wasn’t setting the `PGPASSWORD` environment variable. ([#2741](https://github.com/craftcms/cms/pull/2741))

## 3.0.2 - 2018-04-10

Expand Down
24 changes: 16 additions & 8 deletions src/db/pgsql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ public function getDefaultBackupCommand()
$defaultTableIgnoreList[$key] = " --exclude-table-data '{schema}.".$dbSchema->getRawTableName($ignoreTable)."'";
}

if (Platform::isWindows()) {
$envCommand = 'set PGPASSWORD="{password}" && ';
} else {
$envCommand = 'PGPASSWORD="{password}" ';
}

return $envCommand.
return $this->_pgpasswordCommand().
'pg_dump'.
' --dbname={database}'.
' --host={server}'.
Expand All @@ -160,7 +154,8 @@ public function getDefaultBackupCommand()
*/
public function getDefaultRestoreCommand(): string
{
return 'psql'.
return $this->_pgpasswordCommand().
'psql'.
' --dbname={database}'.
' --host={server}'.
' --port={port}'.
Expand Down Expand Up @@ -341,4 +336,17 @@ protected function getIndexInformation(TableSchema $table): array
':tableName' => $table->name,
])->queryAll();
}

// Private Methods
// =========================================================================

/**
* Returns the PGPASSWORD command for backup/restore actions.
*
* @return string
*/
private function _pgpasswordCommand(): string
{
return Platform::isWindows() ? 'set PGPASSWORD="{password}" && ' : 'PGPASSWORD="{password}" ';
}
}

0 comments on commit 9a637eb

Please sign in to comment.