UNPKG

3.72 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var index_1 = require("../index");
5var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader");
6var process = require("process");
7var chalk = require("chalk");
8/**
9 * Runs migration command.
10 */
11var MigrationShowCommand = /** @class */ (function () {
12 function MigrationShowCommand() {
13 this.command = "migration:show";
14 this.describe = "Show all migrations and whether they have been run or not";
15 }
16 MigrationShowCommand.prototype.builder = function (args) {
17 return args
18 .option("connection", {
19 alias: "c",
20 default: "default",
21 describe: "Name of the connection on which run a query."
22 })
23 .option("config", {
24 alias: "f",
25 default: "ormconfig",
26 describe: "Name of the file with connection configuration."
27 });
28 };
29 MigrationShowCommand.prototype.handler = function (args) {
30 return tslib_1.__awaiter(this, void 0, void 0, function () {
31 var connection, connectionOptionsReader, connectionOptions, unappliedMigrations, err_1;
32 return tslib_1.__generator(this, function (_a) {
33 switch (_a.label) {
34 case 0:
35 connection = undefined;
36 _a.label = 1;
37 case 1:
38 _a.trys.push([1, 6, , 9]);
39 connectionOptionsReader = new ConnectionOptionsReader_1.ConnectionOptionsReader({
40 root: process.cwd(),
41 configName: args.config
42 });
43 return [4 /*yield*/, connectionOptionsReader.get(args.connection)];
44 case 2:
45 connectionOptions = _a.sent();
46 Object.assign(connectionOptions, {
47 subscribers: [],
48 synchronize: false,
49 migrationsRun: false,
50 dropSchema: false,
51 logging: ["query", "error", "schema"]
52 });
53 return [4 /*yield*/, index_1.createConnection(connectionOptions)];
54 case 3:
55 connection = _a.sent();
56 return [4 /*yield*/, connection.showMigrations()];
57 case 4:
58 unappliedMigrations = _a.sent();
59 return [4 /*yield*/, connection.close()];
60 case 5:
61 _a.sent();
62 // return error code if there are unapplied migrations for CI
63 process.exit(unappliedMigrations ? 1 : 0);
64 return [3 /*break*/, 9];
65 case 6:
66 err_1 = _a.sent();
67 if (!connection) return [3 /*break*/, 8];
68 return [4 /*yield*/, connection.close()];
69 case 7:
70 _a.sent();
71 _a.label = 8;
72 case 8:
73 console.log(chalk.black.bgRed("Error during migration show:"));
74 console.error(err_1);
75 process.exit(1);
76 return [3 /*break*/, 9];
77 case 9: return [2 /*return*/];
78 }
79 });
80 });
81 };
82 return MigrationShowCommand;
83}());
84exports.MigrationShowCommand = MigrationShowCommand;
85
86//# sourceMappingURL=MigrationShowCommand.js.map