@spinajs/orm-cli 2.0.487

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +247 -0
  2. package/lib/cjs/cli/MigrateCreate.d.ts +59 -0
  3. package/lib/cjs/cli/MigrateCreate.d.ts.map +1 -0
  4. package/lib/cjs/cli/MigrateCreate.js +211 -0
  5. package/lib/cjs/cli/MigrateCreate.js.map +1 -0
  6. package/lib/cjs/cli/MigrateDown.d.ts +23 -0
  7. package/lib/cjs/cli/MigrateDown.d.ts.map +1 -0
  8. package/lib/cjs/cli/MigrateDown.js +74 -0
  9. package/lib/cjs/cli/MigrateDown.js.map +1 -0
  10. package/lib/cjs/cli/MigrateResolve.d.ts +19 -0
  11. package/lib/cjs/cli/MigrateResolve.d.ts.map +1 -0
  12. package/lib/cjs/cli/MigrateResolve.js +66 -0
  13. package/lib/cjs/cli/MigrateResolve.js.map +1 -0
  14. package/lib/cjs/cli/MigrateStatus.d.ts +19 -0
  15. package/lib/cjs/cli/MigrateStatus.d.ts.map +1 -0
  16. package/lib/cjs/cli/MigrateStatus.js +109 -0
  17. package/lib/cjs/cli/MigrateStatus.js.map +1 -0
  18. package/lib/cjs/cli/MigrateUp.d.ts +33 -0
  19. package/lib/cjs/cli/MigrateUp.d.ts.map +1 -0
  20. package/lib/cjs/cli/MigrateUp.js +92 -0
  21. package/lib/cjs/cli/MigrateUp.js.map +1 -0
  22. package/lib/cjs/config/orm-cli.d.ts +9 -0
  23. package/lib/cjs/config/orm-cli.d.ts.map +1 -0
  24. package/lib/cjs/config/orm-cli.js +26 -0
  25. package/lib/cjs/config/orm-cli.js.map +1 -0
  26. package/lib/cjs/index.d.ts +18 -0
  27. package/lib/cjs/index.d.ts.map +1 -0
  28. package/lib/cjs/index.js +34 -0
  29. package/lib/cjs/index.js.map +1 -0
  30. package/lib/cjs/orm.d.ts +31 -0
  31. package/lib/cjs/orm.d.ts.map +1 -0
  32. package/lib/cjs/orm.js +38 -0
  33. package/lib/cjs/orm.js.map +1 -0
  34. package/lib/cjs/package.json +1 -0
  35. package/lib/mjs/cli/MigrateCreate.d.ts +59 -0
  36. package/lib/mjs/cli/MigrateCreate.d.ts.map +1 -0
  37. package/lib/mjs/cli/MigrateCreate.js +173 -0
  38. package/lib/mjs/cli/MigrateCreate.js.map +1 -0
  39. package/lib/mjs/cli/MigrateDown.d.ts +23 -0
  40. package/lib/mjs/cli/MigrateDown.d.ts.map +1 -0
  41. package/lib/mjs/cli/MigrateDown.js +71 -0
  42. package/lib/mjs/cli/MigrateDown.js.map +1 -0
  43. package/lib/mjs/cli/MigrateResolve.d.ts +19 -0
  44. package/lib/mjs/cli/MigrateResolve.d.ts.map +1 -0
  45. package/lib/mjs/cli/MigrateResolve.js +63 -0
  46. package/lib/mjs/cli/MigrateResolve.js.map +1 -0
  47. package/lib/mjs/cli/MigrateStatus.d.ts +19 -0
  48. package/lib/mjs/cli/MigrateStatus.d.ts.map +1 -0
  49. package/lib/mjs/cli/MigrateStatus.js +106 -0
  50. package/lib/mjs/cli/MigrateStatus.js.map +1 -0
  51. package/lib/mjs/cli/MigrateUp.d.ts +33 -0
  52. package/lib/mjs/cli/MigrateUp.d.ts.map +1 -0
  53. package/lib/mjs/cli/MigrateUp.js +89 -0
  54. package/lib/mjs/cli/MigrateUp.js.map +1 -0
  55. package/lib/mjs/config/orm-cli.d.ts +9 -0
  56. package/lib/mjs/config/orm-cli.d.ts.map +1 -0
  57. package/lib/mjs/config/orm-cli.js +24 -0
  58. package/lib/mjs/config/orm-cli.js.map +1 -0
  59. package/lib/mjs/index.d.ts +18 -0
  60. package/lib/mjs/index.d.ts.map +1 -0
  61. package/lib/mjs/index.js +18 -0
  62. package/lib/mjs/index.js.map +1 -0
  63. package/lib/mjs/orm.d.ts +31 -0
  64. package/lib/mjs/orm.d.ts.map +1 -0
  65. package/lib/mjs/orm.js +34 -0
  66. package/lib/mjs/orm.js.map +1 -0
  67. package/lib/mjs/package.json +1 -0
  68. package/lib/tsconfig.cjs.tsbuildinfo +1 -0
  69. package/lib/tsconfig.mjs.tsbuildinfo +1 -0
  70. package/package.json +68 -0
@@ -0,0 +1,19 @@
1
+ import { CliCommand } from '@spinajs/cli';
2
+ import { Log } from '@spinajs/log-common';
3
+ import { MigrationResolveAction } from '@spinajs/orm';
4
+ export interface IMigrateResolveCommandOptions {
5
+ name: string;
6
+ applied?: boolean;
7
+ rolledBack?: boolean;
8
+ }
9
+ export declare class MigrateResolveCommand extends CliCommand {
10
+ protected Log: Log;
11
+ execute(options: IMigrateResolveCommandOptions): Promise<void>;
12
+ /**
13
+ * Exactly one of the two flags, never both and never neither: the whole point of this command is
14
+ * to state which of the two things actually happened to the database, and neither the CLI nor
15
+ * the service can find that out on its own.
16
+ */
17
+ protected action(options: IMigrateResolveCommandOptions): MigrationResolveAction;
18
+ }
19
+ //# sourceMappingURL=MigrateResolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrateResolve.d.ts","sourceRoot":"","sources":["../../../src/cli/MigrateResolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAGtD,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,qBAIa,qBAAsB,SAAQ,UAAU;IAEnD,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB3E;;;;OAIG;IACH,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,6BAA6B,GAAG,sBAAsB;CAcjF"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MigrateResolveCommand = void 0;
13
+ const cli_1 = require("@spinajs/cli");
14
+ const exceptions_1 = require("@spinajs/exceptions");
15
+ const log_common_1 = require("@spinajs/log-common");
16
+ const orm_js_1 = require("../orm.js");
17
+ let MigrateResolveCommand = class MigrateResolveCommand extends cli_1.CliCommand {
18
+ async execute(options) {
19
+ // Validated before the Orm is resolved: this refusal is about the command line, and booting
20
+ // an Orm ( which opens connections and can run the startup migration pass ) to reject a
21
+ // malformed invocation would be a side effect nobody asked for.
22
+ const action = this.action(options);
23
+ // Not `DI.resolve(Orm)`: this command is invoked precisely when a connection holds a FAILED
24
+ // row, and a boot migration pass refuses to run against one - so resolving an ordinary Orm
25
+ // would fail here, on the very row this call is about to clear. See `resolveCliOrm`.
26
+ const orm = await (0, orm_js_1.resolveCliOrm)();
27
+ // The facade refuses anything that is not in the failed state - `FinishedAt` NULL and `Logs`
28
+ // set - so a healthy or absent row throws rather than being silently rewritten. That error is
29
+ // let through unchanged; it names the migration and the connection.
30
+ await orm.Migration.resolve(options.name, action);
31
+ if (action === 'applied') {
32
+ this.Log.success(`Migration ${options.name} is now recorded as applied. It will not run again.`);
33
+ }
34
+ else {
35
+ this.Log.success(`Migration ${options.name} is now recorded as rolled back. It is pending again and WILL run on the next migrate-up.`);
36
+ }
37
+ }
38
+ /**
39
+ * Exactly one of the two flags, never both and never neither: the whole point of this command is
40
+ * to state which of the two things actually happened to the database, and neither the CLI nor
41
+ * the service can find that out on its own.
42
+ */
43
+ action(options) {
44
+ const applied = options.applied === true;
45
+ const rolledBack = options.rolledBack === true;
46
+ if (applied && rolledBack) {
47
+ throw new exceptions_1.InvalidArgument('--applied and --rolled-back are mutually exclusive - a migration either reached the database or it did not');
48
+ }
49
+ if (!applied && !rolledBack) {
50
+ throw new exceptions_1.InvalidArgument('one of --applied / --rolled-back is required - resolving a failed migration means recording which of the two actually happened');
51
+ }
52
+ return applied ? 'applied' : 'rolled-back';
53
+ }
54
+ };
55
+ exports.MigrateResolveCommand = MigrateResolveCommand;
56
+ __decorate([
57
+ (0, log_common_1.Logger)('ORM-CLI'),
58
+ __metadata("design:type", log_common_1.Log)
59
+ ], MigrateResolveCommand.prototype, "Log", void 0);
60
+ exports.MigrateResolveCommand = MigrateResolveCommand = __decorate([
61
+ (0, cli_1.Command)('migrate-resolve', 'Records the outcome of a FAILED migration - the escape hatch for a run that died halfway'),
62
+ (0, cli_1.Option)('-n, --name [name]', true, 'migration class name'),
63
+ (0, cli_1.Option)('--applied', false, 'record it as applied - the change IS in the database'),
64
+ (0, cli_1.Option)('--rolled-back', false, 'record it as rolled back - the change is NOT in the database, run it again later')
65
+ ], MigrateResolveCommand);
66
+ //# sourceMappingURL=MigrateResolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrateResolve.js","sourceRoot":"","sources":["../../../src/cli/MigrateResolve.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAA2D;AAC3D,oDAAsD;AACtD,oDAAkD;AAElD,sCAA0C;AAYnC,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,gBAAU;IAI5C,KAAK,CAAC,OAAO,CAAC,OAAsC;QACzD,4FAA4F;QAC5F,wFAAwF;QACxF,gEAAgE;QAChE,MAAM,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AE,sBAAsB,CAAC;IACzD,IAAA,YAAM,EAAC,WAAW,EAAE,KAAK,EAAE,sDAAsD,CAAC;IAClF,IAAA,YAAM,EAAC,eAAe,EAAE,KAAK,EAAE,kFAAkF,CAAC;GACtG,qBAAqB,CA8CjC"}
@@ -0,0 +1,19 @@
1
+ import { CliCommand } from '@spinajs/cli';
2
+ import { IMigrationStatusEntry } from '@spinajs/orm';
3
+ /**
4
+ * The report goes to stdout with `console.log`, not through the framework logger: it is this
5
+ * command's OUTPUT - something an operator greps and a script pipes - and routing it through the
6
+ * log would let a configured level or target silently swallow it.
7
+ */
8
+ export declare class MigrateStatusCommand extends CliCommand {
9
+ execute(): Promise<void>;
10
+ protected state(e: IMigrationStatusEntry): string;
11
+ /**
12
+ * The counterpart to `explainFailed`, and the wording has to carry the difference: a failed row
13
+ * blocks and waits for a decision, an interrupted one blocks nothing and the next `migrate-up`
14
+ * re-runs it whether or not anybody looked.
15
+ */
16
+ protected explainInterrupted(interrupted: IMigrationStatusEntry[]): void;
17
+ protected explainFailed(failed: IMigrationStatusEntry[]): void;
18
+ }
19
+ //# sourceMappingURL=MigrateStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrateStatus.d.ts","sourceRoot":"","sources":["../../../src/cli/MigrateStatus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAW,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGrD;;;;GAIG;AACH,qBACa,oBAAqB,SAAQ,UAAU;IACrC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2DrC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM;IAMjD;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,CAAC,WAAW,EAAE,qBAAqB,EAAE,GAAG,IAAI;IAoBxE,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,IAAI;CAY/D"}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MigrateStatusCommand = void 0;
10
+ /* eslint-disable no-console */
11
+ const cli_1 = require("@spinajs/cli");
12
+ const orm_js_1 = require("../orm.js");
13
+ /**
14
+ * The report goes to stdout with `console.log`, not through the framework logger: it is this
15
+ * command's OUTPUT - something an operator greps and a script pipes - and routing it through the
16
+ * log would let a configured level or target silently swallow it.
17
+ */
18
+ let MigrateStatusCommand = class MigrateStatusCommand extends cli_1.CliCommand {
19
+ async execute() {
20
+ // Not `DI.resolve(Orm)`: that boots with a migration pass, so this report would apply every
21
+ // pending migration on every `Migration.OnStartup` connection and only then describe the
22
+ // database it had just changed - always "all applied", always exit 0. See `resolveCliOrm`.
23
+ const orm = await (0, orm_js_1.resolveCliOrm)();
24
+ const entries = await orm.Migration.status();
25
+ if (entries.length === 0) {
26
+ console.log('No migrations are registered for any configured connection.');
27
+ return;
28
+ }
29
+ const width = Math.max(...entries.map((e) => e.connection.length), 'CONNECTION'.length);
30
+ console.log(` ${'STATE'.padEnd(12)} ${'BATCH'.padStart(5)} ${'CONNECTION'.padEnd(width)} MIGRATION`);
31
+ for (const e of entries) {
32
+ // `!!` in the leftmost column, not just the word FAILED: a failed row is the one line in
33
+ // this report that stops every later migrate-up on its connection, and it has to survive
34
+ // being skimmed in a wall of `applied`. `??` earns the same treatment for the opposite
35
+ // reason - an interrupted row stops nothing at all, and the next migrate-up will re-run it.
36
+ const marker = e.failed ? '!!' : e.interrupted ? '??' : ' ';
37
+ const drift = e.checksumMismatch ? ' [checksum mismatch - the file changed after it was applied]' : '';
38
+ console.log(`${marker} ${this.state(e).padEnd(12)} ${String(e.batch ?? '-').padStart(5)} ${e.connection.padEnd(width)} ${e.name}${drift}`);
39
+ }
40
+ const failed = entries.filter((e) => e.failed);
41
+ // `pending` is already false on a failed row ( the service derives it as `!applied && !failed` ),
42
+ // so the counts below never double-count the same entry.
43
+ const pending = entries.filter((e) => e.pending);
44
+ // `pending` from the service covers "will run on the next migrate-up", which includes rows
45
+ // that were rolled back and rows a killed run left open. The STATE column tells those apart,
46
+ // so the summary has to as well - otherwise the report says "0 pending" nowhere and "N
47
+ // pending" against a list in which no line reads `pending`. The three are disjoint: the
48
+ // service never reports `interrupted` on a row carrying RolledBackAt.
49
+ const interrupted = pending.filter((e) => e.interrupted);
50
+ const rolledBack = pending.filter((e) => e.rolledBack);
51
+ const neverRun = pending.filter((e) => !e.rolledBack && !e.interrupted);
52
+ console.log('');
53
+ console.log(`${entries.length} migration(s): ${entries.filter((e) => e.applied).length} applied, ${neverRun.length} pending, ${rolledBack.length} rolled back, ${interrupted.length} interrupted, ${failed.length} failed, ${entries.filter((e) => e.checksumMismatch).length} with a checksum mismatch`);
54
+ if (failed.length > 0) {
55
+ this.explainFailed(failed);
56
+ }
57
+ if (interrupted.length > 0) {
58
+ this.explainInterrupted(interrupted);
59
+ }
60
+ // Pending is an exit code too, not only failure: `migrate-status` is what a deploy gate calls
61
+ // to ask "is this database current?", and an un-run migration is a "no".
62
+ if (failed.length > 0 || pending.length > 0) {
63
+ process.exitCode = 1;
64
+ }
65
+ }
66
+ state(e) {
67
+ // interrupted is checked before rolled-back and pending, and after failed: it is a narrowing
68
+ // of `pending`, so reporting the broader word would lose the only thing worth saying about it
69
+ return e.failed ? 'FAILED' : e.applied ? 'applied' : e.interrupted ? 'INTERRUPTED' : e.rolledBack ? 'rolled-back' : 'pending';
70
+ }
71
+ /**
72
+ * The counterpart to `explainFailed`, and the wording has to carry the difference: a failed row
73
+ * blocks and waits for a decision, an interrupted one blocks nothing and the next `migrate-up`
74
+ * re-runs it whether or not anybody looked.
75
+ */
76
+ explainInterrupted(interrupted) {
77
+ console.log('');
78
+ console.log('An INTERRUPTED migration was started and never finished - the process running it was killed before it could');
79
+ console.log('record either outcome. Nothing blocks: the next migrate-up RE-RUNS it from the top, and how much of the first');
80
+ console.log('attempt is already in the database was never recorded. Establish that before the next run, then either let it');
81
+ console.log('re-run or record what really happened:');
82
+ for (const i of interrupted) {
83
+ console.log('');
84
+ // `startedAt` is typed Date, but a dialect that hands timestamps back as strings puts one
85
+ // here - and `new Date(<odd format>).toISOString()` THROWS, out of a report whose entire job
86
+ // is to be readable when something has gone wrong
87
+ const started = i.startedAt instanceof Date ? i.startedAt.toISOString() : String(i.startedAt);
88
+ console.log(` ${i.name} ( ${i.connection} )${i.startedAt ? `, started ${started}` : ''}`);
89
+ console.log(` migrate-resolve --name ${i.name} --applied # the change IS in the database, do not run it again`);
90
+ console.log(` migrate-resolve --name ${i.name} --rolled-back # the change is NOT, run it again on the next migrate-up`);
91
+ }
92
+ }
93
+ explainFailed(failed) {
94
+ console.log('');
95
+ console.log('A FAILED migration blocks every later migrate-up on its connection. Establish whether the change actually');
96
+ console.log('reached the database, then record that outcome so the connection is unblocked:');
97
+ for (const f of failed) {
98
+ console.log('');
99
+ console.log(` ${f.name} ( ${f.connection} )`);
100
+ console.log(` migrate-resolve --name ${f.name} --applied # the change IS in the database`);
101
+ console.log(` migrate-resolve --name ${f.name} --rolled-back # the change is NOT in the database`);
102
+ }
103
+ }
104
+ };
105
+ exports.MigrateStatusCommand = MigrateStatusCommand;
106
+ exports.MigrateStatusCommand = MigrateStatusCommand = __decorate([
107
+ (0, cli_1.Command)('migrate-status', 'Prints migration status for every configured connection')
108
+ ], MigrateStatusCommand);
109
+ //# sourceMappingURL=MigrateStatus.js.map
@@ -0,0 +1 @@
1
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C;QAC1G,CAAC;IACH,CAAC;CACF,CAAA;AAvGY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,aAAO,EAAC,gBAAgB,EAAE,yDAAyD,CAAC;GACxE,oBAAoB,CAuGhC"}
@@ -0,0 +1,33 @@
1
+ import { CliCommand } from '@spinajs/cli';
2
+ import { Log } from '@spinajs/log-common';
3
+ import { Orm } from '@spinajs/orm';
4
+ export interface IMigrateUpCommandOptions {
5
+ name?: string;
6
+ fake?: boolean;
7
+ connection?: string;
8
+ }
9
+ /**
10
+ * `orm.Migration` only exists on a RESOLVED Orm - it is assigned inside `Orm.resolve()`, once the
11
+ * connections it dispatches to have been created. So every command here resolves the Orm first
12
+ * and reaches the facade through it, rather than injecting a migration service directly.
13
+ *
14
+ * Through `resolveCliOrm()`, so that resolve does not run a migration pass of its own: the run
15
+ * below is the one the operator asked for, and it is the only one. Without that, `--fake` on a
16
+ * `Migration.OnStartup` connection would really apply the migrations it promises to merely
17
+ * record, because the boot pass would have executed them before this line is reached.
18
+ */
19
+ export declare class MigrateUpCommand extends CliCommand {
20
+ protected Log: Log;
21
+ execute(options: IMigrateUpCommandOptions): Promise<void>;
22
+ /**
23
+ * Turns an empty `up(name)` into a statement about what actually happened - and a non-zero exit
24
+ * code whenever the requested schema change is not in the database, so a deploy script cannot
25
+ * march past it believing "0 applied" meant "nothing left to do".
26
+ *
27
+ * `status()` here is deliberately NOT narrowed by `--connection`: with the filter on, "the
28
+ * migration lives on a connection this run excluded" is the likeliest reason the run was empty,
29
+ * and a narrowed report could not tell that from "not registered at all".
30
+ */
31
+ protected explainEmptyNamedRun(orm: Orm, name: string, connection?: string): Promise<void>;
32
+ }
33
+ //# sourceMappingURL=MigrateUp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrateUp.d.ts","sourceRoot":"","sources":["../../../src/cli/MigrateUp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,qBAIa,gBAAiB,SAAQ,UAAU;IAE9C,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBtE;;;;;;;;OAQG;cACa,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA6BjG"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MigrateUpCommand = void 0;
13
+ const cli_1 = require("@spinajs/cli");
14
+ const log_common_1 = require("@spinajs/log-common");
15
+ const orm_js_1 = require("../orm.js");
16
+ /**
17
+ * `orm.Migration` only exists on a RESOLVED Orm - it is assigned inside `Orm.resolve()`, once the
18
+ * connections it dispatches to have been created. So every command here resolves the Orm first
19
+ * and reaches the facade through it, rather than injecting a migration service directly.
20
+ *
21
+ * Through `resolveCliOrm()`, so that resolve does not run a migration pass of its own: the run
22
+ * below is the one the operator asked for, and it is the only one. Without that, `--fake` on a
23
+ * `Migration.OnStartup` connection would really apply the migrations it promises to merely
24
+ * record, because the boot pass would have executed them before this line is reached.
25
+ */
26
+ let MigrateUpCommand = class MigrateUpCommand extends cli_1.CliCommand {
27
+ async execute(options) {
28
+ const orm = await (0, orm_js_1.resolveCliOrm)();
29
+ const executed = await orm.Migration.up(options.name, { fake: options.fake, connection: options.connection });
30
+ if (executed.length > 0) {
31
+ this.Log.success(`${options.fake ? 'Recorded as applied ( --fake, nothing was executed )' : 'Applied'} ${executed.length} migration(s): ${executed.map((m) => m.constructor.name).join(', ')}`);
32
+ return;
33
+ }
34
+ if (!options.name) {
35
+ this.Log.info(options.connection ? `No pending migrations on connection ${options.connection} - it is already up to date ( --connection was given, other connections were not touched )` : 'No pending migrations - every configured connection is already up to date');
36
+ return;
37
+ }
38
+ // A named run that applied nothing is ambiguous at this level, and the two readings could not
39
+ // be further apart: the migration is already applied ( fine ), or it never ran because the
40
+ // connection it declares is missing from this deployment and the runner only WARNED about it.
41
+ // `up()` throws outright on a name nothing is registered under, so a typo is already excluded
42
+ // here. `status()` reports exactly the connections that ARE configured, which makes "absent
43
+ // from status" the reliable signal for the second case.
44
+ await this.explainEmptyNamedRun(orm, options.name, options.connection);
45
+ }
46
+ /**
47
+ * Turns an empty `up(name)` into a statement about what actually happened - and a non-zero exit
48
+ * code whenever the requested schema change is not in the database, so a deploy script cannot
49
+ * march past it believing "0 applied" meant "nothing left to do".
50
+ *
51
+ * `status()` here is deliberately NOT narrowed by `--connection`: with the filter on, "the
52
+ * migration lives on a connection this run excluded" is the likeliest reason the run was empty,
53
+ * and a narrowed report could not tell that from "not registered at all".
54
+ */
55
+ async explainEmptyNamedRun(orm, name, connection) {
56
+ const entry = (await orm.Migration.status()).find((e) => e.name === name);
57
+ if (!entry) {
58
+ this.Log.error(`Migration ${name} did NOT run: it is registered, but the connection it declares is not configured here ( or the class carries no @Migration('connection') decorator ). Nothing was applied.`);
59
+ process.exitCode = 1;
60
+ return;
61
+ }
62
+ if (entry.applied) {
63
+ this.Log.info(`Migration ${name} is already applied on connection ${entry.connection} ( batch ${entry.batch ?? '-'} ) - nothing to do`);
64
+ return;
65
+ }
66
+ // `--connection` resolves through aliases, so the requested name and the connection reported
67
+ // here can differ while naming the same driver. Stated as a possibility rather than as fact
68
+ // for exactly that reason - the alternative readings below are printed either way.
69
+ if (connection) {
70
+ this.Log.error(`Migration ${name} did NOT run, and --connection ${connection} was given while the migration belongs to connection ${entry.connection}. Drop --connection, or point it at ${entry.connection}.`);
71
+ }
72
+ if (entry.failed) {
73
+ this.Log.error(`Migration ${name} did NOT run - it is in the FAILED state on connection ${entry.connection}. It blocks every later migrate-up on that connection until migrate-resolve records what really happened.`);
74
+ }
75
+ else {
76
+ this.Log.error(`Migration ${name} did NOT run and is still pending on connection ${entry.connection} - check migrate-status`);
77
+ }
78
+ process.exitCode = 1;
79
+ }
80
+ };
81
+ exports.MigrateUpCommand = MigrateUpCommand;
82
+ __decorate([
83
+ (0, log_common_1.Logger)('ORM-CLI'),
84
+ __metadata("design:type", log_common_1.Log)
85
+ ], MigrateUpCommand.prototype, "Log", void 0);
86
+ exports.MigrateUpCommand = MigrateUpCommand = __decorate([
87
+ (0, cli_1.Command)('migrate-up', 'Runs pending ORM migrations on every configured connection'),
88
+ (0, cli_1.Option)('-n, --name [name]', false, 'run a single migration, by class name'),
89
+ (0, cli_1.Option)('-c, --connection [connection]', false, 'limit the run to one connection, by name'),
90
+ (0, cli_1.Option)('-f, --fake', false, 'record the migrations as applied without executing them')
91
+ ], MigrateUpCommand);
92
+ //# sourceMappingURL=MigrateUp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MigrateUp.js","sourceRoot":"","sources":["../../../src/cli/MigrateUp.ts"],"names":[],"mappings":";;;;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AC;8BACH,gBAAG;6CAAC;2BAFR,gBAAgB;IAJ5B,IAAA,aAAO,EAAC,YAAY,EAAE,4DAA4D,CAAC;IACnF,IAAA,YAAM,EAAC,mBAAmB,EAAE,KAAK,EAAE,uCAAuC,CAAC;IAC3E,IAAA,YAAM,EAAC,+BAA+B,EAAE,KAAK,EAAE,0CAA0C,CAAC;IAC1F,IAAA,YAAM,EAAC,YAAY,EAAE,KAAK,EAAE,yDAAyD,CAAC;GAC1E,gBAAgB,CAiE5B"}
@@ -0,0 +1,9 @@
1
+ declare const ormCli: {
2
+ system: {
3
+ dirs: {
4
+ cli: string[];
5
+ };
6
+ };
7
+ };
8
+ export default ormCli;
9
+ //# sourceMappingURL=orm-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orm-cli.d.ts","sourceRoot":"","sources":["../../../src/config/orm-cli.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,MAAM;;;;;;CAMX,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ /**
5
+ * Mirrors `@spinajs/cli`'s own config: `Cli` discovers commands by scanning `system.dirs.cli`,
6
+ * so a package that ships commands has to add its own command directory to that list or the
7
+ * classes are never handed to commander. `system.dirs.cli` is merged by concatenation, so this
8
+ * appends to whatever `@spinajs/cli` and the application already declared.
9
+ */
10
+ function dir(path) {
11
+ const inCommonJs = typeof module !== 'undefined';
12
+ return [
13
+ (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), 'node_modules', '@spinajs', 'orm-cli', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
14
+ // one up, for when the process runs from an app or build folder
15
+ (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), '../', 'node_modules', '@spinajs', 'orm-cli', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
16
+ ];
17
+ }
18
+ const ormCli = {
19
+ system: {
20
+ dirs: {
21
+ cli: [...dir('cli')],
22
+ },
23
+ },
24
+ };
25
+ exports.default = ormCli;
26
+ //# sourceMappingURL=orm-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orm-cli.js","sourceRoot":"","sources":["../../../src/config/orm-cli.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD;;;;;GAKG;AACH,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IAEjD,OAAO;QACL,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QAE1J,gEAAgE;QAChE,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;KAClK,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG;IACb,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;SACrB;KACF;CACF,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `@spinajs/orm-cli` - the migration commands, as plain DI-resolvable classes.
3
+ *
4
+ * Importing this module is enough to register all five with `@spinajs/cli`: `@Command` registers
5
+ * each class under `__cli_command__` the moment it is evaluated. The shipped
6
+ * `config/orm-cli` also appends this package's `cli` directory to `system.dirs.cli`, which is
7
+ * how `Cli` discovers them without the host application importing anything by hand.
8
+ *
9
+ * Nothing here is exported from `@spinajs/orm`: the dependency runs one way only, from orm-cli to
10
+ * orm, so the ORM stays usable ( and testable ) with no CLI in its dependency tree.
11
+ */
12
+ export * from './orm.js';
13
+ export * from './cli/MigrateUp.js';
14
+ export * from './cli/MigrateDown.js';
15
+ export * from './cli/MigrateStatus.js';
16
+ export * from './cli/MigrateResolve.js';
17
+ export * from './cli/MigrateCreate.js';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * `@spinajs/orm-cli` - the migration commands, as plain DI-resolvable classes.
19
+ *
20
+ * Importing this module is enough to register all five with `@spinajs/cli`: `@Command` registers
21
+ * each class under `__cli_command__` the moment it is evaluated. The shipped
22
+ * `config/orm-cli` also appends this package's `cli` directory to `system.dirs.cli`, which is
23
+ * how `Cli` discovers them without the host application importing anything by hand.
24
+ *
25
+ * Nothing here is exported from `@spinajs/orm`: the dependency runs one way only, from orm-cli to
26
+ * orm, so the ORM stays usable ( and testable ) with no CLI in its dependency tree.
27
+ */
28
+ __exportStar(require("./orm.js"), exports);
29
+ __exportStar(require("./cli/MigrateUp.js"), exports);
30
+ __exportStar(require("./cli/MigrateDown.js"), exports);
31
+ __exportStar(require("./cli/MigrateStatus.js"), exports);
32
+ __exportStar(require("./cli/MigrateResolve.js"), exports);
33
+ __exportStar(require("./cli/MigrateCreate.js"), exports);
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;GAUG;AACH,2CAAyB;AACzB,qDAAmC;AACnC,uDAAqC;AACrC,yDAAuC;AACvC,0DAAwC;AACxC,yDAAuC"}
@@ -0,0 +1,31 @@
1
+ import { IOrmOptions, Orm } from '@spinajs/orm';
2
+ /**
3
+ * `Orm.resolve()` normally ends with a migration pass - every pending migration on every
4
+ * connection whose `Migration.OnStartup` is on. For an application that is the point. For a
5
+ * process whose entire job is to operate on those migrations it is a trap, twice over:
6
+ *
7
+ * - a connection holding a FAILED row refuses every migration run, so `DI.resolve(Orm)` throws
8
+ * before the command body starts - including `migrate-resolve`, the one command that exists to
9
+ * clear that row. The error even names `orm.Migration.resolve(...)` as the remedy, which by
10
+ * then is unreachable except by editing the tracking table or the config by hand.
11
+ * - `migrate-status` would apply every pending migration and only then report - so the deploy
12
+ * gate asking "is this database current?" makes it current, answers "yes", and exits 0 with
13
+ * the DDL it was meant to gate already run.
14
+ *
15
+ * `migrate-up` and `migrate-down` take the same Orm: an operator running them explicitly gets
16
+ * exactly the run they asked for, once, rather than a boot pass followed by their own. It is
17
+ * what makes `migrate-up --fake` mean anything at all - a boot pass would have really applied
18
+ * the migrations the flag says to only record.
19
+ */
20
+ export declare const CLI_ORM_OPTIONS: IOrmOptions;
21
+ /**
22
+ * The Orm every command in this package runs against: fully resolved - connections, models,
23
+ * value converters, `orm.Migration` - with the boot migration pass suppressed.
24
+ *
25
+ * The suppression is honoured by the resolve that CONSTRUCTS the Orm; `Orm` is a DI singleton,
26
+ * so a host process that already resolved one gets that instance back and these options are
27
+ * ignored. Right answer either way: in a CLI process this call is the first, and a host that
28
+ * booted its own Orm has already run whatever its configuration asked for.
29
+ */
30
+ export declare function resolveCliOrm(): Promise<Orm>;
31
+ //# sourceMappingURL=orm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orm.d.ts","sourceRoot":"","sources":["../../src/orm.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,eAAe,EAAE,WAAyC,CAAC;AAExE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAAC,GAAG,CAAC,CAE5C"}
package/lib/cjs/orm.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLI_ORM_OPTIONS = void 0;
4
+ exports.resolveCliOrm = resolveCliOrm;
5
+ const di_1 = require("@spinajs/di");
6
+ const orm_1 = require("@spinajs/orm");
7
+ /**
8
+ * `Orm.resolve()` normally ends with a migration pass - every pending migration on every
9
+ * connection whose `Migration.OnStartup` is on. For an application that is the point. For a
10
+ * process whose entire job is to operate on those migrations it is a trap, twice over:
11
+ *
12
+ * - a connection holding a FAILED row refuses every migration run, so `DI.resolve(Orm)` throws
13
+ * before the command body starts - including `migrate-resolve`, the one command that exists to
14
+ * clear that row. The error even names `orm.Migration.resolve(...)` as the remedy, which by
15
+ * then is unreachable except by editing the tracking table or the config by hand.
16
+ * - `migrate-status` would apply every pending migration and only then report - so the deploy
17
+ * gate asking "is this database current?" makes it current, answers "yes", and exits 0 with
18
+ * the DDL it was meant to gate already run.
19
+ *
20
+ * `migrate-up` and `migrate-down` take the same Orm: an operator running them explicitly gets
21
+ * exactly the run they asked for, once, rather than a boot pass followed by their own. It is
22
+ * what makes `migrate-up --fake` mean anything at all - a boot pass would have really applied
23
+ * the migrations the flag says to only record.
24
+ */
25
+ exports.CLI_ORM_OPTIONS = { MigrateOnStartup: false };
26
+ /**
27
+ * The Orm every command in this package runs against: fully resolved - connections, models,
28
+ * value converters, `orm.Migration` - with the boot migration pass suppressed.
29
+ *
30
+ * The suppression is honoured by the resolve that CONSTRUCTS the Orm; `Orm` is a DI singleton,
31
+ * so a host process that already resolved one gets that instance back and these options are
32
+ * ignored. Right answer either way: in a CLI process this call is the first, and a host that
33
+ * booted its own Orm has already run whatever its configuration asked for.
34
+ */
35
+ function resolveCliOrm() {
36
+ return di_1.DI.resolve(orm_1.Orm, [exports.CLI_ORM_OPTIONS]);
37
+ }
38
+ //# sourceMappingURL=orm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../src/orm.ts"],"names":[],"mappings":";;;AAgCA,sCAEC;AAlCD,oCAAiC;AACjC,sCAAgD;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,eAAe,GAAgB,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;AAExE;;;;;;;;GAQG;AACH,SAAgB,aAAa;IAC3B,OAAO,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,uBAAe,CAAC,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}