Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ignore partitions in schema diff #8239

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en_US/preferences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ Use the *Ignore Tablespace* switch to ignores the tablespace while comparing the
Use the *Ignore Whitespace* switch to ignores the whitespace while comparing
the string objects. Whitespace includes space, tabs, and CRLF.

Use the *Ignore Partitions* switch to ignores the partitions while comparing
the partitions tables.

The Storage Node
****************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def compare(self, **kwargs):
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_tablespace = kwargs.get('ignore_tablespace')
ignore_grants = kwargs.get('ignore_grants')
ignore_partitions = kwargs.get('ignore_partitions')

group_name = kwargs.get('group_name')
source_schema_name = kwargs.get('source_schema_name', None)
Expand Down Expand Up @@ -96,7 +97,8 @@ def compare(self, **kwargs):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

def ddl_compare(self, **kwargs):
"""
Expand Down Expand Up @@ -300,6 +302,7 @@ def get_sql_from_submodule_diff(self, **kwargs):
target = kwargs.get('target')
diff_dict = kwargs.get('diff_dict')
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_partitions = kwargs.get('ignore_partitions')

# Get the difference result for source and target columns
col_diff = self.table_col_comp(source, target)
Expand All @@ -314,7 +317,7 @@ def get_sql_from_submodule_diff(self, **kwargs):
diff = self.get_sql_from_table_diff(**target_params)

ignore_sub_modules = ['column', 'constraints']
if self.manager.version < 100000:
if self.manager.version < 100000 or ignore_partitions:
ignore_sub_modules.append('partition')
if self.manager.server_type == 'pg' or self.manager.version < 120000:
ignore_sub_modules.append('compound_trigger')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def compare(self, **kwargs):
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_tablespace = kwargs.get('ignore_tablespace')
ignore_grants = kwargs.get('ignore_grants')
ignore_partitions = kwargs.get('ignore_partitions')

group_name = kwargs.get('group_name')
source_schema_name = kwargs.get('source_schema_name', None)
Expand Down Expand Up @@ -80,7 +81,8 @@ def compare(self, **kwargs):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

def ddl_compare(self, **kwargs):
"""
Expand Down Expand Up @@ -125,6 +127,7 @@ def get_sql_from_submodule_diff(self, **kwargs):
target = kwargs.get('target')
diff_dict = kwargs.get('diff_dict')
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_partitions = kwargs.get('ignore_partitions')
diff = ''

# Get the difference DDL/DML statements for table
Expand Down Expand Up @@ -169,7 +172,8 @@ def get_sql_from_submodule_diff(self, **kwargs):
"source": source,
"target": target,
"target_schema": target_schema,
"ignore_whitespaces": ignore_whitespaces
"ignore_whitespaces": ignore_whitespaces,
"ignore_partitions": ignore_partitions
}
diff = self._compare_source_and_target(
intersect_keys, module_view, source_params,
Expand Down
35 changes: 28 additions & 7 deletions web/pgadmin/tools/schema_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def register_preferences(self):
'in the Schema Diff tab.')
)

self.preference.register(
'display', 'ignore_partitioons',
gettext("Ignore Partitions"), 'boolean', False,
category_label=PREF_LABEL_DISPLAY,
help_str=gettext('Set ignore partitions on or off by default '
'in the drop-down menu near the Compare button '
'in the Schema Diff tab.')
)

blueprint = SchemaDiffModule(MODULE_NAME, __name__, static_url_path='/static')

Expand Down Expand Up @@ -477,6 +485,8 @@ def compare_database(params):
ignore_whitespaces = bool(params['ignore_whitespaces'])
ignore_tablespace = bool(params['ignore_tablespace'])
ignore_grants = bool(params['ignore_grants'])
ignore_partitions = bool(params['ignore_partitions'])


# Fetch all the schemas of source and target database
# Compare them and get the status.
Expand Down Expand Up @@ -506,7 +516,8 @@ def compare_database(params):
node_percent=node_percent, ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)
comparison_result = \
comparison_result + comparison_schema_result

Expand All @@ -530,7 +541,8 @@ def compare_database(params):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

comparison_result = \
comparison_result + comparison_schema_result
Expand All @@ -553,7 +565,8 @@ def compare_database(params):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

comparison_result = \
comparison_result + comparison_schema_result
Expand All @@ -578,7 +591,8 @@ def compare_database(params):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

comparison_result = \
comparison_result + comparison_schema_result
Expand Down Expand Up @@ -623,6 +637,8 @@ def compare_schema(params):
ignore_whitespaces = bool(params['ignore_whitespaces'])
ignore_tablespace = bool(params['ignore_tablespace'])
ignore_grants = bool(params['ignore_grants'])
ignore_partitions = bool(params['ignore_partitions'])

all_registered_nodes = SchemaDiffRegistry.get_registered_nodes()
node_percent = round(100 / len(all_registered_nodes), 2)
total_percent = 0
Expand All @@ -643,7 +659,8 @@ def compare_schema(params):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

comparison_result = \
comparison_result + comparison_schema_result
Expand Down Expand Up @@ -779,6 +796,7 @@ def compare_database_objects(**kwargs):
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_tablespace = kwargs.get('ignore_tablespace')
ignore_grants = kwargs.get('ignore_grants')
ignore_partitions = kwargs.get('ignore_partitions')
comparison_result = []

all_registered_nodes = SchemaDiffRegistry.get_registered_nodes(None,
Expand All @@ -804,7 +822,8 @@ def compare_database_objects(**kwargs):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

if res is not None:
comparison_result = comparison_result + res
Expand Down Expand Up @@ -837,6 +856,7 @@ def compare_schema_objects(**kwargs):
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_tablespace = kwargs.get('ignore_tablespace')
ignore_grants = kwargs.get('ignore_grants')
ignore_partitions = kwargs.get('ignore_partitions')

source_schema_name = None
if is_schema_source_only:
Expand Down Expand Up @@ -875,7 +895,8 @@ def compare_schema_objects(**kwargs):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

if res is not None:
comparison_result = comparison_result + res
Expand Down
4 changes: 3 additions & 1 deletion web/pgadmin/tools/schema_diff/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def compare(self, **kwargs):
ignore_whitespaces = kwargs.get('ignore_whitespaces', False)
ignore_tablespace = kwargs.get('ignore_tablespace', False)
ignore_grants = kwargs.get('ignore_grants', False)
ignore_partitions = kwargs.get('ignore_partitions', False)

group_name = kwargs.get('group_name')
source_schema_name = kwargs.get('source_schema_name', None)
Expand Down Expand Up @@ -106,7 +107,8 @@ def compare(self, **kwargs):
ignore_owner=ignore_owner,
ignore_whitespaces=ignore_whitespaces,
ignore_tablespace=ignore_tablespace,
ignore_grants=ignore_grants)
ignore_grants=ignore_grants,
ignore_partitions=ignore_partitions)

def ddl_compare(self, **kwargs):
"""
Expand Down
8 changes: 6 additions & 2 deletions web/pgadmin/tools/schema_diff/directory_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def _get_identical_and_different_list(intersect_keys, source_dict, target_dict,
target_schema = kwargs.get('target_schema')
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_grants = kwargs.get('ignore_grants', False)
ignore_partitions = kwargs.get('ignore_partitions', False)

for key in intersect_keys:
source_object_id, target_object_id = \
Expand Down Expand Up @@ -357,7 +358,8 @@ def _get_identical_and_different_list(intersect_keys, source_dict, target_dict,
target_params=temp_tgt_params,
source=dict1[key], target=dict2[key], diff_dict=diff_dict,
target_schema=target_schema,
ignore_whitespaces=ignore_whitespaces)
ignore_whitespaces=ignore_whitespaces,
ignore_partitions=ignore_partitions)
else:
temp_src_params = copy.deepcopy(source_params)
temp_tgt_params = copy.deepcopy(target_params)
Expand Down Expand Up @@ -431,6 +433,7 @@ def compare_dictionaries(**kwargs):
ignore_whitespaces = kwargs.get('ignore_whitespaces')
ignore_tablespace = kwargs.get('ignore_tablespace')
ignore_grants = kwargs.get('ignore_grants')
ignore_partitions = kwargs.get('ignore_partitions')

dict1 = copy.deepcopy(source_dict)
dict2 = copy.deepcopy(target_dict)
Expand Down Expand Up @@ -491,7 +494,8 @@ def compare_dictionaries(**kwargs):
"group_name": group_name,
"target_schema": target_schema,
"ignore_whitespaces": ignore_whitespaces,
"ignore_grants": ignore_grants
"ignore_grants": ignore_grants,
"ignore_partitions": ignore_partitions
}

identical, different = _get_identical_and_different_list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const MENUS_COMPARE_CONSTANT = {
COMPARE_IGNORE_OWNER: 1,
COMPARE_IGNORE_WHITESPACE: 2,
COMPARE_IGNORE_TABLESPACE: 3,
COMPARE_IGNORE_GRANTS: 4
COMPARE_IGNORE_GRANTS: 4,
COMPARE_IGNORE_PARTITIONS: 5
};

export const MENUS_FILTER_CONSTANT = {
Expand Down Expand Up @@ -70,5 +71,6 @@ export const IGNORE_OPTION = {
OWNER : gettext('Ignore Owner'),
WHITESPACE : gettext('Ignore Whitespace'),
TABLESPACE: gettext('Ignore Tablespace'),
GRANTS: gettext('Ignore Grant/Revoke')
GRANTS: gettext('Ignore Grant/Revoke'),
PARTITIONS: gettext('Ignore Partitions')
};
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
compareParams.ignoreWhitespaces && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_WHITESPACE);
compareParams.ignoreTablespace && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_TABLESPACE);
compareParams.ignoreGrants && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS);
compareParams.ignorePartitions && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_PARTITIONS);
setSelectedCompare(prefCompareOptions);
} else {
schemaDiffCtx?.preferences_schema_diff?.ignore_owner && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_OWNER);
schemaDiffCtx?.preferences_schema_diff?.ignore_whitespaces && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_WHITESPACE);
schemaDiffCtx?.preferences_schema_diff?.ignore_tablespace && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_TABLESPACE);
schemaDiffCtx?.preferences_schema_diff?.ignore_grants && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS);
schemaDiffCtx?.preferences_schema_diff?.ignore_partitions && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_PARTITIONS);
setSelectedCompare(prefCompareOptions);
}
}, [schemaDiffCtx.preferences_schema_diff]);
Expand Down Expand Up @@ -141,6 +143,7 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
'ignoreWhitespaces': selectedCompare.includes(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_WHITESPACE) ? 1 : 0,
'ignoreTablespace': selectedCompare.includes(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_TABLESPACE) ? 1 : 0,
'ignoreGrants': selectedCompare.includes(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS) ? 1 : 0,
'ignorePartitions': selectedCompare.includes(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_PARTITIONS) ? 1 : 0,
};
let filterParam = selectedFilters;
eventBus.fireEvent(SCHEMA_DIFF_EVENT.TRIGGER_COMPARE_DIFF, { sourceData, targetData, compareParams: compareParam, filterParams: filterParam });
Expand Down Expand Up @@ -194,6 +197,8 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
onClick={() => { selectCompareOption(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_TABLESPACE); }}>{IGNORE_OPTION.TABLESPACE}</PgMenuItem>
<PgMenuItem hasCheck checked={selectedCompare.includes(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS)}
onClick={() => { selectCompareOption(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS); }}>{IGNORE_OPTION.GRANTS}</PgMenuItem>
<PgMenuItem hasCheck checked={selectedCompare.includes(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_PARTITIONS)}
onClick={() => { selectCompareOption(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_PARTITIONS); }}>{IGNORE_OPTION.PARTITIONS}</PgMenuItem>
</PgMenu>
<PgMenu
anchorRef={filterRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export function SchemaDiffCompare({ params }) {
'ignore_whitespaces': compareParams['ignoreWhitespaces'],
'ignore_tablespace': compareParams['ignoreTablespace'],
'ignore_grants': compareParams['ignoreGrants'],
'ignore_partitions': compareParams['ignorePartitions'],
};
let socketEndpoint = 'compare_database';
if (sourceData['scid'] != null && targetData['scid'] != null) {
Expand Down
3 changes: 2 additions & 1 deletion web/pgadmin/tools/schema_diff/tests/test_schema_diff_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def compare(self):
'ignore_owner': 0,
'ignore_whitespaces': 0,
'ignore_tablespace': 0,
'ignore_grants': 0
'ignore_grants': 0,
"ignore_partitions": 0
}
self.socket_client.emit('compare_database', data,
namespace=self.SOCKET_NAMESPACE)
Expand Down