import { log } from './FsOps' ; import Conversion from './Conversion' ; import DBAccess from './DBAccess' ; import DBVendors from './DBVendors' ; import DBAccessQueryResult from './DBAccessQueryResult' ; import IDBAccessQueryParams from './IDBAccessQueryParams' ; import * as extraConfigProcessor from './ExtraConfigProcessor' ; /**
 * Defines which columns of the given table can contain the "NULL" value.
 * Sets an appropriate constraint, if need.
 */ export default async ( conversion , tableName ) : Promise < void > => { const logTitle = 'NullProcessor::default' ; const msg = `\t--[${ logTitle }] Defines "NOT NULLs" for table: "${ conversion . _schema }"."${ tableName }"` ; log ( conversion , msg , conversion . _dicTables [ tableName ] . tableLogPath ) ; const originalTableName = extraConfigProcessor . getTableName ( conversion , tableName , true ) ; const promises = conversion . _dicTables [ tableName ] . arrTableColumns . map ( async ( column ) => { if ( column . Null . toLowerCase ( ) === 'no' ) { const columnName = extraConfigProcessor . getColumnName ( conversion , originalTableName , column . Field , false ) ; const params = { conversion : conversion , caller : logTitle , sql : `ALTER TABLE "${ conversion . _schema }"."${ tableName }" ALTER COLUMN "${ columnName }" SET NOT NULL;` , vendor : DBVendors . PG , processExitOnError : false , shouldReturnClient : false } ; const result = await DBAccess . query ( params ) ; if ( ! result . error ) { const successMsg = `\t--[${ logTitle }] Set NOT NULL for "${ conversion . _schema }"."${ tableName }"."${ columnName }"...` ; log ( conversion , successMsg , conversion . _dicTables [ tableName ] . tableLogPath ) ; } } } ) ; await Promise . all ( promises ) ; } ;