From 59834fba310722b0c45bdcb3bfc9eb0a8ac4d9aa Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Mon, 24 Apr 2017 13:55:29 +0100 Subject: [PATCH] Initial support for PG 10.0, per #2214 --- .../templates/sequence/sql/default/update.sql | 10 ++--- .../servers/templates/__init__.py | 0 .../servers/templates/connect/__init__.py | 0 .../servers/templates/connect/sql/__init__.py | 0 .../templates/connect/sql/tests/__init__.py | 0 .../connect/sql/tests/test_check_recovery.py | 37 ------------------- web/pgadmin/dashboard/__init__.py | 16 ++++++++ .../utils/versioned_template_loader.py | 1 + 8 files changed, 22 insertions(+), 42 deletions(-) delete mode 100644 web/pgadmin/browser/server_groups/servers/templates/__init__.py delete mode 100644 web/pgadmin/browser/server_groups/servers/templates/connect/__init__.py delete mode 100644 web/pgadmin/browser/server_groups/servers/templates/connect/sql/__init__.py delete mode 100644 web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/__init__.py delete mode 100644 web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/test_check_recovery.py diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/default/update.sql index cb1df060c..cf5948918 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/default/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/sequences/templates/sequence/sql/default/update.sql @@ -11,22 +11,22 @@ ALTER SEQUENCE {{ conn|qtIdent(o_data.schema, data.name) }} OWNER TO {{ conn|qtIdent(data.seqowner) }}; {% endif %} -{% if data.current_value %} +{% if data.current_value is defined %} {% set seqname = conn|qtIdent(o_data.schema, data.name) %} SELECT setval({{ seqname|qtLiteral }}, {{ data.current_value }}, true); {% endif %} {% set defquery = '' %} -{% if data.increment %} +{% if data.increment is defined %} {% set defquery = defquery+'\n INCREMENT '+data.increment|string %} {% endif %} -{% if data.minimum %} +{% if data.minimum is defined %} {% set defquery = defquery+'\n MINVALUE '+data.minimum|string %} {% endif %} -{% if data.maximum %} +{% if data.maximum is defined %} {% set defquery = defquery+'\n MAXVALUE '+data.maximum|string %} {% endif %} -{% if data.cache %} +{% if data.cache is defined %} {% set defquery = defquery+'\n CACHE '+data.cache|string %} {% endif %} {% if data.cycled == True %} diff --git a/web/pgadmin/browser/server_groups/servers/templates/__init__.py b/web/pgadmin/browser/server_groups/servers/templates/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/pgadmin/browser/server_groups/servers/templates/connect/__init__.py b/web/pgadmin/browser/server_groups/servers/templates/connect/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/pgadmin/browser/server_groups/servers/templates/connect/sql/__init__.py b/web/pgadmin/browser/server_groups/servers/templates/connect/sql/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/__init__.py b/web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/test_check_recovery.py b/web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/test_check_recovery.py deleted file mode 100644 index 954e20bda..000000000 --- a/web/pgadmin/browser/server_groups/servers/templates/connect/sql/tests/test_check_recovery.py +++ /dev/null @@ -1,37 +0,0 @@ -import os - -from pgadmin.utils.route import BaseTestGenerator -from regression.python_test_utils import test_utils - - -class TestCheckRecovery(BaseTestGenerator): - - versions_to_test = ["default", "9.0_plus"] - - scenarios = [ - ("Test for check recovery", dict()) - ] - - def runTest(self): - - cursor = test_utils.get_db_connection(self.server['db'], - self.server['username'], - self.server['db_password'], - self.server['host'], - self.server['port']).cursor() - - for version in self.versions_to_test: - template_file = os.path.join(os.path.dirname(__file__), "..", version, "check_recovery.sql") - - cursor.execute(open(template_file, 'r').read()) - fetch_result = cursor.fetchall() - - first_row = {} - for index, description in enumerate(cursor.description): - first_row[description.name] = fetch_result[0][index] - - in_recovery = first_row['inrecovery'] - wal_paused = first_row['isreplaypaused'] - - self.assertEqual(False, in_recovery) - self.assertEqual(False, wal_paused) diff --git a/web/pgadmin/dashboard/__init__.py b/web/pgadmin/dashboard/__init__.py index 0a0796ac4..a95ba53d1 100644 --- a/web/pgadmin/dashboard/__init__.py +++ b/web/pgadmin/dashboard/__init__.py @@ -131,6 +131,22 @@ def check_precondition(f): PG_DEFAULT_DRIVER).connection_manager( kwargs['sid'] ) + + # Below check handle the case where existing server is deleted + # by user and python server will raise exception if this check + # is not introduce. + if g.manager is None: + if f.__name__ in ['activity', 'prepared', 'locks', 'config']: + return precondition_required( + gettext("Please connect to the selected server" + " to view the table.") + ) + else: + return precondition_required( + gettext("Please connect to the selected server" + " to view the graph.") + ) + g.conn = g.manager.connection() # If DB not connected then return error to browser diff --git a/web/pgadmin/utils/versioned_template_loader.py b/web/pgadmin/utils/versioned_template_loader.py index 7d2b70f22..df24ab74c 100644 --- a/web/pgadmin/utils/versioned_template_loader.py +++ b/web/pgadmin/utils/versioned_template_loader.py @@ -16,6 +16,7 @@ class VersionedTemplateLoader(DispatchingJinjaLoader): template_path_parts = template.split("#", 2) server_versions = ( + {'name': "10.0_plus", 'number': 100000}, {'name': "9.6_plus", 'number': 90600}, {'name': "9.5_plus", 'number': 90500}, {'name': "9.4_plus", 'number': 90400},