mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add database install / migrate commands
This commit is contained in:
@@ -3,6 +3,12 @@ import run from '../../../database/seeds/run';
|
||||
|
||||
export default async function start() {
|
||||
const database = require('../../../database/index').default as Knex;
|
||||
await run(database);
|
||||
database.destroy();
|
||||
try {
|
||||
await run(database);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
database.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
14
api/src/cli/commands/database/migrate.ts
Normal file
14
api/src/cli/commands/database/migrate.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import run from '../../../database/migrations/run';
|
||||
|
||||
export default async function migrate(direction: 'latest' | 'up' | 'down') {
|
||||
const database = require('../../../database').default;
|
||||
|
||||
try {
|
||||
await run(database, direction);
|
||||
} catch(err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
database.destroy();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import logger from '../../logger';
|
||||
|
||||
export default async function start() {
|
||||
const { default: env, validateEnv } = require('../../env');
|
||||
const { default: env } = require('../../env');
|
||||
const { validateDBConnection } = require('../../database');
|
||||
|
||||
validateEnv();
|
||||
await validateDBConnection();
|
||||
|
||||
const app = require('../../app').default;
|
||||
|
||||
@@ -7,13 +7,19 @@ const pkg = require('../../package.json');
|
||||
import start from './commands/start';
|
||||
import init from './commands/init';
|
||||
import dbInstall from './commands/database/install';
|
||||
|
||||
program.version(pkg.version, '-v, --version');
|
||||
import dbMigrate from './commands/database/migrate';
|
||||
|
||||
program.name('directus').usage('[command] [options]');
|
||||
program.version(pkg.version, '-v, --version');
|
||||
|
||||
program.command('start').description('Start the Directus API').action(start);
|
||||
program.command('init').description('Create a new Directus Project').action(init);
|
||||
program.command('database install').description('Install the database').action(dbInstall);
|
||||
|
||||
program.parseAsync(process.argv);
|
||||
const dbCommand = program.command('database');
|
||||
|
||||
dbCommand.command('install').description('Install the database').action(dbInstall);
|
||||
dbCommand.command('migrate:latest').description('Upgrade the database').action(() => dbMigrate('latest'));
|
||||
dbCommand.command('migrate:up').description('Upgrade the database').action(() => dbMigrate('up'));
|
||||
dbCommand.command('migrate:down').description('Downgrade the database').action(() => dbMigrate('down'));
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
Reference in New Issue
Block a user