Commit 5b446846 authored by catch's avatar catch
Browse files

Issue #2846994 by Gábor Hojtsy, jungle, andypost, daffie, swatichouhan012,...

Issue #2846994 by Gábor Hojtsy, jungle, andypost, daffie, swatichouhan012, xjm, catch, effulgentsia, bzrudi71, mradcliffe, TravisCarden, Mixologic: Increase minimum version requirement for Postgres to 10 and require the pg_trgm extension
parent c88513f9
......@@ -56,7 +56,7 @@ Drupal requires:
compatible drop-in replacement for MySQL.
- Percona Server 5.7.8 (or greater) (http://www.percona.com/). Percona
Server is a backwards-compatible replacement for MySQL.
- PostgreSQL 9.1.2 (or greater) (http://www.postgresql.org/).
- PostgreSQL 10 (or greater) (http://www.postgresql.org/).
- SQLite 3.26 (or greater) (http://www.sqlite.org/).
For more detailed information about Drupal requirements, including a list of
......
......@@ -11,6 +11,15 @@
*/
class Tasks extends InstallTasks {
/**
* Minimum required PostgreSQL version.
*
* The contrib extension pg_trgm is supposed to be installed.
*
* @see https://www.postgresql.org/docs/10/pgtrgm.html
*/
const PGSQL_MINIMUM_VERSION = '10';
/**
* {@inheritdoc}
*/
......@@ -49,7 +58,7 @@ public function name() {
* {@inheritdoc}
*/
public function minimumVersion() {
return '9.1.2';
return static::PGSQL_MINIMUM_VERSION;
}
/**
......@@ -133,42 +142,38 @@ protected function checkEncoding() {
* Unserializing does not work on Postgresql 9 when bytea_output is 'hex'.
*/
public function checkBinaryOutput() {
// PostgreSQL < 9 doesn't support bytea_output, so verify we are running
// at least PostgreSQL 9.
$database_connection = Database::getConnection();
if (version_compare($database_connection->version(), '9') >= 0) {
if (!$this->checkBinaryOutputSuccess()) {
// First try to alter the database. If it fails, raise an error telling
// the user to do it themselves.
$connection_options = $database_connection->getConnectionOptions();
// It is safe to include the database name directly here, because this
// code is only called when a connection to the database is already
// established, thus the database name is guaranteed to be a correct
// value.
$query = "ALTER DATABASE \"" . $connection_options['database'] . "\" SET bytea_output = 'escape';";
try {
$database_connection->query($query);
}
catch (\Exception $e) {
// Ignore possible errors when the user doesn't have the necessary
// privileges to ALTER the database.
}
if (!$this->checkBinaryOutputSuccess()) {
// First try to alter the database. If it fails, raise an error telling
// the user to do it themselves.
$connection_options = $database_connection->getConnectionOptions();
// It is safe to include the database name directly here, because this
// code is only called when a connection to the database is already
// established, thus the database name is guaranteed to be a correct
// value.
$query = "ALTER DATABASE \"{$connection_options['database']}\" SET bytea_output = 'escape';";
try {
$database_connection->query($query);
}
catch (\Exception $e) {
// Ignore possible errors when the user doesn't have the necessary
// privileges to ALTER the database.
}
// Close the database connection so that the configuration parameter
// is applied to the current connection.
Database::closeConnection();
// Close the database connection so that the configuration parameter
// is applied to the current connection.
Database::closeConnection();
// Recheck, if it fails, finally just rely on the end user to do the
// right thing.
if (!$this->checkBinaryOutputSuccess()) {
$replacements = [
'%setting' => 'bytea_output',
'%current_value' => 'hex',
'%needed_value' => 'escape',
'@query' => $query,
];
$this->fail(t("The %setting setting is currently set to '%current_value', but needs to be '%needed_value'. Change this by running the following query: <code>@query</code>", $replacements));
}
// Recheck, if it fails, finally just rely on the end user to do the
// right thing.
if (!$this->checkBinaryOutputSuccess()) {
$replacements = [
'%setting' => 'bytea_output',
'%current_value' => 'hex',
'%needed_value' => 'escape',
'@query' => $query,
];
$this->fail(t("The %setting setting is currently set to '%current_value', but needs to be '%needed_value'. Change this by running the following query: <code>@query</code>", $replacements));
}
}
}
......
......@@ -380,7 +380,7 @@ protected function processField($field) {
}
if (!empty($field['unsigned'])) {
// Unsigned data types are not supported in PostgreSQL 9.1. In MySQL,
// Unsigned data types are not supported in PostgreSQL 10. In MySQL,
// they are used to ensure a positive number is inserted and it also
// doubles the maximum integer size that can be stored in a field.
// The PostgreSQL schema in Drupal creates a check constraint
......@@ -706,7 +706,7 @@ public function fieldExists($table, $column) {
* {@inheritdoc}
*/
public function indexExists($table, $name) {
// Details http://www.postgresql.org/docs/9.1/interactive/view-pg-indexes.html
// Details https://www.postgresql.org/docs/10/view-pg-indexes.html
$index_name = $this->ensureIdentifiersLength($table, $name, 'idx');
// Remove leading and trailing quotes because the index name is in a WHERE
// clause and not used as an identifier.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment