import DBAccessQueryResult from './DBAccessQueryResult' ; import Conversion from './Conversion' ; import DBAccess from './DBAccess' ; import DBVendors from './DBVendors' ; import IDBAccessQueryParams from './IDBAccessQueryParams' ; import { getDataPoolTableName } from './DataPoolManager' ; /**
 * Enforces consistency before processing a chunk of data.
 * Ensures there are no any data duplications.
 * In case of normal execution - it is a good practice.
 * In case of rerunning Nmig after unexpected failure - it is absolutely mandatory.
 */ export const dataTransferred = async ( conversion , dataPoolId ) : Promise < boolean > => { const dataPoolTable = getDataPoolTableName ( conversion ) ; const sqlGetMetadata = `SELECT metadata AS metadata FROM ${ dataPoolTable } WHERE id = ${ dataPoolId };` ; const params = { conversion : conversion , caller : 'ConsistencyEnforcer::dataTransferred' , sql : sqlGetMetadata , vendor : DBVendors . PG , processExitOnError : true , shouldReturnClient : true } ; const result = await DBAccess . query ( params ) ; const metadata = JSON . parse ( result . data . rows [ 0 ] . metadata ) ; const targetTableName = `"${ conversion . _schema }"."${ metadata . _tableName }"` ; params . sql = `SELECT * FROM ${ targetTableName } LIMIT 1 OFFSET 0;` ; params . shouldReturnClient = false ; params . client = result . client ; const probe = await DBAccess . query ( params ) ; return probe . data . rows . length !== 0 ; } ;