diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5492af..b9fcf1a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pg_metadata/processing/database/create.py b/pg_metadata/processing/database/create.py index b90f96d3..09e38752 100644 --- a/pg_metadata/processing/database/create.py +++ b/pg_metadata/processing/database/create.py @@ -9,6 +9,7 @@ from qgis.core import ( Qgis, + QgsAbstractDatabaseProviderConnection, QgsProcessingException, QgsProcessingOutputString, QgsProcessingParameterBoolean, @@ -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(): @@ -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")