async def _direct_recursively_preparing_table_chunk( self, table: DBTable, need_transfer_pks_chunk: List[int], stack_tables: Optional[Set[DBTable]] = None, ): """ Recursively preparing table """ logger.debug(make_str_from_iterable([t.name for t in stack_tables])) coroutines = [ self._direct_recursively_preparing_foreign_table( table=table, column=column, need_transfer_pks=need_transfer_pks_chunk, stack_tables=stack_tables, ) for column in table.not_self_fk_columns if not ( column.constraint_table.with_key_column or column.constraint_table in stack_tables ) ] if coroutines: await asyncio.wait(coroutines) del need_transfer_pks_chunk
async def _validate_table_data( self, table: DBTable, ): """ Validating table key column values """ get_table_key_column_ids_sql = self.GET_TABLE_KEY_COLUMN_IDS_SQL.format( key_column_name=table.key_column.name, table_name=table.name, ) async with self._dst_database.connection_pool.acquire() as connection: key_column_ids_records: List[Record] = await connection.fetch( query=get_table_key_column_ids_sql, ) if key_column_ids_records: key_column_ids = { str(record.get(table.key_column.name)) for record in key_column_ids_records } difference = key_column_ids.difference(self._key_column_ids) if difference: wrong_key_column_ids = make_str_from_iterable( iterable=difference, with_quotes=True, ) self._validation_result.append( f'Wrong key column "{table.key_column.name}" ids found ' f'in table "{table.name}" - {wrong_key_column_ids}!')
async def _prepare_chunk_tables( self, chunk_table_names: Iterable[str], ): """ Preparing tables of chunk table names """ getting_tables_columns_sql = SQLRepository.get_table_columns_sql( table_names=make_str_from_iterable( iterable=chunk_table_names, with_quotes=True, quote='\'', ), ) async with self._connection_pool.acquire() as connection: records = await connection.fetch( query=getting_tables_columns_sql, ) coroutines = [ self.tables[table_name].append_column( column_name=column_name, data_type=data_type, ordinal_position=ordinal_position, constraint_table=self.tables.get(constraint_table_name), constraint_type=constraint_type, ) for ( table_name, column_name, data_type, ordinal_position, constraint_table_name, constraint_type, ) in records ] if coroutines: await asyncio.gather(*coroutines) self.clear_cache()