()
| 38 | const { credentials, db } = await trySeed(); |
| 39 | |
| 40 | async function trySeed(): Promise<{ credentials: Credentials; db: Knex }> { |
| 41 | const credentials: Credentials = await inquirer.prompt( |
| 42 | (databaseQuestions[dbClient] as any[]).map((question: ({ client, filepath }: any) => any) => |
| 43 | question({ client: dbClient, filepath: rootPath }), |
| 44 | ), |
| 45 | ); |
| 46 | |
| 47 | const db = createDBConnection(dbClient, credentials!); |
| 48 | |
| 49 | try { |
| 50 | await runSeed(db); |
| 51 | await runMigrations(db, 'latest', false); |
| 52 | } catch (err: any) { |
| 53 | process.stdout.write('\nSomething went wrong while seeding the database:\n'); |
| 54 | process.stdout.write(`\n${chalk.red(`[${err.code || 'Error'}]`)} ${err.message}\n`); |
| 55 | process.stdout.write('\nPlease try again\n\n'); |
| 56 | |
| 57 | attemptsRemaining--; |
| 58 | |
| 59 | if (attemptsRemaining > 0) { |
| 60 | return await trySeed(); |
| 61 | } else { |
| 62 | process.stdout.write("Couldn't seed the database. Exiting.\n"); |
| 63 | process.exit(1); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return { credentials, db }; |
| 68 | } |
| 69 | |
| 70 | await createEnv(dbClient, credentials!, rootPath); |
| 71 |
no test coverage detected