Re: [GSoC][Patch] Automatic Mode Detection V1

2019-06-16 Thread Yosry Muhammad
This is a patch fixing a problem with the above patch that happened when:
- primary key columns are renamed.
- other columns are renamed to be like primary key columns.

This problem happened mainly because the primary keys are identified in the
front-end by their names. This can be handled in a better way in a future
update where columns that are primary keys are identified by the backend
and sent to the frontend instead.
Also, renamed columns can be handled better by making them read-only in a
future update (now they are editable but they cannot be updated as a column
with the new name does not exist - it produces an error message to the
user).

Waiting for your feedback. Thanks !

On Sat, Jun 15, 2019 at 8:48 AM Yosry Muhammad  wrote:

> Dear all,
>
> This is my first patch of my GSoC project, query tool automatic mode
> detection.
>
> In this patch, the initial (basic) version of the project is implemented.
> In this version, query resultsets are updatable if and only if:
> - All the columns belong to a single table
> - No duplicate columns are available
> - All the primary keys of the table are available
>
> Inserts, updates and deletes work automatically when the resultset is
> updatable.
>
> The 'save' button in the query tool works automatically to save the
> changes in the resultset if the query is the updatable, and saves the query
> to a file otherwise. The 'save as' button stays as is.
>
> I will work on improving and adding features to this version throughout my
> work during the summer according to what has the highest priorities
> (supporting duplicate columns or columns produced by functions or
> aggregations as read-only columns in the results seems like a good next
> move).
>
> Please give me your feedback of the changes I made, and any hints or
> comments that will improve my code in any aspect.
>
> I also have a couple of questions,
> - Should the save button in the query tool work the way I am using it now?
> or should there be a new dedicated button for saving the query to a file?
>
> - What documentations or unit tests should I write? any guidelines here
> would be appreciated.
>
> Thanks a lot!
>
>
> --
> *Yosry Muhammad Yosry*
>
> Computer Engineering student,
> The Faculty of Engineering,
> Cairo University (2021).
> Class representative of CMP 2021.
> https://www.linkedin.com/in/yosrym93/
>


-- 
*Yosry Muhammad Yosry*

Computer Engineering student,
The Faculty of Engineering,
Cairo University (2021).
Class representative of CMP 2021.
https://www.linkedin.com/in/yosrym93/
diff --git a/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py b/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py
index ed60f1e9..2ff18d83 100644
--- a/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py
+++ b/web/pgadmin/tools/sqleditor/utils/is_query_resultset_updatable.py
@@ -37,20 +37,25 @@ def is_query_resultset_updatable(conn, sql_path):
 
 # First check that all the columns belong to a single table
 table_oid = columns_info[0]['table_oid']
-column_numbers = []
+columns = []
 for column in columns_info:
 if column['table_oid'] != table_oid:
 return False, None, None, None
 else:
-column_numbers.append(column['table_column'])
+columns.append({
+'display_name': column['display_name'],
+'column_number': column['table_column']
+})
 
 # Check for duplicate columns
+column_numbers = [col['column_number'] for col in columns]
 is_duplicate_columns = len(column_numbers) != len(set(column_numbers))
 if is_duplicate_columns:
 return False, None, None, None
 
 if conn.connected():
 # Then check that all the primary keys of the table are present
+# and no primary keys are renamed (or other columns renamed to be like primary keys)
 query = render_template(
 "/".join([sql_path, 'primary_keys.sql']),
 obj_id=table_oid
@@ -59,21 +64,36 @@ def is_query_resultset_updatable(conn, sql_path):
 if not status:
 return False, None, None, None
 
-primary_keys_column_numbers = []
+primary_keys_columns = []
 primary_keys = OrderedDict()
 pk_names = []
 
 for row in result['rows']:
 primary_keys[row['attname']] = row['typname']
-primary_keys_column_numbers.append(row['attnum'])
+primary_keys_columns.append({
+'name': row['attname'],
+'column_number': row['attnum']
+})
 pk_names.append(row['attname'])
 
-all_primary_keys_exist = all(elem in column_numbers
- for elem in primary_keys_column_numbers)
-else:
-return False, None, None, None
+# Check that all primary keys exist and that all of them are not renamed
+# and other columns are not renamed to primary key names
+for pk 

Re: [pgAdmin4][Patch]: Feature #4202 Implement new framework to test Reverse Engineering SQL

2019-06-16 Thread Akshay Joshi
Hi Dave/Hackers

On Fri, Jun 14, 2019 at 6:10 PM Akshay Joshi 
wrote:

>
>
> On Fri, Jun 14, 2019 at 1:59 PM Dave Page  wrote:
>
>> Hi
>>
>> On Thu, Jun 13, 2019 at 12:52 PM Akshay Joshi <
>> akshay.jo...@enterprisedb.com> wrote:
>>
>>> Hi Hackers
>>>
>>> I have implemented the new test framework to test the Reverse
>>> Engineering SQL. I have integrated it as a part of API/Regression test
>>> suite. It will work when we run all the test cases or module wise test case.
>>>
>>> *How it works*: Attached patch contains the generic framework to read
>>> all the JSON files from the *tests->version based (example 9.6_plus,
>>> 10_plus or default) folder. *Run all the test scenarios present in the
>>> JSON file in sequential order.
>>>
>>> Format of the JSON file is mentioned in
>>> "web/pgadmin/browser/server_groups/servers/databases/casts/tests/default/test.json"
>>>
>>> For expected SQL we will have following two options:
>>>
>>>- Provide the expected sql in scenario itself as parameter 
>>> *"expected_sql"
>>>: ""*.
>>>- Create a output file with any name in the same directory where the
>>>JSON file resides and specify the parameter "*expected_sql_file":
>>>""*
>>>
>>> Attached patch contains both the above mentioned examples.
>>>
>>> Please review it.
>>>
>>
>> Nice!
>>
>> A few comments:
>>
>> - The scenario name should be "Reverse Engineered SQL Test Cases"
>> - After the scenario name is output, can we output a \n so the next line
>> isn't appended to the name?
>>
>
>Will fix the above.
>
>> - How do we run only the re_sql tests? I tried the obvious ways
>> (e.g. python runtests.py --pkg
>> regression.re_sql.tests.test_resql.ReverseEngineeringSQLTestCase) but got
>> errors. Please add an example to web/regression/README.
>>
>
>It is not a pgadmin module and we have kept it in regression folder, so
> will have to change the existing code. I have tried but facing issues when
> run only  "regression.re_sql.tests", will continue working on this.
>

 Can we add a new parameter  to --pkg "*resql*" to run all the reverse
engineered test cases for all the modules, it just like parameter "*all*"
which is used to run all the regression tests. Following will be the
scenario if we add new parameter:

   - If we run --pkg all, run all the API and resql test cases.
   - If we run --pkg , run the API and resql test cases for
   the specified module list
   - if we run --pkg resql, run all the resql test cases only.


>
>> - Once we have a way to run these tests only, please add a "make
>> check-resql" target to the Makefile.
>> - Can the expected output be formatted in the JSON such that it doesn't
>> use \n, but uses regular line breaks? That would make it easier to
>> copy/paste.
>>
>
> I have tried that during implementation, but JSON does not allow
> line-breaks.
>
>>
>> Thanks.
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
>
> *Sr. Software Architect*
> *EnterpriseDB Software India Private Limited*
> *Mobile: +91 976-788-8246*
>


-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


[pgAdmin][RM3174] Distinguish simple tables from tables that are inherited and from which other tables are inherited

2019-06-16 Thread Aditya Toshniwal
Hi Hackers,

Attached is the patch to change icons for table inheritance (icons by
Chethana Kumar)
Along with this, I have also fixed few other issues/icons found on the way:
1) Dependencies tab for inherited tables/foreign keys shows partial text
(#3994).
2) Dependencies tab for child partition table shows parent partition table
as Function.
3) Dependencies tab for triggers shows trigger functions as plain functions.
4) Dependents tab for partitioned table shows the child partition tables as
normal table instead for partitioned tables.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"


RM3174.patch
Description: Binary data