@fewer/cli
Version:
The CLI to scaffold and perform operations for Fewer.
67 lines • 2.59 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const commonFlags_1 = __importDefault(require("../../commonFlags"));
const MigrationRunner_1 = __importDefault(require("../../MigrationRunner"));
const utils_1 = require("../../utils");
class Migrate extends command_1.Command {
async run() {
const { flags } = this.parse(Migrate);
const migrations = await utils_1.getMigrations();
const runner = new MigrationRunner_1.default(migrations);
try {
if (flags.redo) {
await runner.redo(flags.steps);
}
else if (flags.version) {
if (flags.direction === 'down') {
await runner.down(flags.version);
}
else {
await runner.up(flags.version);
}
}
else if (flags.rollback) {
await runner.rollback(flags.steps);
}
else {
await runner.latest();
}
}
finally {
await runner.cleanup();
}
}
}
Migrate.description = 'Performs migrations.';
Migrate.examples = [
'$ fewer db:migrate',
'$ fewer db:migrate --version 20190121190432',
'$ fewer db:migrate --direction down --version 20190121190432',
'$ fewer db:migrate --rollback',
'$ fewer db:migrate --rollback --steps 3',
'$ fewer db:migrate --redo --steps 3',
];
Migrate.flags = Object.assign({}, commonFlags_1.default, { version: command_1.flags.string({
char: 'v',
description: 'Runs a specific migration that matches the version.',
}), rollback: command_1.flags.boolean({
description: 'Rolls back the previous migration.',
exclusive: ['version'],
}), redo: command_1.flags.boolean({
description: 'Roll back a number of migrations, then perform them again.',
exclusive: ['version'],
}), steps: command_1.flags.integer({
description: 'Sets the number of migrations to rollback, or redo.',
exclusive: ['version'],
}), direction: command_1.flags.string({
description: 'Runs a specific migration in the provided direction.',
options: ['up', 'down'],
dependsOn: ['version'],
exclusive: ['rollback', 'redo', 'steps'],
}) });
exports.default = Migrate;
//# sourceMappingURL=migrate.js.map