1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var index_1 = require("../index");
|
5 | var ConnectionOptionsReader_1 = require("../connection/ConnectionOptionsReader");
|
6 | var process = require("process");
|
7 | var chalk = require("chalk");
|
8 |
|
9 |
|
10 |
|
11 | var MigrationShowCommand = (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 , 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 , index_1.createConnection(connectionOptions)];
|
54 | case 3:
|
55 | connection = _a.sent();
|
56 | return [4 , connection.showMigrations()];
|
57 | case 4:
|
58 | unappliedMigrations = _a.sent();
|
59 | return [4 , connection.close()];
|
60 | case 5:
|
61 | _a.sent();
|
62 |
|
63 | process.exit(unappliedMigrations ? 1 : 0);
|
64 | return [3 , 9];
|
65 | case 6:
|
66 | err_1 = _a.sent();
|
67 | if (!connection) return [3 , 8];
|
68 | return [4 , 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 , 9];
|
77 | case 9: return [2 ];
|
78 | }
|
79 | });
|
80 | });
|
81 | };
|
82 | return MigrationShowCommand;
|
83 | }());
|
84 | exports.MigrationShowCommand = MigrationShowCommand;
|
85 |
|
86 |
|