Untitled

 avatar
unknown
plain_text
2 years ago
3.9 kB
4
Indexable
    if releaseType.casefold() == 'DEPLOYED'.casefold() or releaseType.casefold() == 'CANCELLED'.casefold():
        logging.info(f"processing - {releaseType}")
        order = ['MASTER-CHILD', 'AUDIT-CHILD', 'MASTER', 'AUDIT', 'RELEASE']
        logging.info("order of execution - 'MASTER-CHILD', 'AUDIT-CHILD', 'MASTER', 'AUDIT', 'RELEASE'")
        filtered_df = df.loc[
            df['eprm_catalog'].isin(['PC', 'RELEASE']) & (df['eprm_enabled_flg'].isin(['Y'])) & df[
                'eprm_table_type'].isin(
                order)].copy()
        filtered_df['eprm_table_type'] = pd.Categorical(filtered_df['eprm_table_type'], categories=order, ordered=True)
        filtered_df = filtered_df.sort_values('eprm_table_type')
        df = df.sort_values('eprm_seq_nbr', ascending=False)

        for _, row in filtered_df.iterrows():
            eprm_table_name = row['eprm_table_name']
            eprm_join_cols_entity = row['eprm_join_cols_entity']
            eprm_join_cols_reim = row['eprm_join_cols_reim']
            eprm_table_alias = row['eprm_table_alias']
            eprm_table_type = row['eprm_table_type']
            eprm_parent_table_name = row['eprm_parent_table_name']

            if eprm_table_type == 'AUDIT':
                eprm_table_col_pk = row['eprm_table_col_pk']
                query = f"SELECT COUNT(*) FROM {schema_tar}.{eprm_table_name} WHERE (" + eprm_table_col_pk + f") IN (SELECT entity_ref_nbr FROM  {schema_tar}.release_entity_inst_map WHERE release_id='" + releaseId + "' AND op_id='" + opId + "' AND bu_id='" + buId + "')"
                try:
                    logging.info(f"processing {eprm_table_type}")
                    cursor_tar.execute(query)
                    result = cursor_tar.fetchone()
                    query_info = f"-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STATUS|{replicationTarget}| TABLE| {eprm_table_name}\n"
                    query_info += f"-- #Query: Result:{result[0]}\n"
                    query_count += 1
                    query_info += query + ";\n"
                    write_sql(query_info)
                    print(f"Count for {eprm_table_name}: {result[0]} (audit)")
                    logging.info(f"Count for {eprm_table_name}: {result[0]} (audit)")
                except mysql.connector.Error as err:
                    print("Error - {} . Line No - {} ".format(str(exp), str(sys.exc_info()[-1].tb_lineno)))
                    print(f"Error occurred while executing the query:{query}: {err}")
                    logging.info(f"Error occurred while executing the query:{query}: {err}")
            if eprm_table_type == 'RELEASE':
                eprm_table_name = row['eprm_table_name']
                eprm_seq_nbr = row['eprm_seq_nbr']
                query = f"SELECT COUNT(*) FROM {schema_tar}.{eprm_table_name} where release_id='" + releaseId + "' AND op_id='" + opId + "' AND bu_id='" + buId + "'"
                try:
                    logging.info(f"processing {eprm_table_type}")
                    cursor_tar.execute(query)
                    result = cursor_tar.fetchone()
                    query_info = f"-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ STATUS|{replicationTarget}| TABLE| {eprm_table_name}\n"
                    query_info += f"-- #Query: Result:{result[0]}\n"
                    query_count += 1
                    query_info += query + ";\n"
                    write_sql(query_info)
                    print(f"Count for {eprm_table_name}: {result[0]} (release){eprm_seq_nbr}")
                    logging.info(f"Count for {eprm_table_name}: {result[0]} (release)")
                except mysql.connector.Error as err:
                    print(f"Error occurred while executing the query:{query}: {err}")
                    logging.info(f"Error occurred while executing the query:{query}: {err}")
Editor is loading...