public inbox for [email protected]
help / color / mirror / Atom feedFrom: Murtuza Zabuawala <[email protected]>
To: Dave Page <[email protected]>
Cc: Joao De Almeida Pereira <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin4][RM#2989] To fix the issue in Table node
Date: Wed, 7 Mar 2018 20:29:46 +0530
Message-ID: <CAKKotZSas8Chx0neZqpvFwSBPE1JDwF=afbvP3aptfF578Xhxw@mail.gmail.com> (raw)
In-Reply-To: <CAKKotZRwaG6X-9ZZ3+CCMQ0y=h7kTR_ver=QfWf6savrjtbF3A@mail.gmail.com>
References: <CAKKotZSRSKPWzapTT6fJQiCAprRs_h644mXkeP_ba-NbynJufg@mail.gmail.com>
<CAE+jjamZ94=4w+dR7bCYcPv0iQMj5bNmtpZdDCppVf2G_KNReA@mail.gmail.com>
<CA+OCxox3gREiVKvXSh2=OjooseZH3cveT90C97k6mH6s0AYGnA@mail.gmail.com>
<CAKKotZRwaG6X-9ZZ3+CCMQ0y=h7kTR_ver=QfWf6savrjtbF3A@mail.gmail.com>
Hi Dave,
PFA updated patch.
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Wed, Mar 7, 2018 at 6:14 PM, Murtuza Zabuawala <
[email protected]> wrote:
>
> On Wed, Mar 7, 2018 at 6:12 PM, Dave Page <[email protected]> wrote:
>
>> Hi
>>
>> On Tue, Mar 6, 2018 at 4:06 PM, Joao De Almeida Pereira <
>> [email protected]> wrote:
>>
>>> Hi Murtuza,
>>>
>>> The code change works, and I passed the patches through our pipeline and
>>> everything is green.
>>> Personally I would love this bug fixes to have refactored the function
>>> into smaller chunk and made it more readable so that the next time someone
>>> need to check out a problem in the same area it is easier. I understand
>>> that without a good test coverage it is hard to have confidence while
>>> refactoring, but we need to start somewhere.
>>>
>>
>> Are you planning to look into this Murtuza?
>>
> Yes Dave, I am working on another issue, I'll pick up after that.
>
>
>>
>>
>>>
>>> @Hackers
>>> Here is a video that I saw some time ago about refactoring existing code
>>> and code complexity that is very interesting
>>> https://www.youtube.com/watch?v=8bZh5LMaSmE
>>> In this video Sandi Metz does the Gilded Rose Kata in a talk in
>>> RailsConf 2014, and with it tries to demonstrate that code can be
>>> refactored and with that it make the code much more simpler. But the
>>> journey is not always simple and the complexity will increase before it get
>>> simpler. It is a good example of something that we can try with our code.
>>>
>>
>> Nice!
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>
Attachments:
[application/octet-stream] RM_2989_v1.diff (7.1K, 3-RM_2989_v1.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..b4602b4 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,8 @@ class BaseTableView(PGChildNodeView):
) or matchObj.group(1)
c['attprecision'] = None
else:
- c['attlen'] = None
- c['attprecision'] = None
+ # Use the old values to avoid unnecessary
+ self.assign_old_length_precision(c, old_data)
if 'cltype' in c:
typename = c['cltype']
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
index ddebd5e..e1b50ad 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/utils.py
@@ -320,6 +320,25 @@ class DataTypeReader:
return type_name
+ @classmethod
+ def assign_old_length_precision(cls, data, old_data):
+ """
+ Assign the old values to new which will avoid unnecessary
+ sql generation
+
+ Args:
+ data: New values
+ old_data: Old values
+ """
+ if 'attlen' in old_data:
+ if old_data['attlen'] != '-1':
+ data['attlen'] = old_data.get('attlen', None)
+ if 'attprecision' in old_data:
+ if old_data['attprecision'] != '-1':
+ data['attprecision'] = old_data.get(
+ 'attprecision', None
+ )
+
def trigger_definition(data):
"""
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], [email protected], [email protected]
Subject: Re: [pgAdmin4][RM#2989] To fix the issue in Table node
In-Reply-To: <CAKKotZSas8Chx0neZqpvFwSBPE1JDwF=afbvP3aptfF578Xhxw@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