postgres/client.js
function createDBIfNotExists() {
  const tmpClient = knexLib({
    client: 'pg',
    connection: {
      host: POSTGRES_HOST,
      user: POSTGRES_USER,
      password: POSTGRES_PASSWORD,
      database: 'postgres',
      port: POSTGRES_PORT
    },
    pool: { min: CONNECTION_POOL_MIN, max: CONNECTION_POOL_MAX }
  });

  // https://github.com/clay/amphora-storage-postgres/pull/7/files/16d3429767943a593ad9667b0d471fefc15088d3#diff-6a1e11a6146d3a5a01f955a44a2ac07a
  return tmpClient.raw('CREATE DATABASE ??', [POSTGRES_DB])
    .then(() => tmpClient.destroy())
    .then(connect);
}
function createDBIfNotExists() {
  const tmpClient = knexLib({
    client: 'pg',
    connection: {
      host: POSTGRES_HOST,
      user: POSTGRES_USER,
      password: POSTGRES_PASSWORD,
      database: 'postgres',
      port: POSTGRES_PORT
    },
    pool: { min: CONNECTION_POOL_MIN, max: CONNECTION_POOL_MAX }
  });

  // https://github.com/clay/amphora-storage-postgres/pull/7/files/16d3429767943a593ad9667b0d471fefc15088d3#diff-6a1e11a6146d3a5a01f955a44a2ac07a
  return tmpClient.raw('CREATE DATABASE ??', [POSTGRES_DB])
    .then(() => tmpClient.destroy())
    .then(connect);
}
function createDBIfNotExists ( ) { const tmpClient = knexLib ( { client : 'pg' , connection : { host : POSTGRES_HOST , user : POSTGRES_USER , password : POSTGRES_PASSWORD , database : 'postgres' , port : POSTGRES_PORT } , pool : { min : CONNECTION_POOL_MIN , max : CONNECTION_POOL_MAX } } ) ; // https://github.com/clay/amphora-storage-postgres/pull/7/files/16d3429767943a593ad9667b0d471fefc15088d3#diff-6a1e11a6146d3a5a01f955a44a2ac07a return tmpClient . raw ( 'CREATE DATABASE ??' , [ POSTGRES_DB ] ) . then ( ( ) => tmpClient . destroy ( ) ) . then ( connect ) ; }
Connect to the default DB and create the Clay
DB. Once the DB has been made the connection
can be killed and we can try to re-connect
to the Clay DB

@returns {Promise}
Connect to the default DB and create the Clay DB . Once the DB has been made the connection can be killed and we can try to re - connect to the Clay DB