コード例 #1
0
ファイル: schema_diff_utils.py プロジェクト: wilj/pgadmin4
    def _compare_source_and_target(self, intersect_keys, module_view,
                                   source_params, target_params, diff,
                                   **kwargs):
        dict1 = kwargs['dict1']
        dict2 = kwargs['dict2']
        ignore_whitespaces = kwargs['ignore_whitespaces']
        source = kwargs['source']
        target = kwargs['target']
        for key in intersect_keys:
            # Recursively Compare the two dictionary
            if not are_dictionaries_identical(
                    dict1[key], dict2[key], ignore_whitespaces,
                    self.keys_to_ignore):
                diff_ddl = module_view.ddl_compare(
                    source_params=source_params,
                    target_params=target_params,
                    source=dict1[key],
                    target=dict2[key],
                    comp_status='different',
                    parent_source_data=source,
                    parent_target_data=target
                )

                diff += '\n' + diff_ddl
        return diff
コード例 #2
0
    def get_sql_from_submodule_diff(self, source_params, target_params,
                                    target_schema, source, target, diff_dict):
        """
        This function returns the DDL/DML statements of the
        submodules of table based on the comparison status.

        :param source_params:
        :param target_params:
        :param target_schema:
        :param source:
        :param target:
        :param diff_dict:
        :return:
        """
        # Get the difference result for source and target columns
        col_diff = self.table_col_comp(source, target)
        diff_dict.update(col_diff)

        # Get the difference result for source and target constraints
        pk_diff = self.table_constraint_comp(source, target)
        diff_dict.update(pk_diff)

        # Get the difference DDL/DML statements for table
        target_params['diff_data'] = diff_dict
        diff = self.get_sql_from_table_diff(**target_params)

        ignore_sub_modules = ['column', 'constraints']
        if self.manager.version < 100000:
            ignore_sub_modules.append('partition')
        if self.manager.server_type == 'pg' or self.manager.version < 120000:
            ignore_sub_modules.append('compound_trigger')

        # Iterate through all the sub modules of the table
        for module in self.blueprint.submodules:
            if module.NODE_TYPE not in ignore_sub_modules:
                module_view = \
                    SchemaDiffRegistry.get_node_view(module.NODE_TYPE)

                if module.NODE_TYPE == 'partition' and \
                    ('is_partitioned' in source and source['is_partitioned'])\
                        and ('is_partitioned' in target and
                             target['is_partitioned']):
                    target_ddl = module_view.ddl_compare(
                        target_params=target_params,
                        parent_source_data=source,
                        parent_target_data=target)

                    diff += '\n' + target_ddl
                elif module.NODE_TYPE != 'partition':
                    dict1 = copy.deepcopy(source[module.NODE_TYPE])
                    dict2 = copy.deepcopy(target[module.NODE_TYPE])

                    # Find the duplicate keys in both the dictionaries
                    dict1_keys = set(dict1.keys())
                    dict2_keys = set(dict2.keys())
                    intersect_keys = dict1_keys.intersection(dict2_keys)

                    # Keys that are available in source and missing in target.
                    added = dict1_keys - dict2_keys
                    for item in added:
                        source_ddl = module_view.ddl_compare(
                            source_params=source_params,
                            target_params=target_params,
                            source=dict1[item],
                            target=None,
                            target_schema=target_schema,
                            comp_status='source_only')

                        diff += '\n' + source_ddl

                    # Keys that are available in target and missing in source.
                    removed = dict2_keys - dict1_keys
                    for item in removed:
                        target_ddl = module_view.ddl_compare(
                            source_params=source_params,
                            target_params=target_params,
                            source=None,
                            target=dict2[item],
                            target_schema=target_schema,
                            comp_status='target_only')

                        diff += '\n' + target_ddl

                    # Keys that are available in both source and target.
                    for key in intersect_keys:
                        # Recursively Compare the two dictionary
                        if not are_dictionaries_identical(
                                dict1[key], dict2[key], self.keys_to_ignore):

                            diff_ddl = module_view.ddl_compare(
                                source_params=source_params,
                                target_params=target_params,
                                source=dict1[key],
                                target=dict2[key],
                                target_schema=target_schema,
                                comp_status='different',
                                parent_source_data=source,
                                parent_target_data=target)

                            diff += '\n' + diff_ddl

        return diff