def __init__(self): time_check_query="""SELECT CASE WHEN (SELECT TRUE FROM log_time WHERE hour_truncate=date_trunc('hour',now())) THEN NULl ELSE LOCALTIMESTAMP END AS actual_time,date_trunc('hour',LOCALTIMESTAMP) AS hour_truncate""" self.cursor.execute(time_check_query) time_data=self.cursor.fetchone() if not time_data[0]: logger.critical('Appropriate record for "{0}" already exists'.format(time_data[1])) self.cursor.close() db_handler.close() exit() logger.debug('Log time obtained. Actual Time: {0}\tHour Truncate: {1}'.format(time_data[0],time_data[1])) self.actual_time=time_data[0] self.hour_truncate=time_data[1] self.cursor.execute("INSERT INTO log_time (hour_truncate,actual_time) VALUES ('{0}','{1}') RETURNING id".format(time_data[1],time_data[0])) self.id=self.cursor.fetchone()[0] db_handler.commit()
for tn_id in sn.get_tables(): tn=TableName(tn_id) tables.append(tn.db_dump()) if tn.get_toast_id(): ttn=TableToastName(tn.get_toast_id()) toast_tables.append(ttn.db_dump()) tin=IndexToastName(ttn.get_tindex_id()) toast_indexes.append(tin.db_dump()) for ind_id in tn.get_dependants(): ind=IndexName(ind_id) indexes.append(ind.db_dump()) l_payload['table_name']=tables l_payload['index_name']=indexes l_payload['table_toast_name']=toast_tables l_payload['index_toast_name']=toast_indexes for fn_id in sn.get_functions(): fn=FunctionName(fn_id) functions.append(fn.db_dump()) l_payload['function_name']=functions output['list_payload']=l_payload tr=transfer.Transfer() tr.set_db_data(output) db_handler.commit() self_cursor.close() db_handler.close()