Fixed a schema diff issue in which user mappings were not compared correctly. Fixes #6956

This commit is contained in:
Akshay Joshi 2022-03-04 17:21:30 +05:30
parent 4033bf3748
commit 1af431dcc2
5 changed files with 42 additions and 6 deletions

View File

@ -20,6 +20,7 @@ Housekeeping
Bug fixes
*********
| `Issue #6956 <https://redmine.postgresql.org/issues/6956>`_ - Fixed a schema diff issue in which user mappings were not compared correctly.
| `Issue #6991 <https://redmine.postgresql.org/issues/6991>`_ - Fixed an issue where pgadmin cannot connect to LDAP when STARTTLS is required before bind.
| `Issue #6999 <https://redmine.postgresql.org/issues/6999>`_ - Fixed an issue where a warning is flashed every time for an email address when authentication sources are internal and ldap.
| `Issue #7124 <https://redmine.postgresql.org/issues/7124>`_ - Fixed the schema diff issue where tables have different column positions and a column has a default value.

View File

@ -25,6 +25,7 @@ from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
from pgadmin.utils.constants import PGADMIN_STRING_SEPARATOR
class UserMappingModule(CollectionNodeModule):
@ -916,7 +917,14 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
# the empty list.
if 'umoptions' in data and data['umoptions'] is None:
data['umoptions'] = []
res[row['name']] = data
mapping_name = row['name']
if 'srvname' in data:
mapping_name = \
row['name'] + PGADMIN_STRING_SEPARATOR + \
data['srvname']
res[mapping_name] = data
return res

View File

@ -5,7 +5,7 @@ FROM pg_catalog.pg_foreign_server srv
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=srv.oid AND des.objsubid=0 AND des.classoid='pg_foreign_server'::regclass)
WHERE srv.oid = {{fserid}}::oid
{% elif fsid or umid %}
SELECT u.umid AS oid, u.usename AS name, u.srvid AS fsid, umoptions AS umoptions, fs.srvfdw AS fdwid
SELECT u.umid AS oid, u.usename AS name, fs.srvname, u.srvid AS fsid, umoptions AS umoptions, fs.srvfdw AS fdwid
FROM pg_catalog.pg_user_mappings u
LEFT JOIN pg_catalog.pg_foreign_server fs ON fs.oid = u.srvid
{% if fsid %} WHERE u.srvid = {{fsid}}::oid {% endif %} {% if umid %} WHERE u.umid= {{umid}}::oid {% endif %}

View File

@ -14,6 +14,7 @@ import string
from pgadmin.tools.schema_diff.model import SchemaDiffModel
from flask import current_app
from pgadmin.utils.preferences import Preferences
from pgadmin.utils.constants import PGADMIN_STRING_SEPARATOR
count = 1
@ -22,6 +23,19 @@ list_keys_array = ['name', 'colname', 'argid', 'token', 'option', 'conname',
'fsrvoption', 'umoption']
def _get_user_mapping_name(user_mapping_name):
"""
This function is used to check the pgadmin string separator in the
specific string and split that.
"""
mapping_name = user_mapping_name
if mapping_name.find(PGADMIN_STRING_SEPARATOR):
mapping_name = mapping_name.split(PGADMIN_STRING_SEPARATOR)[0]
return mapping_name
def _get_source_list(**kwargs):
"""
Get only source list.
@ -74,11 +88,15 @@ def _get_source_list(**kwargs):
view_object.conn, source_object_id, where=None,
show_system_objects=None, is_schema_diff=True)
title = item
if node == 'user_mapping':
title = _get_user_mapping_name(item)
source_only.append({
'id': count,
'type': node,
'label': node_label,
'title': item,
'title': title,
'oid': source_object_id,
'status': SchemaDiffModel.COMPARISON_STATUS['source_only'],
'source_ddl': source_ddl,
@ -151,11 +169,15 @@ def _get_target_list(removed, target_dict, node, target_params, view_object,
{'drop_sql': True})
diff_ddl = view_object.get_sql_from_diff(**temp_tgt_params)
title = item
if node == 'user_mapping':
title = _get_user_mapping_name(item)
target_only.append({
'id': count,
'type': node,
'label': node_label,
'title': item,
'title': title,
'oid': target_object_id,
'status': SchemaDiffModel.COMPARISON_STATUS['target_only'],
'source_ddl': '',
@ -315,11 +337,15 @@ def _get_identical_and_different_list(intersect_keys, source_dict, target_dict,
{'data': diff_dict, 'target_schema': target_schema})
diff_ddl = view_object.get_sql_from_diff(**temp_tgt_params)
title = key
if node == 'user_mapping':
title = _get_user_mapping_name(key)
different.append({
'id': count,
'type': node,
'label': node_label,
'title': key,
'title': title,
'oid': source_object_id,
'source_oid': source_object_id,
'target_oid': target_object_id,
@ -699,7 +725,7 @@ def parse_acl(source, target, diff_dict):
:param target: Target Dict
:param diff_dict: Difference Dict
"""
acl_keys = ['datacl', 'relacl', 'typacl', 'pkgacl']
acl_keys = ['datacl', 'relacl', 'typacl', 'pkgacl', 'fsrvacl']
key = is_key_exists(acl_keys, source)
# If key is not found in source then check the key is available

View File

@ -26,6 +26,7 @@ PREF_LABEL_RESULTS_GRID = gettext('Results grid')
PREF_LABEL_SQL_FORMATTING = gettext('SQL formatting')
PREF_LABEL_TABS_SETTINGS = gettext('Tab settings')
PGADMIN_STRING_SEPARATOR = '_$PGADMIN$_'
PGADMIN_NODE = 'pgadmin.node.%s'
UNAUTH_REQ = "Unauthorized request."
SERVER_CONNECTION_CLOSED = gettext(