import { EventstoreResourceNotExistError } from '@resolve-js/eventstore-base' ; import { getLog } from './get-log' ; import { AdapterPool } from './types' ; import executeSequence from './execute-sequence' ; import { isNotExistError } from './resource-errors' ; const dropEvents = async ( { databaseName , secretsTableName , executeStatement , escapeId , } ) : Promise < any [ ] > => { const log = getLog ( 'dropSecrets' ) ; log . debug ( `dropping secrets` ) ; log . verbose ( `secretsTableName: ${ secretsTableName }` ) ; log . verbose ( `databaseName: ${ databaseName }` ) ; const databaseNameAsId = escapeId ( databaseName ) ; const secretsTableNameAsId = escapeId ( secretsTableName ) ; const globalIndexName = escapeId ( `${ secretsTableName }-global` ) ; const statements = [ `DROP TABLE ${ databaseNameAsId }.${ secretsTableNameAsId }` , `DROP INDEX IF EXISTS ${ databaseNameAsId }.${ globalIndexName }` , ] ; const errors = await executeSequence ( executeStatement , statements , log , ( error ) => { if ( isNotExistError ( error ) ) { return new EventstoreResourceNotExistError ( `postgresql adapter for database "${ databaseName }" already dropped` ) ; } return null ; } ) ; log . debug ( `finished dropping secrets` ) ; return errors ; } ; export default dropEvents ;