public inbox for [email protected]
help / color / mirror / Atom feedFrom: Murtuza Zabuawala <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM#2989] To fix the issue in Table node
Date: Tue, 6 Mar 2018 14:52:46 +0530
Message-ID: <CAKKotZSRSKPWzapTT6fJQiCAprRs_h644mXkeP_ba-NbynJufg@mail.gmail.com> (raw)
Hi,
PFA patch to fix the issue in Table node where wrong sql was generated
while altering column.
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:
[application/octet-stream] RM_2989.diff (6.7K, 3-RM_2989.diff)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_column_update.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_column_update.py
new file mode 100644
index 0000000..9c59c1e
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_column_update.py
@@ -0,0 +1,90 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2018, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import json
+import uuid
+
+from pgadmin.browser.server_groups.servers.databases.schemas.tests import \
+ utils as schema_utils
+from pgadmin.browser.server_groups.servers.databases.tests import utils as \
+ database_utils
+from pgadmin.utils.route import BaseTestGenerator
+from regression import parent_node_dict
+from regression.python_test_utils import test_utils as utils
+from . import utils as tables_utils
+
+
+class TableNotNullUpdateTestCase(BaseTestGenerator):
+ """This class will add new collation under schema node."""
+ scenarios = [
+ ('Update Table with not null field', dict(url='/browser/table/obj/')),
+ ]
+
+ def setUp(self):
+ self.db_name = parent_node_dict["database"][-1]["db_name"]
+ schema_info = parent_node_dict["schema"][-1]
+ self.server_id = schema_info["server_id"]
+ self.db_id = schema_info["db_id"]
+ db_con = database_utils.connect_database(
+ self, utils.SERVER_GROUP, self.server_id, self.db_id
+ )
+ if not db_con['data']["connected"]:
+ raise Exception("Could not connect to database to add a table.")
+ self.schema_id = schema_info["schema_id"]
+ self.schema_name = schema_info["schema_name"]
+ schema_response = schema_utils.verify_schemas(self.server,
+ self.db_name,
+ self.schema_name)
+ if not schema_response:
+ raise Exception("Could not find the schema to add a table.")
+
+ self.table_name = "test_table_column_put_%s" % (str(uuid.uuid4())[1:8])
+
+ custom_sql = 'column_1 "char" NOT NULL'
+
+ self.table_id = tables_utils.create_table(
+ self.server,
+ self.db_name,
+ self.schema_name,
+ self.table_name,
+ custom_sql
+ )
+
+ def runTest(self):
+ """This function will fetch added table under schema node."""
+ table_response = tables_utils.verify_table(
+ self.server, self.db_name, self.table_id
+ )
+ if not table_response:
+ raise Exception("Could not find the table to update.")
+
+ data = {
+ "id": self.table_id,
+ "columns": {
+ "changed": [
+ {
+ "attnum": 1,
+ "attnotnull": False
+ }
+ ]
+ }
+ }
+
+ response = self.tester.put(
+ self.url + str(utils.SERVER_GROUP) + '/' +
+ str(self.server_id) + '/' + str(self.db_id) + '/' +
+ str(self.schema_id) + '/' + str(self.table_id),
+ data=json.dumps(data), follow_redirects=True
+ )
+
+ self.assertEquals(response.status_code, 200)
+
+ def tearDown(self):
+ # Disconnect the database
+ database_utils.disconnect_database(self, self.server_id, self.db_id)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/utils.py
index 4cec323..b722147 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/utils.py
@@ -15,7 +15,8 @@ import traceback
from regression.python_test_utils import test_utils as utils
-def create_table(server, db_name, schema_name, table_name):
+def create_table(server, db_name, schema_name, table_name,
+ custom_column_sql=None):
"""
This function creates a table under provided schema.
:param server: server details
@@ -39,9 +40,13 @@ def create_table(server, db_name, schema_name, table_name):
old_isolation_level = connection.isolation_level
connection.set_isolation_level(0)
pg_cursor = connection.cursor()
- query = "CREATE TABLE %s.%s(id serial UNIQUE NOT NULL, name text," \
- " location text)" %\
- (schema_name, table_name)
+ if custom_column_sql:
+ query = "CREATE TABLE %s.%s(%s)" % \
+ (schema_name, table_name, custom_column_sql)
+ else:
+ query = "CREATE TABLE %s.%s(id serial UNIQUE NOT NULL, " \
+ "name text, location text)" % \
+ (schema_name, table_name)
pg_cursor.execute(query)
connection.set_isolation_level(old_isolation_level)
connection.commit()
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
index 45403d1..36b6a3b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
@@ -1779,8 +1779,18 @@ class BaseTableView(PGChildNodeView):
) or matchObj.group(1)
c['attprecision'] = None
else:
- c['attlen'] = None
- c['attprecision'] = None
+ # Use the old values to avoid unnecessary
+ # sql generation
+ if 'attlen' in old_data:
+ if old_data['attlen'] != '-1':
+ c['attlen'] = old_data.get(
+ 'attlen', None
+ )
+ if 'attprecision' in old_data:
+ if old_data['attprecision'] != '-1':
+ c['attprecision'] = old_data.get(
+ 'attprecision', None
+ )
if 'cltype' in c:
typename = c['cltype']
[application/octet-stream] fix_table_node_PEP8.diff (2.4K, 4-fix_table_node_PEP8.diff)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index 2bd30d1..1160cfb 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -349,7 +349,6 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings):
if not status:
return internal_server_error(errormsg=rset)
-
for row in rset['rows']:
if 'is_partitioned' in row and row['is_partitioned']:
icon = "icon-partition"
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py
index 3cdc292..c5bfa54 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/tests/test_column_msql.py
@@ -167,16 +167,20 @@ class ColumnMsqlTestCase(BaseTestGenerator):
if not expected_precision and hasattr(self, 'old_precision'):
expected_precision = self.old_precision
- self.assertEquals(response_data['data'],
- self.expected_res.format(
- **dict([('schema', self.schema_name),
- ('table', self.table_name),
- ('column', self.column_name),
- ('len', expected_len),
- ('precision', expected_precision)
- ]
- )
- ))
+ self.assertEquals(
+ response_data['data'],
+ self.expected_res.format(
+ **dict(
+ [
+ ('schema', self.schema_name),
+ ('table', self.table_name),
+ ('column', self.column_name),
+ ('len', expected_len),
+ ('precision', expected_precision)
+ ]
+ )
+ )
+ )
def tearDown(self):
# Disconnect the database
view thread (12+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin4][RM#2989] To fix the issue in Table node
In-Reply-To: <CAKKotZSRSKPWzapTT6fJQiCAprRs_h644mXkeP_ba-NbynJufg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox