def get_sql_from_diff(self, **kwargs): """ This function is used to get the DDL/DML statements. :param kwargs: :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') fid = kwargs.get('fdwid') fsid = kwargs.get('fsid') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(data=data, fsid=fsid, umid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, fid=fid, fsid=fsid, umid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, fid=fid, fsid=fsid, umid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, UserMappingView, 'Database') UserMappingView.register_node_view(blueprint)
:param kwargs: :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(data=data, lid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, lid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, lid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, LanguageView, 'Database') LanguageView.register_node_view(blueprint)
:param kwargs: :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql = self.get_sql(data=data, etid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, etid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, etid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, EventTriggerView, 'Database') EventTriggerView.register_node_view(blueprint)
return res def get_sql_from_diff(self, **kwargs): """ This function is used to get the DDL/DML statements. :param kwargs :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') scid = kwargs.get('scid') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(gid, sid, data, scid, oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, syid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, syid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, SynonymView) SynonymView.register_node_view(blueprint)
def connect_database(sid, did): server = Server.query.filter_by(id=sid).first() view = SchemaDiffRegistry.get_node_view('database') return view.connect(server.servergroup_id, sid, did)
def compare_schema_objects(**kwargs): """ This function is used to compare the specified schema and their children. :param kwargs: :return: """ trans_id = kwargs.get('trans_id') session_obj = kwargs.get('session_obj') source_sid = kwargs.get('source_sid') source_did = kwargs.get('source_did') source_scid = kwargs.get('source_scid') target_sid = kwargs.get('target_sid') target_did = kwargs.get('target_did') target_scid = kwargs.get('target_scid') schema_name = kwargs.get('schema_name') diff_model_obj = kwargs.get('diff_model_obj') total_percent = kwargs.get('total_percent') node_percent = kwargs.get('node_percent') is_schema_source_only = kwargs.get('is_schema_source_only', False) source_schema_name = None if is_schema_source_only: driver = get_driver(PG_DEFAULT_DRIVER) source_schema_name = driver.qtIdent(None, schema_name) comparison_result = [] all_registered_nodes = SchemaDiffRegistry.get_registered_nodes() for node_name, node_view in all_registered_nodes.items(): view = SchemaDiffRegistry.get_node_view(node_name) if hasattr(view, 'compare'): if schema_name == 'Schema Objects': msg = gettext('Comparing {0} '). \ format(gettext(view.blueprint.collection_label)) else: msg = gettext('Comparing {0} of schema \'{1}\''). \ format(gettext(view.blueprint.collection_label), gettext(schema_name)) app.logger.debug(msg) diff_model_obj.set_comparison_info(msg, total_percent) # Update the message and total percentage in session object update_session_diff_transaction(trans_id, session_obj, diff_model_obj) res = view.compare(source_sid=source_sid, source_did=source_did, source_scid=source_scid, target_sid=target_sid, target_did=target_did, target_scid=target_scid, group_name=gettext(schema_name), source_schema_name=source_schema_name) if res is not None: comparison_result = comparison_result + res total_percent = total_percent + node_percent # if total_percent is more then 100 then set it to less then 100 if total_percent >= 100: total_percent = 96 return comparison_result, total_percent
gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: if 'pub' in data and type(data['pub']) == str: # Convert publication details to list data['pub'] = data['pub'].split(',,') sql, name = self.get_sql(data=data, subid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, subid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, subid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, SubscriptionView, 'Database') SubscriptionView.register_node_view(blueprint)
sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(gid=gid, sid=sid, did=did, data=data, fid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, fid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, fid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, ForeignDataWrapperView, 'Database') ForeignDataWrapperView.register_node_view(blueprint)
if 'event' in diff_dict or 'type' in diff_dict: delete_sql = self.get_sql_from_diff(gid=1, sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], plid=target['oid'], drop_req=True) diff = self.get_sql_from_diff(gid=src_params['gid'], sid=src_params['sid'], did=src_params['did'], scid=src_params['scid'], tid=src_params['tid'], plid=source['oid'], diff_schema=target_schema) return delete_sql + diff diff = self.get_sql_from_diff(gid=tgt_params['gid'], sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], plid=target['oid'], data=diff_dict) return '\n' + diff SchemaDiffRegistry(blueprint.node_type, RowSecurityView, 'table') RowSecurityView.register_node_view(blueprint)
""" gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') scid = kwargs.get('scid') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) target_schema = kwargs.get('target_schema', None) if data: if target_schema: data['schema'] = target_schema sql, name = self.get_sql(gid=gid, sid=sid, data=data, scid=scid, coid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, coid=oid, only_sql=True) elif target_schema: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, coid=oid, target_schema=target_schema, json_resp=False) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, coid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, CollationView) CollationView.register_node_view(blueprint)
where=None, show_system_objects=None, is_schema_diff=True) if len(domain_deps) > 0: domain_dependencies.extend(domain_deps) # Get Domain Constraints SQL = render_template("/".join( [self.template_path, self._GET_CONSTRAINTS_SQL]), doid=object_id) status, res = self.conn.execute_dict(SQL) if not status: return False, internal_server_error(errormsg=res) # Get the domain constraints dependencies. for row in res['rows']: constraint_deps = super().get_dependencies( conn, row['conoid'], where=None, show_system_objects=None, is_schema_diff=True) if len(constraint_deps) > 0: domain_dependencies.extend(constraint_deps) return domain_dependencies SchemaDiffRegistry(blueprint.node_type, DomainView) DomainView.register_node_view(blueprint)
sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(gid=gid, sid=sid, did=did, data=data, cid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, cid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, cid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, CastView, 'Database') CastView.register_node_view(blueprint)
def get_sql_from_diff(self, **kwargs): """ This function is used to get the DDL/DML statements. :param kwargs :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') scid = kwargs.get('scid') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, data=data, tid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, tid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, tid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, FtsTemplateView) FtsTemplateView.register_node_view(blueprint)
data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid, data=data, cfgid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, cfgid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, cfgid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, FtsConfigurationView) FtsConfigurationView.register_node_view(blueprint)
data=data, dcid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, dcid=oid, only_sql=True) elif diff_schema: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, dcid=oid, diff_schema=diff_schema, json_resp=False) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, dcid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, FtsDictionaryView) FtsDictionaryView.register_node_view(blueprint)
data['columns'] = tmp_columns tmp_constraints = [] if 'constraints' in data: if 'added' in data['constraints']: for item in data['constraints']['added']: tmp_constraints.append(item) if 'changed' in data['constraints']: for item in data['constraints']['changed']: tmp_constraints.append(item) data['constraints'] = tmp_constraints tmp_ftoptions = [] if 'ftoptions' in old_data: tmp_ftoptions = old_data['ftoptions'] if 'ftoptions' in data: if 'added' in data['ftoptions']: for item in data['ftoptions']['added']: tmp_ftoptions.append(item) if 'changed' in data['ftoptions']: for item in data['ftoptions']['changed']: tmp_ftoptions.append(item) if 'deleted' in data['ftoptions']: for item in data['ftoptions']['deleted']: tmp_ftoptions.remove(item) data['ftoptions'] = tmp_ftoptions SchemaDiffRegistry(blueprint.node_type, ForeignTableView) ForeignTableView.register_node_view(blueprint)
def compare_database(trans_id, source_sid, source_did, target_sid, target_did): """ This function will compare the two databases. """ # Check the pre validation before compare status, error_msg, diff_model_obj, session_obj = \ compare_pre_validation(trans_id, source_sid, target_sid) if not status: return error_msg comparison_result = [] diff_model_obj.set_comparison_info(COMPARE_MSG, 0) update_session_diff_transaction(trans_id, session_obj, diff_model_obj) try: # Fetch all the schemas of source and target database # Compare them and get the status. schema_result = fetch_compare_schemas(source_sid, source_did, target_sid, target_did) total_schema = len(schema_result['source_only']) + len( schema_result['target_only']) + len( schema_result['in_both_database']) node_percent = 0 if total_schema > 0: node_percent = round( 100 / (total_schema * len(SchemaDiffRegistry.get_registered_nodes()))) total_percent = 0 # Compare Database objects comparison_schema_result, total_percent = \ compare_database_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, target_sid=target_sid, target_did=target_did, diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent) comparison_result = \ comparison_result + comparison_schema_result # Compare Schema objects if 'source_only' in schema_result and \ len(schema_result['source_only']) > 0: for item in schema_result['source_only']: comparison_schema_result, total_percent = \ compare_schema_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, source_scid=item['scid'], target_sid=target_sid, target_did=target_did, target_scid=None, schema_name=item['schema_name'], diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent, is_schema_source_only=True) comparison_result = \ comparison_result + comparison_schema_result if 'target_only' in schema_result and \ len(schema_result['target_only']) > 0: for item in schema_result['target_only']: comparison_schema_result, total_percent = \ compare_schema_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, source_scid=None, target_sid=target_sid, target_did=target_did, target_scid=item['scid'], schema_name=item['schema_name'], diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent) comparison_result = \ comparison_result + comparison_schema_result # Compare the two schema present in both the databases if 'in_both_database' in schema_result and \ len(schema_result['in_both_database']) > 0: for item in schema_result['in_both_database']: comparison_schema_result, total_percent = \ compare_schema_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, source_scid=item['src_scid'], target_sid=target_sid, target_did=target_did, target_scid=item['tar_scid'], schema_name=item['schema_name'], diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent) comparison_result = \ comparison_result + comparison_schema_result msg = gettext("Successfully compare the specified databases.") total_percent = 100 diff_model_obj.set_comparison_info(msg, total_percent) # Update the message and total percentage done in session object update_session_diff_transaction(trans_id, session_obj, diff_model_obj) except Exception as e: app.logger.exception(e) return make_json_response(data=comparison_result)
target, ignore_keys=self.keys_to_ignore, difference={}) required_create_keys = ['columns'] create_req = IndexesView._check_for_create_req( required_create_keys, diff_dict) if create_req: diff = self.get_sql_from_index_diff(sid=src_params['sid'], did=src_params['did'], scid=src_params['scid'], tid=src_params['tid'], idx=source['oid'], diff_schema=target_schema, drop_req=True) else: diff = self.get_sql_from_index_diff(sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], idx=target['oid'], data=diff_dict) return diff SchemaDiffRegistry(blueprint.node_type, IndexesView, 'table') IndexesView.register_node_view(blueprint)
:param kwargs: :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.get_sql(data=data, pbid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, pbid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, pbid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, PublicationView, 'Database') PublicationView.register_node_view(blueprint)
def get_sql_from_diff(self, **kwargs): """ This function is used to get the DDL/DML statements. :param kwargs :return: """ gid = kwargs.get('gid') sid = kwargs.get('sid') did = kwargs.get('did') oid = kwargs.get('oid') data = kwargs.get('data', None) drop_sql = kwargs.get('drop_sql', False) if data: sql, name = self.getSQL(gid=gid, sid=sid, did=did, data=data, eid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, eid=oid, only_sql=True) else: sql = self.sql(gid=gid, sid=sid, did=did, eid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, ExtensionView, 'Database') # Register and add ExtensionView as blueprint ExtensionView.register_node_view(blueprint)
old_data = res['rows'][0] old_data = self._formatter(old_data, scid) # Privileges self.format_request_acls(old_data, specific=['nspacl']) # Render sql from create & alter sql using properties & acl data SQL = '' SQL = render_template( "/".join([self.template_path, self._SQL_PREFIX + self._CREATE_SQL]), _=gettext, data=old_data, conn=self.conn, add_not_exists_clause=True ) sql_header = """ -- CATALOG: {0} -- DROP SCHEMA IF EXISTS {0}; """.format(old_data['name']) SQL = sql_header + SQL return ajax_response(response=SQL.strip("\n")) SchemaDiffRegistry(schema_blueprint.node_type, SchemaView) SchemaView.register_node_view(schema_blueprint) CatalogView.register_node_view(catalog_blueprint)
def get_sql_from_submodule_diff(self, **kwargs): """ This function returns the DDL/DML statements of the submodules of table based on the comparison status. :param kwargs: :return: """ source_params = kwargs.get('source_params') target_params = kwargs.get('target_params') target_schema = kwargs.get('target_schema') source = kwargs.get('source') target = kwargs.get('target') diff_dict = kwargs.get('diff_dict') # 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 diff = SchemaDiffTableCompare._compare_source_only( added, module_view, source_params, target_params, dict1, diff, target_schema) # Keys that are available in target and missing in source. removed = dict2_keys - dict1_keys diff = SchemaDiffTableCompare._compare_target_only( removed, module_view, source_params, target_params, dict2, diff, target_schema) # Keys that are available in both source and target. other_param = { "dict1": dict1, "dict2": dict2, "source": source, "target": target, "target_schema": target_schema } diff = self._compare_source_and_target( intersect_keys, module_view, source_params, target_params, diff, **other_param) return diff
This function gets the dependents and returns an ajax response for the database. Args: gid: Server Group ID sid: Server ID did: Database ID """ dependents_result = self.get_dependents(self.conn, did) if \ self.conn.connected() else [] return ajax_response(response=dependents_result, status=200) @check_precondition() def dependencies(self, gid, sid, did): """ This function gets the dependencies and returns an ajax response for the database. Args: gid: Server Group ID sid: Server ID did: Database ID """ dependencies_result = self.get_dependencies(self.conn, did) if \ self.conn.connected() else [] return ajax_response(response=dependencies_result, status=200) SchemaDiffRegistry(blueprint.node_type, DatabaseView) DatabaseView.register_node_view(blueprint)
info=gettext("Partition dropped")) except Exception as e: return internal_server_error(errormsg=str(e)) def ddl_compare(self, **kwargs): """ This function returns the DDL/DML statements based on the comparison status. :param kwargs: :return: """ tgt_params = kwargs.get('target_params') parent_source_data = kwargs.get('parent_source_data') parent_target_data = kwargs.get('parent_target_data') diff = self.get_sql_from_diff(sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], source_data=parent_source_data, target_data=parent_target_data) return diff + '\n' SchemaDiffRegistry(blueprint.node_type, PartitionsView, 'table') PartitionsView.register_node_view(blueprint)
data['schema'] = diff_schema sql, name = self.getSQL(gid, sid, did, data, scid, oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, pkgid=oid, only_sql=True) elif diff_schema: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pkgid=oid, diff_schema=diff_schema, json_resp=False) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pkgid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, PackageView) PackageView.register_node_view(blueprint)
data=data, pid=oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, pid=oid, only_sql=True) elif target_schema: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pid=oid, target_schema=target_schema, json_resp=False) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, FtsParserView) FtsParserView.register_node_view(blueprint)
elif comp_status == 'target_only': diff = self.get_sql_from_diff(gid=tgt_params['gid'], sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], oid=target['oid'], drop_sql=True) elif comp_status == 'different': diff_dict = directory_diff(source, target, ignore_keys=self.keys_to_ignore, difference={}) diff_dict.update(parce_acl(source, target)) diff = self.get_sql_from_diff(gid=tgt_params['gid'], sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], oid=target['oid'], source_schema=source['schema'], diff_schema=target_schema, data=diff_dict) return diff SchemaDiffRegistry(blueprint.node_type, RuleView, 'table') RuleView.register_node_view(blueprint)
data['schema'] = diff_schema sql, name = self.get_SQL(gid, sid, did, data, scid, oid) else: if drop_sql: sql = self.delete(gid=gid, sid=sid, did=did, scid=scid, seid=oid, only_sql=True) elif diff_schema: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, seid=oid, diff_schema=diff_schema, json_resp=False) else: sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, seid=oid, json_resp=False) return sql SchemaDiffRegistry(blueprint.node_type, SequenceView) SequenceView.register_node_view(blueprint)
oid=source['oid'], target_schema=target_schema) elif comp_status == 'target_only': diff = self.get_sql_from_diff(gid=tgt_params['gid'], sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], oid=target['oid'], drop_sql=True) elif comp_status == 'different': diff_dict = directory_diff(source, target, ignore_keys=self.keys_to_ignore, difference={}) parse_acl(source, target, diff_dict) diff = self.get_sql_from_diff(gid=tgt_params['gid'], sid=tgt_params['sid'], did=tgt_params['did'], scid=tgt_params['scid'], tid=tgt_params['tid'], oid=target['oid'], data=diff_dict) return diff SchemaDiffRegistry(blueprint.node_type, CompoundTriggerView, 'table') CompoundTriggerView.register_node_view(blueprint)
def compare(trans_id, source_sid, source_did, target_sid, target_did): """ This function will compare the two schemas. """ # Check the transaction and connection status status, error_msg, diff_model_obj, session_obj = \ check_transaction_status(trans_id) if error_msg == gettext('Transaction ID not found in the session.'): return make_json_response(success=0, errormsg=error_msg, status=404) # Server version compatibility check status, msg = check_version_compatibility(source_sid, target_sid) if not status: return make_json_response(success=0, errormsg=msg, status=428) comparison_result = [] diff_model_obj.set_comparison_info(gettext("Comparing objects..."), 0) update_session_diff_transaction(trans_id, session_obj, diff_model_obj) try: pref = Preferences.module('schema_diff') ignore_whitespaces = pref.preference('ignore_whitespaces').get() # Fetch all the schemas of source and target database # Compare them and get the status. schema_result = fetch_compare_schemas(source_sid, source_did, target_sid, target_did) total_schema = len(schema_result['source_only']) + len( schema_result['target_only']) + len( schema_result['in_both_database']) node_percent = round( 100 / (total_schema * len(SchemaDiffRegistry.get_registered_nodes()))) total_percent = 0 # Compare Database objects comparison_schema_result, total_percent = \ compare_database_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, target_sid=target_sid, target_did=target_did, diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent, ignore_whitespaces=ignore_whitespaces) comparison_result = \ comparison_result + comparison_schema_result # Compare Schema objects if 'source_only' in schema_result and \ len(schema_result['source_only']) > 0: for item in schema_result['source_only']: comparison_schema_result, total_percent = \ compare_schema_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, source_scid=item['scid'], target_sid=target_sid, target_did=target_did, target_scid=None, schema_name=item['schema_name'], diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent, ignore_whitespaces=ignore_whitespaces) comparison_result = \ comparison_result + comparison_schema_result if 'target_only' in schema_result and \ len(schema_result['target_only']) > 0: for item in schema_result['target_only']: comparison_schema_result, total_percent = \ compare_schema_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, source_scid=None, target_sid=target_sid, target_did=target_did, target_scid=item['scid'], schema_name=item['schema_name'], diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent, ignore_whitespaces=ignore_whitespaces) comparison_result = \ comparison_result + comparison_schema_result # Compare the two schema present in both the databases if 'in_both_database' in schema_result and \ len(schema_result['in_both_database']) > 0: for item in schema_result['in_both_database']: comparison_schema_result, total_percent = \ compare_schema_objects( trans_id=trans_id, session_obj=session_obj, source_sid=source_sid, source_did=source_did, source_scid=item['src_scid'], target_sid=target_sid, target_did=target_did, target_scid=item['tar_scid'], schema_name=item['schema_name'], diff_model_obj=diff_model_obj, total_percent=total_percent, node_percent=node_percent, ignore_whitespaces=ignore_whitespaces) comparison_result = \ comparison_result + comparison_schema_result msg = gettext("Successfully compare the specified databases.") total_percent = 100 diff_model_obj.set_comparison_info(msg, total_percent) # Update the message and total percentage done in session object update_session_diff_transaction(trans_id, session_obj, diff_model_obj) except Exception as e: app.logger.exception(e) return make_json_response(data=comparison_result)