@datacapy/migrate 0.1.0
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.
- package/LICENSE +29 -0
- package/README.md +658 -0
- package/dist/cli/command-parser.d.ts +18 -0
- package/dist/cli/command-parser.d.ts.map +1 -0
- package/dist/cli/command-parser.js +159 -0
- package/dist/cli/command-parser.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +22 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/runner.d.ts +6 -0
- package/dist/cli/runner.d.ts.map +1 -0
- package/dist/cli/runner.js +141 -0
- package/dist/cli/runner.js.map +1 -0
- package/dist/executor/patch-executor.d.ts +13 -0
- package/dist/executor/patch-executor.d.ts.map +1 -0
- package/dist/executor/patch-executor.js +58 -0
- package/dist/executor/patch-executor.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interface/context-resolver.d.ts +4 -0
- package/dist/interface/context-resolver.d.ts.map +1 -0
- package/dist/interface/context-resolver.js +3 -0
- package/dist/interface/context-resolver.js.map +1 -0
- package/dist/interface/database-patch.d.ts +8 -0
- package/dist/interface/database-patch.d.ts.map +1 -0
- package/dist/interface/database-patch.js +3 -0
- package/dist/interface/database-patch.js.map +1 -0
- package/dist/interface/index.d.ts +4 -0
- package/dist/interface/index.d.ts.map +1 -0
- package/dist/interface/index.js +20 -0
- package/dist/interface/index.js.map +1 -0
- package/dist/interface/migration-config.d.ts +26 -0
- package/dist/interface/migration-config.d.ts.map +1 -0
- package/dist/interface/migration-config.js +3 -0
- package/dist/interface/migration-config.js.map +1 -0
- package/dist/interface/migration-result.d.ts +31 -0
- package/dist/interface/migration-result.d.ts.map +1 -0
- package/dist/interface/migration-result.js +3 -0
- package/dist/interface/migration-result.js.map +1 -0
- package/dist/logger/migration-logger.d.ts +21 -0
- package/dist/logger/migration-logger.d.ts.map +1 -0
- package/dist/logger/migration-logger.js +78 -0
- package/dist/logger/migration-logger.js.map +1 -0
- package/dist/manager/migration-manager.d.ts +12 -0
- package/dist/manager/migration-manager.d.ts.map +1 -0
- package/dist/manager/migration-manager.js +262 -0
- package/dist/manager/migration-manager.js.map +1 -0
- package/dist/meta/meta-table.d.ts +22 -0
- package/dist/meta/meta-table.d.ts.map +1 -0
- package/dist/meta/meta-table.js +86 -0
- package/dist/meta/meta-table.js.map +1 -0
- package/dist/scanner/patch-scanner.d.ts +11 -0
- package/dist/scanner/patch-scanner.d.ts.map +1 -0
- package/dist/scanner/patch-scanner.js +166 -0
- package/dist/scanner/patch-scanner.js.map +1 -0
- package/dist/version/version-manager.d.ts +11 -0
- package/dist/version/version-manager.d.ts.map +1 -0
- package/dist/version/version-manager.js +90 -0
- package/dist/version/version-manager.js.map +1 -0
- package/package.json +51 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandParser = void 0;
|
|
4
|
+
class CommandParser {
|
|
5
|
+
static parse(args) {
|
|
6
|
+
const result = {
|
|
7
|
+
context: {},
|
|
8
|
+
dryRun: false,
|
|
9
|
+
verbose: false,
|
|
10
|
+
help: false,
|
|
11
|
+
version: false,
|
|
12
|
+
};
|
|
13
|
+
for (let i = 0; i < args.length; i++) {
|
|
14
|
+
const arg = args[i];
|
|
15
|
+
switch (arg) {
|
|
16
|
+
case "-c":
|
|
17
|
+
case "--config":
|
|
18
|
+
result.config = args[++i];
|
|
19
|
+
break;
|
|
20
|
+
case "--datasource":
|
|
21
|
+
result.datasource = args[++i];
|
|
22
|
+
break;
|
|
23
|
+
case "--context": {
|
|
24
|
+
const contextArg = args[++i];
|
|
25
|
+
if (!contextArg) {
|
|
26
|
+
throw new Error("--context requires a key=value argument");
|
|
27
|
+
}
|
|
28
|
+
const [key, value] = contextArg.split("=");
|
|
29
|
+
if (!key || !value) {
|
|
30
|
+
throw new Error(`Invalid context format: "${contextArg}". Expected format: key=value`);
|
|
31
|
+
}
|
|
32
|
+
result.context[key] = value;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case "--context-lookup":
|
|
36
|
+
result.contextLookup = args[++i];
|
|
37
|
+
break;
|
|
38
|
+
case "-d":
|
|
39
|
+
case "--patch-dir":
|
|
40
|
+
result.patchDirectory = args[++i];
|
|
41
|
+
break;
|
|
42
|
+
case "-t":
|
|
43
|
+
case "--target":
|
|
44
|
+
result.targetVersion = args[++i];
|
|
45
|
+
break;
|
|
46
|
+
case "--dry-run":
|
|
47
|
+
result.dryRun = true;
|
|
48
|
+
break;
|
|
49
|
+
case "-v":
|
|
50
|
+
case "--verbose":
|
|
51
|
+
result.verbose = true;
|
|
52
|
+
break;
|
|
53
|
+
case "-h":
|
|
54
|
+
case "--help":
|
|
55
|
+
result.help = true;
|
|
56
|
+
break;
|
|
57
|
+
case "--version":
|
|
58
|
+
result.version = true;
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
static validate(args) {
|
|
67
|
+
if (args.help || args.version) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!args.config) {
|
|
71
|
+
throw new Error("Missing required argument: --config");
|
|
72
|
+
}
|
|
73
|
+
if (!args.datasource) {
|
|
74
|
+
throw new Error("Missing required argument: --datasource");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static getHelpText() {
|
|
78
|
+
return `
|
|
79
|
+
@datacapy/migrate - Database migration tool for @datacapy/om applications
|
|
80
|
+
|
|
81
|
+
USAGE:
|
|
82
|
+
@datacapy/migrate [OPTIONS]
|
|
83
|
+
|
|
84
|
+
REQUIRED OPTIONS:
|
|
85
|
+
-c, --config <file> Path to migration config file
|
|
86
|
+
--datasource <name> Target datasource name (e.g., 'db', 'project')
|
|
87
|
+
|
|
88
|
+
OPTIONAL OPTIONS:
|
|
89
|
+
--context <key=value> Context for dynamic datasources (can be specified multiple times)
|
|
90
|
+
Example: --context projectId=abc123
|
|
91
|
+
--context-lookup <pattern> Lookup pattern for batch migrations across multiple contexts
|
|
92
|
+
Example: --context-lookup "*" (migrate all projects)
|
|
93
|
+
Requires contextResolver to be configured
|
|
94
|
+
-d, --patch-dir <dir> Patch directory (default: ./migrate)
|
|
95
|
+
-t, --target <version> Target version to migrate to (default: latest)
|
|
96
|
+
Format: YYYY-MM-DD_HHMM
|
|
97
|
+
--dry-run Preview migration without making changes
|
|
98
|
+
-v, --verbose Enable verbose logging
|
|
99
|
+
-h, --help Show this help message
|
|
100
|
+
--version Show package version
|
|
101
|
+
|
|
102
|
+
EXAMPLES:
|
|
103
|
+
# Migrate account-level database
|
|
104
|
+
@datacapy/migrate --config ./migrate.config.js --datasource db
|
|
105
|
+
|
|
106
|
+
# Migrate specific project database
|
|
107
|
+
@datacapy/migrate --config ./migrate.config.js --datasource project --context projectId=abc123
|
|
108
|
+
|
|
109
|
+
# Migrate ALL project databases (batch migration)
|
|
110
|
+
@datacapy/migrate --config ./migrate.config.js --datasource project --context-lookup "*"
|
|
111
|
+
|
|
112
|
+
# Dry run to preview changes
|
|
113
|
+
@datacapy/migrate --config ./migrate.config.js --datasource db --dry-run
|
|
114
|
+
|
|
115
|
+
# Migrate to specific version
|
|
116
|
+
@datacapy/migrate --config ./migrate.config.js --datasource db --target 2024-02-05_1430
|
|
117
|
+
|
|
118
|
+
# Verbose output
|
|
119
|
+
@datacapy/migrate --config ./migrate.config.js --datasource db --verbose
|
|
120
|
+
|
|
121
|
+
CONFIG FILE FORMAT:
|
|
122
|
+
The config file should export an async function that returns a MigrationConfig object:
|
|
123
|
+
|
|
124
|
+
// migrate.config.js
|
|
125
|
+
const modelManager = require('./src/model-manager').default
|
|
126
|
+
|
|
127
|
+
module.exports = async () => {
|
|
128
|
+
return {
|
|
129
|
+
modelManager, // Existing ModelManager instance
|
|
130
|
+
patchDirectory: './migrate'
|
|
131
|
+
// dataSourceName and context provided via CLI arguments
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
PATCH FILE FORMAT:
|
|
136
|
+
Patches must be placed in: <patchDir>/YYYY/MM/YYYY-MM-DD_HHMM_label.(ts|tsx|js)
|
|
137
|
+
|
|
138
|
+
Example patch:
|
|
139
|
+
// migrate/2024/02/2024-02-05_1430_add-users-table.ts
|
|
140
|
+
import { DatabasePatchInterface } from '@datacapy/migrate'
|
|
141
|
+
import { ModelManager } from '@datacapy/om'
|
|
142
|
+
|
|
143
|
+
export default class AddUsersTable implements DatabasePatchInterface {
|
|
144
|
+
version = '2024-02-05_1430'
|
|
145
|
+
description = 'Add users table'
|
|
146
|
+
dataSourceName = 'db'
|
|
147
|
+
|
|
148
|
+
async update(modelManager: ModelManager): Promise<void> {
|
|
149
|
+
const dataSource = modelManager.getDataSource('db')
|
|
150
|
+
// Your migration logic here
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
For more information, visit: https://github.com/datacapy/datacapy
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.CommandParser = CommandParser;
|
|
159
|
+
//# sourceMappingURL=command-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-parser.js","sourceRoot":"","sources":["../../src/cli/command-parser.ts"],"names":[],"mappings":";;;AAmBA,MAAa,aAAa;IAOxB,MAAM,CAAC,KAAK,CAAC,IAAc;QACzB,MAAM,MAAM,GAAiB;YAC3B,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,KAAK;SACf,CAAC;QAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,C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ER,KAAK,WAAW;oBACd,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;oBACrB,MAAM;gBAER,KAAK,IAAI,CAAC;gBACV,KAAK,WAAW;oBACd,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;oBACtB,MAAM;gBAER,KAAK,IAAI,CAAC;gBACV,KAAK,QAAQ;oBACX,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;oBACnB,MAAM;gBAER,KAAK,WAAW;oBACd,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;oBACtB,MAAM;gBAER;oBACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAQD,MAAM,CAAC,QAAQ,CAAC,IAAkB;QAEhC,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QAGD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,CAAC;QAGD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAKD,MAAM,CAAC,WAAW;QAChB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6EV,CAAC;IACA,CAAC;CACF;AAhMD,sCAgMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const runner_1 = require("./runner");
|
|
5
|
+
async function main() {
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const exitCode = await runner_1.CliRunner.run(args);
|
|
8
|
+
process.exit(exitCode);
|
|
9
|
+
}
|
|
10
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
11
|
+
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
|
14
|
+
process.on("uncaughtException", (error) => {
|
|
15
|
+
console.error("Uncaught Exception:", error);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
18
|
+
main().catch((error) => {
|
|
19
|
+
console.error("Fatal error:", error);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAEA,qCAAqC;AAQrC,KAAK,UAAU,IAAI;IACjB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,MAAM,kBAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC;AAGD,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;IACnD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAGH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;IACxC,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAGH,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/cli/runner.ts"],"names":[],"mappings":"AAUA,qBAAa,SAAS;WAOP,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;mBAqE5B,UAAU;IA4B/B,OAAO,CAAC,MAAM,CAAC,YAAY;CA8C5B"}
|
|
@@ -0,0 +1,141 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CliRunner = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const command_parser_1 = require("./command-parser");
|
|
39
|
+
const migration_manager_1 = require("../manager/migration-manager");
|
|
40
|
+
class CliRunner {
|
|
41
|
+
static async run(args) {
|
|
42
|
+
try {
|
|
43
|
+
const cliArgs = command_parser_1.CommandParser.parse(args);
|
|
44
|
+
if (cliArgs.help) {
|
|
45
|
+
console.log(command_parser_1.CommandParser.getHelpText());
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
if (cliArgs.version) {
|
|
49
|
+
const packageJson = require("../../package.json");
|
|
50
|
+
console.log(`@datacapy/migrate v${packageJson.version}`);
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
command_parser_1.CommandParser.validate(cliArgs);
|
|
54
|
+
const config = await this.loadConfig(cliArgs);
|
|
55
|
+
if (!config.modelManager) {
|
|
56
|
+
throw new Error("Config file must provide a modelManager instance");
|
|
57
|
+
}
|
|
58
|
+
const migrationConfig = {
|
|
59
|
+
...config,
|
|
60
|
+
modelManager: config.modelManager,
|
|
61
|
+
dataSourceName: cliArgs.datasource,
|
|
62
|
+
context: Object.keys(cliArgs.context).length > 0
|
|
63
|
+
? cliArgs.context
|
|
64
|
+
: config.context,
|
|
65
|
+
contextLookup: cliArgs.contextLookup,
|
|
66
|
+
contextResolver: config.contextResolver,
|
|
67
|
+
patchDirectory: cliArgs.patchDirectory || config.patchDirectory,
|
|
68
|
+
targetVersion: cliArgs.targetVersion || config.targetVersion,
|
|
69
|
+
dryRun: cliArgs.dryRun || config.dryRun,
|
|
70
|
+
verbose: cliArgs.verbose || config.verbose,
|
|
71
|
+
};
|
|
72
|
+
const manager = new migration_manager_1.MigrationManager(migrationConfig);
|
|
73
|
+
const result = await manager.migrate();
|
|
74
|
+
this.printSummary(result);
|
|
75
|
+
return result.failedCount > 0 ? 1 : 0;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
if (error instanceof Error && error.stack) {
|
|
80
|
+
console.error(error.stack);
|
|
81
|
+
}
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
static async loadConfig(cliArgs) {
|
|
86
|
+
const configPath = path.resolve(cliArgs.config);
|
|
87
|
+
try {
|
|
88
|
+
delete require.cache[require.resolve(configPath)];
|
|
89
|
+
const configModule = require(configPath);
|
|
90
|
+
const configExport = configModule.default || configModule;
|
|
91
|
+
if (typeof configExport === "function") {
|
|
92
|
+
return await configExport();
|
|
93
|
+
}
|
|
94
|
+
return configExport;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new Error(`Failed to load config file "${configPath}": ${error instanceof Error ? error.message : String(error)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
static printSummary(result) {
|
|
101
|
+
console.log("\n" + "=".repeat(60));
|
|
102
|
+
console.log("MIGRATION SUMMARY");
|
|
103
|
+
console.log("=".repeat(60));
|
|
104
|
+
if (result.dryRun) {
|
|
105
|
+
console.log("Mode: DRY RUN (no changes applied)");
|
|
106
|
+
}
|
|
107
|
+
console.log(`Previous version: ${result.previousVersion}`);
|
|
108
|
+
console.log(`Current version: ${result.currentVersion}`);
|
|
109
|
+
console.log(`Total patches: ${result.totalPatches}`);
|
|
110
|
+
console.log(`Successful: ${result.successCount}`);
|
|
111
|
+
console.log(`Failed: ${result.failedCount}`);
|
|
112
|
+
console.log(`Skipped: ${result.skippedCount}`);
|
|
113
|
+
console.log(`Duration: ${result.totalDuration}ms`);
|
|
114
|
+
if (result.patchResults && result.patchResults.length > 0) {
|
|
115
|
+
console.log("\nPATCH DETAILS:");
|
|
116
|
+
for (const patch of result.patchResults) {
|
|
117
|
+
const status = patch.status === "success"
|
|
118
|
+
? "✓"
|
|
119
|
+
: patch.status === "failed"
|
|
120
|
+
? "✗"
|
|
121
|
+
: "⊘";
|
|
122
|
+
console.log(` ${status} ${patch.version} - ${patch.description} (${patch.duration}ms)`);
|
|
123
|
+
if (patch.error) {
|
|
124
|
+
console.log(` Error: ${patch.error.message}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
console.log("=".repeat(60) + "\n");
|
|
129
|
+
if (result.failedCount > 0) {
|
|
130
|
+
console.log("❌ Migration completed with errors");
|
|
131
|
+
}
|
|
132
|
+
else if (result.totalPatches === 0) {
|
|
133
|
+
console.log("✓ Database is up to date");
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
console.log("✓ Migration completed successfully");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.CliRunner = CliRunner;
|
|
141
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/cli/runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,qDAA+D;AAC/D,oEAAgE;AAQhE,MAAa,SAAS;IAOpB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAc;QAC7B,IAAI,CAAC;YAEH,MAAM,OAAO,GAAG,8BAAa,C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M,GACV,KAAK,CAAC,MAAM,KAAK,SAAS;oBACxB,CAAC,CAAC,GAAG;oBACL,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ;wBACzB,CAAC,CAAC,GAAG;wBACL,CAAC,CAAC,GAAG,CAAC;gBACZ,OAAO,CAAC,GAAG,CACT,KAAK,MAAM,IAAI,KAAK,CAAC,OAAO,MAAM,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC,QAAQ,KAAK,CAC5E,CAAC;gBAEF,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;oBAChB,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAEnC,IAAI,MAAM,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACnD,CAAC;aAAM,IAAI,MAAM,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF;AAtJD,8BAsJC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DatabasePatchInterface } from "../interface/database-patch";
|
|
2
|
+
import { PatchResult } from "../interface/migration-result";
|
|
3
|
+
import { ModelManager, DataSourceContext } from "@datacapy/om";
|
|
4
|
+
import { MigrationLogger } from "../logger/migration-logger";
|
|
5
|
+
export declare class PatchExecutor {
|
|
6
|
+
private modelManager;
|
|
7
|
+
private logger;
|
|
8
|
+
private dryRun;
|
|
9
|
+
constructor(modelManager: ModelManager, logger: MigrationLogger, dryRun?: boolean);
|
|
10
|
+
executePatch(patch: DatabasePatchInterface, context: DataSourceContext): Promise<PatchResult>;
|
|
11
|
+
executePatches(patches: DatabasePatchInterface[], context: DataSourceContext, stopOnError?: boolean): Promise<PatchResult[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=patch-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-executor.d.ts","sourceRoot":"","sources":["../../src/executor/patch-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAe7D,qBAAa,aAAa;IACxB,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAU;gBAGtB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,eAAe,EACvB,MAAM,GAAE,OAAe;IAenB,YAAY,CAChB,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,WAAW,CAAC;IAwDjB,cAAc,CAClB,OAAO,EAAE,sBAAsB,EAAE,EACjC,OAAO,EAAE,iBAAiB,EAC1B,WAAW,GAAE,OAAc,GAC1B,OAAO,CAAC,WAAW,EAAE,CAAC;CAkB1B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PatchExecutor = void 0;
|
|
4
|
+
class PatchExecutor {
|
|
5
|
+
constructor(modelManager, logger, dryRun = false) {
|
|
6
|
+
this.modelManager = modelManager;
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
this.dryRun = dryRun;
|
|
9
|
+
}
|
|
10
|
+
async executePatch(patch, context) {
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
const result = {
|
|
13
|
+
version: patch.version,
|
|
14
|
+
description: patch.description,
|
|
15
|
+
dataSourceName: patch.dataSourceName,
|
|
16
|
+
status: "success",
|
|
17
|
+
duration: 0,
|
|
18
|
+
timestamp: new Date(),
|
|
19
|
+
};
|
|
20
|
+
this.logger.logPatchStart(patch.version, patch.description);
|
|
21
|
+
if (this.dryRun) {
|
|
22
|
+
result.status = "skipped";
|
|
23
|
+
result.duration = Date.now() - startTime;
|
|
24
|
+
this.logger.logPatchSkipped(patch.version, "dry-run mode");
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await patch.update(this.modelManager, context);
|
|
29
|
+
result.status = "success";
|
|
30
|
+
result.duration = Date.now() - startTime;
|
|
31
|
+
this.logger.logPatchSuccess(patch.version, result.duration);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
result.status = "failed";
|
|
35
|
+
result.duration = Date.now() - startTime;
|
|
36
|
+
result.error = {
|
|
37
|
+
message: error instanceof Error ? error.message : String(error),
|
|
38
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
39
|
+
};
|
|
40
|
+
this.logger.logPatchFailure(patch.version, error instanceof Error ? error : new Error(String(error)));
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
async executePatches(patches, context, stopOnError = true) {
|
|
45
|
+
const results = [];
|
|
46
|
+
for (const patch of patches) {
|
|
47
|
+
const result = await this.executePatch(patch, context);
|
|
48
|
+
results.push(result);
|
|
49
|
+
if (result.status === "failed" && stopOnError) {
|
|
50
|
+
this.logger.error(`Stopping migration due to failed patch: ${patch.version}`);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.PatchExecutor = PatchExecutor;
|
|
58
|
+
//# sourceMappingURL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F,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAxGD,sCAwGC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { MigrationManager } from "./manager/migration-manager.js";
|
|
2
|
+
export { VersionManager } from "./version/version-manager.js";
|
|
3
|
+
export { MetaTable, MetaRecord } from "./meta/meta-table.js";
|
|
4
|
+
export { PatchScanner } from "./scanner/patch-scanner.js";
|
|
5
|
+
export { PatchExecutor } from "./executor/patch-executor.js";
|
|
6
|
+
export { MigrationLogger } from "./logger/migration-logger.js";
|
|
7
|
+
export { DatabasePatchInterface } from "./interface/database-patch.js";
|
|
8
|
+
export { ContextResolver } from "./interface/context-resolver.js";
|
|
9
|
+
export { MigrationConfig, MigrationConfigResolved, } from "./interface/migration-config.js";
|
|
10
|
+
export { MigrationResult, PatchResult, PatchFile, } from "./interface/migration-result.js";
|
|
11
|
+
export { CommandParser, CliArguments } from "./cli/command-parser.js";
|
|
12
|
+
export { CliRunner } from "./cli/runner.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EACL,eAAe,EACf,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,eAAe,EACf,WAAW,EACX,SAAS,GACV,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliRunner = exports.CommandParser = exports.MigrationLogger = exports.PatchExecutor = exports.PatchScanner = exports.MetaTable = exports.VersionManager = exports.MigrationManager = void 0;
|
|
4
|
+
var migration_manager_1 = require("./manager/migration-manager.js");
|
|
5
|
+
Object.defineProperty(exports, "MigrationManager", { enumerable: true, get: function () { return migration_manager_1.MigrationManager; } });
|
|
6
|
+
var version_manager_1 = require("./version/version-manager.js");
|
|
7
|
+
Object.defineProperty(exports, "VersionManager", { enumerable: true, get: function () { return version_manager_1.VersionManager; } });
|
|
8
|
+
var meta_table_1 = require("./meta/meta-table.js");
|
|
9
|
+
Object.defineProperty(exports, "MetaTable", { enumerable: true, get: function () { return meta_table_1.MetaTable; } });
|
|
10
|
+
var patch_scanner_1 = require("./scanner/patch-scanner.js");
|
|
11
|
+
Object.defineProperty(exports, "PatchScanner", { enumerable: true, get: function () { return patch_scanner_1.PatchScanner; } });
|
|
12
|
+
var patch_executor_1 = require("./executor/patch-executor.js");
|
|
13
|
+
Object.defineProperty(exports, "PatchExecutor", { enumerable: true, get: function () { return patch_executor_1.PatchExecutor; } });
|
|
14
|
+
var migration_logger_1 = require("./logger/migration-logger.js");
|
|
15
|
+
Object.defineProperty(exports, "MigrationLogger", { enumerable: true, get: function () { return migration_logger_1.MigrationLogger; } });
|
|
16
|
+
var command_parser_1 = require("./cli/command-parser.js");
|
|
17
|
+
Object.defineProperty(exports, "CommandParser", { enumerable: true, get: function () { return command_parser_1.CommandParser; } });
|
|
18
|
+
var runner_1 = require("./cli/runner.js");
|
|
19
|
+
Object.defineProperty(exports, "CliRunner", { enumerable: true, get: function () { return runner_1.CliRunner; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAOA,iEAA+D;AAAtD,qHAAA,gBAAgB,OAAA;AACzB,6DAA2D;AAAlD,iHAAA,cAAc,OAAA;AACvB,gDAA0D;AAAjD,uGAAA,SAAS,OAAA;AAClB,yDAAuD;AAA9C,6GAAA,YAAY,OAAA;AACrB,4DAA0D;AAAjD,+GAAA,aAAa,OAAA;AACtB,8DAA4D;AAAnD,mHAAA,eAAe,OAAA;AAkBxB,uDAAmE;AAA1D,+GAAA,aAAa,OAAA;AACtB,uCAAyC;AAAhC,mGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-resolver.d.ts","sourceRoot":"","sources":["../../src/interface/context-resolver.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,eAAe;IAM9B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CAClE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-resolver.js","sourceRoot":"","sources":["../../src/interface/context-resolver.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModelManager, DataSourceContext } from "@datacapy/om";
|
|
2
|
+
export interface DatabasePatchInterface {
|
|
3
|
+
version: string;
|
|
4
|
+
description: string;
|
|
5
|
+
dataSourceName: string;
|
|
6
|
+
update(modelManager: ModelManager, context: DataSourceContext): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=database-patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-patch.d.ts","sourceRoot":"","sources":["../../src/interface/database-patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAQ/D,MAAM,WAAW,sBAAsB;IAKrC,OAAO,EAAE,MAAM,CAAC;IAMhB,WAAW,EAAE,MAAM,CAAC;IAOpB,cAAc,EAAE,MAAM,CAAC;IAWvB,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-patch.js","sourceRoot":"","sources":["../../src/interface/database-patch.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
__exportStar(require("./database-patch"), exports);
|
|
18
|
+
__exportStar(require("./migration-config"), exports);
|
|
19
|
+
__exportStar(require("./migration-result"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,qDAAmC;AACnC,qDAAmC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ModelManager } from "@datacapy/om";
|
|
2
|
+
import { DataSourceContext } from "@datacapy/om/dist/data-source";
|
|
3
|
+
import { ContextResolver } from "./context-resolver";
|
|
4
|
+
export interface MigrationConfig {
|
|
5
|
+
modelManager: ModelManager;
|
|
6
|
+
dataSourceName: string;
|
|
7
|
+
context?: DataSourceContext | Record<string, string>;
|
|
8
|
+
contextLookup?: string;
|
|
9
|
+
contextResolver?: ContextResolver;
|
|
10
|
+
patchDirectory?: string;
|
|
11
|
+
targetVersion?: string;
|
|
12
|
+
metaTableName?: string;
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
stopOnError?: boolean;
|
|
16
|
+
logger?: (message: string, level?: "info" | "warn" | "error") => void;
|
|
17
|
+
}
|
|
18
|
+
export interface MigrationConfigResolved extends MigrationConfig {
|
|
19
|
+
patchDirectory: string;
|
|
20
|
+
targetVersion: string;
|
|
21
|
+
metaTableName: string;
|
|
22
|
+
dryRun: boolean;
|
|
23
|
+
verbose: boolean;
|
|
24
|
+
stopOnError: boolean;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=migration-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-config.d.ts","sourceRoot":"","sources":["../../src/interface/migration-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAOrD,MAAM,WAAW,eAAe;IAK9B,YAAY,EAAE,YAAY,CAAC;IAQ3B,cAAc,EAAE,MAAM,CAAC;IASvB,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAQrD,aAAa,CAAC,EAAE,MAAM,CAAC;IAOvB,eAAe,CAAC,EAAE,eAAe,CAAC;IAQlC,cAAc,CAAC,EAAE,MAAM,CAAC;IAMxB,aAAa,CAAC,EAAE,MAAM,CAAC;IAOvB,aAAa,CAAC,EAAE,MAAM,CAAC;IAOvB,MAAM,CAAC,EAAE,OAAO,CAAC;IAMjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAMlB,WAAW,CAAC,EAAE,OAAO,CAAC;IAOtB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,KAAK,IAAI,CAAC;CACvE;AAOD,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-config.js","sourceRoot":"","sources":["../../src/interface/migration-config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface PatchResult {
|
|
2
|
+
version: string;
|
|
3
|
+
description: string;
|
|
4
|
+
dataSourceName: string;
|
|
5
|
+
status: "success" | "failed" | "skipped";
|
|
6
|
+
duration: number;
|
|
7
|
+
error?: {
|
|
8
|
+
message: string;
|
|
9
|
+
stack?: string;
|
|
10
|
+
};
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
}
|
|
13
|
+
export interface MigrationResult {
|
|
14
|
+
totalPatches: number;
|
|
15
|
+
successCount: number;
|
|
16
|
+
failedCount: number;
|
|
17
|
+
skippedCount: number;
|
|
18
|
+
patchResults: PatchResult[];
|
|
19
|
+
previousVersion: string;
|
|
20
|
+
currentVersion: string;
|
|
21
|
+
totalDuration: number;
|
|
22
|
+
dryRun: boolean;
|
|
23
|
+
startTime: Date;
|
|
24
|
+
endTime: Date;
|
|
25
|
+
}
|
|
26
|
+
export interface PatchFile {
|
|
27
|
+
version: string;
|
|
28
|
+
filePath: string;
|
|
29
|
+
patch: any;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=migration-result.d.ts.map
|