db/index.js
// Sync the db, creating it if necessary if not in prod
Sync the db, creating it if necessary if not in prod
Sync the db creating it if necessary if not in prod
function sync(force = process.env.NODE_ENV === 'testing', retries = 0, maxRetries = 5) {
  return db.sync({ force })
    .then(() => console.log(chalk.blue(`Synced models to db ${url}`)))
    .catch((fail) => {
      if (process.env.NODE_ENV === 'production' || retries > maxRetries) {
        console.error(chalk.red('********** Database Error ***********'));
        console.error(chalk.red(`Couldn't connect to ${url}`));
        console.error();
        console.error(chalk.red(fail));
        console.error(chalk.red('*************************************'));
        return;
      }
      console.log(chalk.blue(`${retries ? `[retry ${retries}]` : ''} Creating database ${name}...`));
      return new Promise((resolve, reject) =>
        childProcess.exec(`createdb "${name}"`, resolve))
        .then(() => sync(true, retries + 1));
    });
}
function sync ( force = process . env . NODE_ENV === 'testing' , retries = 0 , maxRetries = 5 ) { return db . sync ( { force } ) . then ( ( ) => console . log ( chalk . blue ( ` ${ url } ` ) ) ) . catch ( ( fail ) => { if ( process . env . NODE_ENV === 'production' || retries > maxRetries ) { console . error ( chalk . red ( '********** Database Error ***********' ) ) ; console . error ( chalk . red ( ` ${ url } ` ) ) ; console . error ( ) ; console . error ( chalk . red ( fail ) ) ; console . error ( chalk . red ( '*************************************' ) ) ; return ; } console . log ( chalk . blue ( ` ${ retries ? ` ${ retries } ` : '' } ${ name } ` ) ) ; return new Promise ( ( resolve , reject ) => childProcess . exec ( ` ${ name } ` , resolve ) ) . then ( ( ) => sync ( true , retries + 1 ) ) ; } ) ; }
Sync the db, creating it if necessary if not in prod
Sync the db creating it if necessary if not in prod
// Don't do this auto-create nonsense in prod, or if we've retried too many times // Otherwise, do this autocreate nonsense // eslint-disable-next-line consistent-return