feat(cli): run migrations and app in start command (#284)
* feat: perform pending migrations in start command * feat: log error when DB connection is refused * feat: log error when Redis connection is refused * refactor: fix type errors * fix: correct server and copy graphql schema * fix: differentiate migrations by env * chore: remove dev executable * chore: fix typo in default postgresUsername * fix: copy json files into dist folder * chore(cli): add dev script * chore: pull non-dev logs to info level * feat(cli): run app in start command * fix(backend): remove default count in Connection * fix(cli): remove .eslintrc usage in lint script * refactor: remove disableMigrationsListValidation * refactor: make Step optional in ExecutionStep * refactor: make Flow optional in Step
This commit is contained in:
@@ -1,9 +1,56 @@
|
||||
import { Command } from '@oclif/core';
|
||||
import { Command, Flags } from '@oclif/core';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
export default class Start extends Command {
|
||||
static description = 'Say hello world';
|
||||
static description = 'Run automatisch';
|
||||
|
||||
static flags = {
|
||||
env: Flags.string({
|
||||
multiple: true,
|
||||
char: 'e',
|
||||
}),
|
||||
'env-file': Flags.string(),
|
||||
}
|
||||
|
||||
async prepareEnvVars(): Promise<void> {
|
||||
const { flags } = await this.parse(Start);
|
||||
|
||||
if (flags['env-file']) {
|
||||
dotenv.config({ path: flags['env-file'] });
|
||||
}
|
||||
|
||||
if (flags.env) {
|
||||
for (const env of flags.env) {
|
||||
const [key, value] = env.split('=');
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
delete process.env.SERVE_WEB_APP_SEPARATELY;
|
||||
}
|
||||
|
||||
async runMigrationsIfNeeded(): Promise<void> {
|
||||
const database = (await import('@automatisch/backend/dist/src/config/database')).default;
|
||||
const migrator = database.migrate;
|
||||
|
||||
const [, pendingMigrations] = await migrator.list();
|
||||
const pendingMigrationsCount = pendingMigrations.length;
|
||||
const needsToMigrate = pendingMigrationsCount > 0;
|
||||
|
||||
if (needsToMigrate) {
|
||||
await migrator.latest();
|
||||
}
|
||||
}
|
||||
|
||||
async runApp(): Promise<void> {
|
||||
await import('@automatisch/backend/dist/src/server');
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
this.log('hello world from start script');
|
||||
await this.prepareEnvVars();
|
||||
|
||||
await this.runMigrationsIfNeeded();
|
||||
|
||||
await this.runApp();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user