import * as path from 'path' ; import { Config } from 'knex' ; import { defaultConfig , defaultDatabaseConfiguration , extractDBConfigFromWalletConfig , WalletConfig , } from '../config' ; try { require ( '@statechannels/devtools' ) . configureEnvVariables ( ) ; } catch ( err ) { if ( /Cannot find module '@statechannels\/devtools'/ . test ( err . message ) ) console . warn ( `
WARNING: @statechannels/devtools not detected.
         Ensure required env variables are properly configured in the shell.
    ` ) ; else throw err ; } const BASE_PATH = path . join ( __dirname , '..' , 'db' ) ; const extensions = [ path . extname ( __filename ) ] ; export function createKnexConfig ( engineConfig ) { return { ... extractDBConfigFromWalletConfig ( engineConfig ) , debug : engineConfig . databaseConfiguration . debug , migrations : { directory : path . join ( BASE_PATH , 'migrations' ) , loadExtensions : extensions , } , seeds : { directory : path . join ( BASE_PATH , 'seeds' ) , loadExtensions : extensions , } , /**
         * To safely run migrations, we cannot use knexSnakeCaseMappers in the knex config
         * https://github.com/Vinci≠t/objection.js/issues/1144
         * So, in our admin knex config, which is used for running migrations, we
         * overwrite the two config options set by knexSnakeCaseMappers
         */ postProcessResponse : undefined , wrapIdentifier : undefined , } ; } const dbConnectionConfig = process . env . SERVER_URL || { host : process . env . SERVER_HOST || defaultDatabaseConfiguration . connection . host , port : Number ( process . env . SERVER_PORT ) || defaultDatabaseConfiguration . connection . port , database : process . env . SERVER_DB_NAME || '' , user : process . env . SERVER_DB_USER || 'postgres' , password : process . env . SERVER_DB_PASSWORD , } ; const dbDebug = process . env . DEBUG_KNEX ?. toLowerCase ( ) === 'true' || false ; export const { client , connection , debug , migrations , seeds , pool } = createKnexConfig ( { ... defaultConfig , databaseConfiguration : { debug : dbDebug , connection : dbConnectionConfig } , networkConfiguration : { chainNetworkID : 0 , } , } ) ;