Skip to content

Commit

Permalink
Fixed an issue where Triggers, Rules, Indexes were absent from the Sc…
Browse files Browse the repository at this point in the history
…hema Diff when comparing views. pgadmin-org#7271
  • Loading branch information
akshay-joshi committed Mar 26, 2024
1 parent 1f0a2fd commit e75e212
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 45 deletions.
6 changes: 3 additions & 3 deletions docs/en_US/dbms_job_scheduler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ as a background process for the DBMS_SCHEDULER and DBMS_JOB packages.

The EDB Job Scheduler has a scheduler process that starts when the database cluster starts.
To start the scheduler process, load the EDB Job Scheduler extension using the **shared_preload_libraries**
parameter. After you load the extension, create the extension using the CREATE EXTENSION command.
The database in which you're creating the extension must be listed in the **edb_job_scheduler.database_list**
parameter.
parameter. After you load the extension, create the extension **'edb_job_scheduler'** and **'dbms_scheduler'** using
the CREATE EXTENSION command. The database in which you're creating the extension must be listed in the
**edb_job_scheduler.database_list** parameter.

Instructions for configuring the EDB Job Scheduler can be found in the
`Configuring EDB Job Scheduler <https://www.enterprisedb.com/docs/pg_extensions/edb_job_scheduler/configuring/>`_.
Expand Down
6 changes: 5 additions & 1 deletion docs/en_US/release_notes_8_5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Bundled PostgreSQL Utilities
New features
************

| `Issue #5611 <https://github.com/pgadmin-org/pgadmin4/issues/5611>`_ - Added support for provider, deterministic, version and RULES parameter while creating collation.
| `Issue #7098 <https://github.com/pgadmin-org/pgadmin4/issues/7098>`_ - Added support for EDB Job Scheduler.
| `Issue #7163 <https://github.com/pgadmin-org/pgadmin4/issues/7163>`_ - Added support to exclude multiple tables while taking backup.
| `Issue #7221 <https://github.com/pgadmin-org/pgadmin4/issues/7221>`_ - Added support for UNIX socket in entrypoint.sh for Docker implementation.
Housekeeping
Expand All @@ -31,12 +31,16 @@ Housekeeping
Bug fixes
*********

| `Issue #4413 <https://github.com/pgadmin-org/pgadmin4/issues/4413>`_ - Fixed an issue in Schema Diff where Columns with sequences get altered unnecessarily.
| `Issue #7116 <https://github.com/pgadmin-org/pgadmin4/issues/7116>`_ - Bug fixes and improvements in pgAdmin CLI.
| `Issue #7165 <https://github.com/pgadmin-org/pgadmin4/issues/7165>`_ - Fixed schema diff wrong query generation for table, foreign table and sequence.
| `Issue #7229 <https://github.com/pgadmin-org/pgadmin4/issues/7229>`_ - Fix an issue in table dialog where changing column name was not syncing table constraints appropriately.
| `Issue #7255 <https://github.com/pgadmin-org/pgadmin4/issues/7255>`_ - Fixed an issue where taking backup of a shared server was using server owner's user name.
| `Issue #7262 <https://github.com/pgadmin-org/pgadmin4/issues/7262>`_ - Fix an issue in editor where replace option in query tool edit menu is not working on non-Mac OS.
| `Issue #7268 <https://github.com/pgadmin-org/pgadmin4/issues/7268>`_ - Fix an issue in editor where Format SQL shortcut and multiline selection are not working.
| `Issue #7269 <https://github.com/pgadmin-org/pgadmin4/issues/7269>`_ - Fix an issue in editor where "Use Spaces?" Preference of Editor is not working.
| `Issue #7271 <https://github.com/pgadmin-org/pgadmin4/issues/7271>`_ - Fixed an issue where Triggers, Rules, Indexes were absent from the Schema Diff when comparing views.
| `Issue #7277 <https://github.com/pgadmin-org/pgadmin4/issues/7277>`_ - Fix an issue in query tool where toggle case of selected text loses selection.
| `Issue #7299 <https://github.com/pgadmin-org/pgadmin4/issues/7299>`_ - Fix query tool autocomplete results when cursor is in between the SQL query.
| `Issue #7305 <https://github.com/pgadmin-org/pgadmin4/issues/7305>`_ - Fix an issue in query tool where custom keyboard shortcuts are not working for some.
| `Issue #7308 <https://github.com/pgadmin-org/pgadmin4/issues/7308>`_ - Fixed issue related to email authentication of Two-factor authentication.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
constraints.foreign_key import utils as fkey_utils
from .schema_diff_utils import SchemaDiffTableCompare
from .schema_diff_table_utils import SchemaDiffTableCompare
from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
columns import utils as column_utils
from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SchemaDiffTableCompare(SchemaDiffObjectCompare):
'relacl_str', 'setting']

column_keys_to_ignore = ['atttypid', 'edit_types', 'elemoid', 'seqrelid',
'indkey']
'indkey', 'seqtypid', 'defval']

constraint_keys_to_ignore = ['relname', 'nspname', 'parent_tbl',
'attrelid', 'adrelid', 'fknsp', 'confrelid',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ WHERE
rw.oid = {{ rid }}
{% endif %}
{% if schema_diff %}
AND rw.rulename != '_RETURN'
AND CASE WHEN (SELECT COUNT(*) FROM pg_catalog.pg_depend
WHERE objid = rw.oid AND deptype = 'e') > 0 THEN FALSE ELSE TRUE END
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ def fetch_tables(self, sid, did, scid, tid=None, with_serial_cols=False):
BaseTableView._get_sub_module_data_for_compare(
self, sid, did, scid, data, row)
res[row['name']] = data
res[row['name']] = data

return True, res

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
make_response as ajax_response, gone
from pgadmin.utils.driver import get_driver
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.compare import SchemaDiffObjectCompare
from .schema_diff_view_utils import SchemaDiffViewCompare
from pgadmin.utils import html, does_utility_exist, get_server
from pgadmin.model import Server
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
Expand Down Expand Up @@ -260,6 +260,24 @@ def wrap(*args, **kwargs):
self.column_template_path = 'columns/sql/#{0}#'.format(
self.manager.version)

# Template for trigger node
self.trigger_template_path = 'triggers/sql/{0}/#{1}#'.format(
self.manager.server_type, self.manager.version)

# Template for compound trigger node
self.compound_trigger_template_path = (
'compound_triggers/sql/{0}/#{1}#'.format(
self.manager.server_type, self.manager.version))

# Template for rules node
self.rules_template_path = 'rules/sql'

# Submodule list for schema diff
self.view_sub_modules = ['rule', 'trigger']
if (self.manager.server_type == 'ppas' and
self.manager.version >= 120000):
self.view_sub_modules.append('compound_trigger')

try:
self.allowed_acls = render_template(
"/".join([self.template_path, self._ALLOWED_PRIVS_JSON])
Expand All @@ -273,7 +291,7 @@ def wrap(*args, **kwargs):
return wrap


class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffViewCompare):
"""
This class is responsible for generating routes for view node.
Expand Down Expand Up @@ -374,8 +392,6 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
{'get': 'get_toast_table_vacuum'}]
})

keys_to_ignore = ['oid', 'schema', 'xmin', 'oid-2', 'setting']

def __init__(self, *args, **kwargs):
"""
Initialize the variables used by methods of ViewNode.
Expand Down Expand Up @@ -510,7 +526,7 @@ def _fetch_properties(self, scid, vid):
# sending result to formtter
frmtd_reslt = self.formatter(result)

# merging formated result with main result again
# merging formatted result with main result again
result.update(frmtd_reslt)

return True, result
Expand Down Expand Up @@ -1140,7 +1156,8 @@ def _generate_and_return_trigger_sql(self, vid, data, display_comments,
[self.ct_trigger_temp_path,
'sql/{0}/#{1}#/create.sql'.format(
self.manager.server_type, self.manager.version)]),
data=res_rows, display_comments=display_comments)
data=res_rows, display_comments=display_comments,
conn=self.conn)
sql_data += '\n'
sql_data += SQL

Expand Down Expand Up @@ -1264,7 +1281,8 @@ def get_trigger_sql(self, vid, display_comments=True):
[self.trigger_temp_path,
'sql/{0}/#{1}#/create.sql'.format(
self.manager.server_type, self.manager.version)]),
data=res_rows, display_comments=display_comments)
data=res_rows, display_comments=display_comments,
conn=self.conn)
sql_data += '\n'
sql_data += SQL

Expand Down Expand Up @@ -1310,7 +1328,8 @@ def get_index_sql(self, did, vid, display_comments=True):
SQL = render_template("/".join(
[self.index_temp_path,
'sql/#{0}#/create.sql'.format(self.manager.version)]),
data=data, display_comments=display_comments)
data=data, display_comments=display_comments,
conn=self.conn)
sql_data += '\n'
sql_data += SQL
return sql_data
Expand Down Expand Up @@ -1680,6 +1699,19 @@ def insert_sql(self, gid, sid, did, scid, vid):

return ajax_response(response=sql)

def _get_sub_module_data_for_compare(self, sid, did, scid, data, vid):
# Get sub module data of a specified view for object
# comparison
for module in self.view_sub_modules:
module_view = SchemaDiffRegistry.get_node_view(module)
if module_view.blueprint.server_type is None or \
self.manager.server_type in \
module_view.blueprint.server_type:
sub_data = module_view.fetch_objects_to_compare(
sid=sid, did=did, scid=scid, tid=vid,
oid=None)
data[module] = sub_data

@check_precondition
def fetch_objects_to_compare(self, sid, did, scid, oid=None):
"""
Expand Down Expand Up @@ -1707,6 +1739,9 @@ def fetch_objects_to_compare(self, sid, did, scid, oid=None):
for row in views['rows']:
status, data = self._fetch_properties(scid, row['oid'])
if status:
# Fetch the data of sub module
self._get_sub_module_data_for_compare(
sid, did, scid, data, row['oid'])
res[row['name']] = data
else:
status, data = self._fetch_properties(scid, oid)
Expand All @@ -1717,7 +1752,7 @@ def fetch_objects_to_compare(self, sid, did, scid, oid=None):

return res

def get_sql_from_diff(self, **kwargs):
def get_sql_from_view_diff(self, **kwargs):
"""
This function is used to get the DDL/DML statements.
:param kwargs
Expand All @@ -1727,15 +1762,15 @@ def get_sql_from_diff(self, **kwargs):
sid = kwargs.get('sid')
did = kwargs.get('did')
scid = kwargs.get('scid')
oid = kwargs.get('oid')
data = kwargs.get('data', None)
oid = kwargs.get('tid')
diff_data = kwargs.get('diff_data', None)
drop_sql = kwargs.get('drop_sql', False)
target_schema = kwargs.get('target_schema', None)

if data:
if diff_data:
if target_schema:
data['schema'] = target_schema
sql, _ = self.getSQL(gid, sid, did, data, oid)
diff_data['schema'] = target_schema
sql, _ = self.getSQL(gid, sid, did, diff_data, oid)
if sql.find('DROP VIEW') != -1:
sql = gettext("""
-- Changing the columns in a view requires dropping and re-creating the view.
Expand All @@ -1755,6 +1790,60 @@ def get_sql_from_diff(self, **kwargs):
json_resp=False)
return sql

def get_submodule_template_path(self, module_name):
"""
This function is used to get the template path based on module name.
:param module_name:
:return:
"""
template_path = None
if module_name == 'trigger':
template_path = self.trigger_template_path
elif module_name == 'rule':
template_path = self.rules_template_path
elif module_name == 'compound_trigger':
template_path = self.compound_trigger_template_path

return template_path

def get_view_submodules_dependencies(self, **kwargs):
"""
This function is used to get the dependencies of view and it's
submodules.
:param kwargs:
:return:
"""
vid = kwargs['tid']
view_dependencies = []
view_deps = self.get_dependencies(self.conn, vid)
if len(view_deps) > 0:
view_dependencies.extend(view_deps)

# Iterate all the submodules of the table and fetch the dependencies.
for module in self.view_sub_modules:
module_view = SchemaDiffRegistry.get_node_view(module)
template_path = self.get_submodule_template_path(module)

SQL = render_template("/".join([template_path,
'nodes.sql']), tid=vid)
status, rset = self.conn.execute_2darray(SQL)
if not status:
return internal_server_error(errormsg=rset)

for row in rset['rows']:
result = module_view.get_dependencies(
self.conn, row['oid'], where=None,
show_system_objects=None, is_schema_diff=True)
if len(result) > 0:
view_dependencies.extend(result)

# Remove the same table from the dependency list
for item in view_dependencies:
if 'oid' in item and item['oid'] == vid:
view_dependencies.remove(item)

return view_dependencies


# Override the operations for materialized view
mview_operations = {
Expand Down
Loading

0 comments on commit e75e212

Please sign in to comment.