Skip to content

Commit

Permalink
SQL - Check that PG is minimum 9.6 when installing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Feb 14, 2022
1 parent d4718e4 commit 54127c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Fix an error when PgMetadata database is not temporary reachable
* Check that PostgreSQL is minimum 9.6 when installing the schema

## 1.1.0 - 2021-09-29

Expand Down
14 changes: 14 additions & 0 deletions pg_metadata/processing/database/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from qgis.core import (
Qgis,
QgsAbstractDatabaseProviderConnection,
QgsProcessingException,
QgsProcessingOutputString,
QgsProcessingParameterBoolean,
Expand Down Expand Up @@ -148,6 +149,8 @@ def processAlgorithm(self, parameters, context, feedback):
if not connection:
raise QgsProcessingException(tr("The connection {} does not exist.").format(connection_name))

self.check_pg_version(connection)

# Drop schema if needed
override = self.parameterAsBool(parameters, self.OVERRIDE, context)
if override and SCHEMA in connection.schemas():
Expand Down Expand Up @@ -246,6 +249,17 @@ def processAlgorithm(self, parameters, context, feedback):
}
return results

@staticmethod
def check_pg_version(connection: QgsAbstractDatabaseProviderConnection):
""" Check PG minimum version. """
try:
result = connection.executeSql("SELECT current_setting('server_version_num');")
except QgsProviderConnectionException as e:
raise QgsProcessingException(str(e))

if int(result[0][0]) <= 90600:
raise QgsProcessingException(tr("PostgreSQL 9.6 minimum is required."))

@staticmethod
def install_html_templates(feedback, connection_name, context):
feedback.pushInfo("Adding default HTML templates")
Expand Down

0 comments on commit 54127c8

Please sign in to comment.