@lenne.tech/nest-server 11.3.0 → 11.4.1
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/bin/migrate.js +40 -0
- package/dist/core/modules/migrate/cli/migrate-cli.d.ts +3 -0
- package/dist/core/modules/migrate/cli/migrate-cli.js +221 -0
- package/dist/core/modules/migrate/cli/migrate-cli.js.map +1 -0
- package/dist/core/modules/migrate/helpers/migration.helper.d.ts +12 -0
- package/dist/core/modules/migrate/helpers/migration.helper.js +57 -0
- package/dist/core/modules/migrate/helpers/migration.helper.js.map +1 -0
- package/dist/core/modules/migrate/helpers/ts-compiler.d.ts +2 -0
- package/dist/core/modules/migrate/helpers/ts-compiler.js +3 -0
- package/dist/core/modules/migrate/helpers/ts-compiler.js.map +1 -0
- package/dist/core/modules/migrate/index.d.ts +4 -0
- package/dist/core/modules/migrate/index.js +21 -0
- package/dist/core/modules/migrate/index.js.map +1 -0
- package/dist/core/modules/migrate/migration-runner.d.ts +26 -0
- package/dist/core/modules/migrate/migration-runner.js +124 -0
- package/dist/core/modules/migrate/migration-runner.js.map +1 -0
- package/dist/core/modules/migrate/mongo-state-store.d.ts +30 -0
- package/dist/core/modules/migrate/mongo-state-store.js +105 -0
- package/dist/core/modules/migrate/mongo-state-store.js.map +1 -0
- package/dist/core/modules/migrate/templates/migration-project.template.ts +53 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +9 -3
- package/src/core/modules/migrate/MIGRATION_FROM_NODEPIT.md +298 -0
- package/src/core/modules/migrate/README.md +453 -0
- package/src/core/modules/migrate/cli/migrate-cli.ts +319 -0
- package/src/core/modules/migrate/helpers/migration.helper.ts +117 -0
- package/src/core/modules/migrate/helpers/ts-compiler.js +14 -0
- package/src/core/modules/migrate/index.ts +41 -0
- package/src/core/modules/migrate/migration-runner.ts +230 -0
- package/src/core/modules/migrate/mongo-state-store.ts +283 -0
- package/src/core/modules/migrate/templates/migration-project.template.ts +53 -0
- package/src/index.ts +9 -3
package/bin/migrate.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Migration CLI wrapper
|
|
5
|
+
*
|
|
6
|
+
* This is a shim that makes the nest-server migration CLI available as "migrate"
|
|
7
|
+
* for drop-in compatibility with projects using the @nodepit/migrate package.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
// Check if running from built dist or src
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const distPath = path.join(__dirname, '../dist/core/modules/migrate/cli/migrate-cli.js');
|
|
15
|
+
const srcPath = path.join(__dirname, '../src/core/modules/migrate/cli/migrate-cli.ts');
|
|
16
|
+
|
|
17
|
+
let cliPath;
|
|
18
|
+
|
|
19
|
+
if (fs.existsSync(distPath)) {
|
|
20
|
+
// Production: use built version
|
|
21
|
+
cliPath = distPath;
|
|
22
|
+
} else if (fs.existsSync(srcPath)) {
|
|
23
|
+
// Development: register ts-node and use source
|
|
24
|
+
try {
|
|
25
|
+
require('ts-node/register');
|
|
26
|
+
cliPath = srcPath;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error('Error: ts-node is required in development mode');
|
|
29
|
+
console.error('Install it with: npm install --save-dev ts-node');
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
console.error('Error: Migration CLI not found');
|
|
34
|
+
console.error('Make sure @lenne.tech/nest-server is properly built');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Load and run the CLI
|
|
39
|
+
const { main } = require(cliPath);
|
|
40
|
+
main();
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.main = main;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const migration_runner_1 = require("../migration-runner");
|
|
8
|
+
async function createMigration(name, options) {
|
|
9
|
+
if (!name) {
|
|
10
|
+
console.error('Error: Migration name is required');
|
|
11
|
+
console.log('Usage: migrate create <name> [options]');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
const timestamp = Date.now();
|
|
15
|
+
const fileName = `${timestamp}-${name}.ts`;
|
|
16
|
+
const filePath = path.join(options.migrationsDir, fileName);
|
|
17
|
+
if (!fs.existsSync(options.migrationsDir)) {
|
|
18
|
+
fs.mkdirSync(options.migrationsDir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
let template;
|
|
21
|
+
if (options.templateFile) {
|
|
22
|
+
const templatePath = path.resolve(process.cwd(), options.templateFile);
|
|
23
|
+
template = fs.readFileSync(templatePath, 'utf-8');
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
template = `/**
|
|
27
|
+
* Migration: ${name}
|
|
28
|
+
* Created: ${new Date().toISOString()}
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export const up = async () => {
|
|
32
|
+
// TODO: Implement migration
|
|
33
|
+
console.log('Running migration: ${name}');
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const down = async () => {
|
|
37
|
+
// TODO: Implement rollback
|
|
38
|
+
console.log('Rolling back migration: ${name}');
|
|
39
|
+
};
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
fs.writeFileSync(filePath, template, 'utf-8');
|
|
43
|
+
console.log(`Created migration: ${fileName}`);
|
|
44
|
+
}
|
|
45
|
+
async function listMigrations(options) {
|
|
46
|
+
registerCompiler(options.compiler);
|
|
47
|
+
const stateStore = loadStateStore(options.store);
|
|
48
|
+
const runner = new migration_runner_1.MigrationRunner({
|
|
49
|
+
migrationsDirectory: options.migrationsDir,
|
|
50
|
+
stateStore,
|
|
51
|
+
});
|
|
52
|
+
const status = await runner.status();
|
|
53
|
+
console.log('\nMigration Status:');
|
|
54
|
+
console.log('=================\n');
|
|
55
|
+
if (status.completed.length > 0) {
|
|
56
|
+
console.log('Completed:');
|
|
57
|
+
status.completed.forEach((name) => {
|
|
58
|
+
console.log(` ✓ ${name}`);
|
|
59
|
+
});
|
|
60
|
+
console.log('');
|
|
61
|
+
}
|
|
62
|
+
if (status.pending.length > 0) {
|
|
63
|
+
console.log('Pending:');
|
|
64
|
+
status.pending.forEach((name) => {
|
|
65
|
+
console.log(` ⋯ ${name}`);
|
|
66
|
+
});
|
|
67
|
+
console.log('');
|
|
68
|
+
}
|
|
69
|
+
if (status.completed.length === 0 && status.pending.length === 0) {
|
|
70
|
+
console.log('No migrations found\n');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function loadStateStore(storePath) {
|
|
74
|
+
if (!storePath) {
|
|
75
|
+
throw new Error('--store option is required for up/down/list commands');
|
|
76
|
+
}
|
|
77
|
+
const absolutePath = path.resolve(process.cwd(), storePath);
|
|
78
|
+
const StoreClass = require(absolutePath);
|
|
79
|
+
if (StoreClass.default) {
|
|
80
|
+
return new StoreClass.default();
|
|
81
|
+
}
|
|
82
|
+
else if (typeof StoreClass === 'function') {
|
|
83
|
+
return new StoreClass();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error(`Invalid state store module at ${storePath}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function main() {
|
|
90
|
+
const { command, name, options } = parseArgs();
|
|
91
|
+
try {
|
|
92
|
+
switch (command) {
|
|
93
|
+
case '--help':
|
|
94
|
+
case '-h':
|
|
95
|
+
case 'help':
|
|
96
|
+
showHelp();
|
|
97
|
+
break;
|
|
98
|
+
case 'create':
|
|
99
|
+
await createMigration(name, options);
|
|
100
|
+
break;
|
|
101
|
+
case 'down':
|
|
102
|
+
await runDown(options);
|
|
103
|
+
break;
|
|
104
|
+
case 'list':
|
|
105
|
+
case 'status':
|
|
106
|
+
await listMigrations(options);
|
|
107
|
+
break;
|
|
108
|
+
case 'up':
|
|
109
|
+
await runUp(options);
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
if (!command) {
|
|
113
|
+
showHelp();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.error(`Unknown command: ${command}`);
|
|
117
|
+
console.log('Run "migrate --help" for usage information');
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error('Error:', error.message);
|
|
124
|
+
if (process.env.DEBUG) {
|
|
125
|
+
console.error(error.stack);
|
|
126
|
+
}
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function parseArgs() {
|
|
131
|
+
const args = process.argv.slice(2);
|
|
132
|
+
const command = args[0];
|
|
133
|
+
let name;
|
|
134
|
+
const options = {
|
|
135
|
+
migrationsDir: './migrations',
|
|
136
|
+
};
|
|
137
|
+
if (args[1] && !args[1].startsWith('-')) {
|
|
138
|
+
name = args[1];
|
|
139
|
+
}
|
|
140
|
+
for (let i = 1; i < args.length; i++) {
|
|
141
|
+
const arg = args[i];
|
|
142
|
+
if (arg === '--migrations-dir' || arg === '-d') {
|
|
143
|
+
options.migrationsDir = args[++i];
|
|
144
|
+
}
|
|
145
|
+
else if (arg === '--store' || arg === '-s') {
|
|
146
|
+
options.store = args[++i];
|
|
147
|
+
}
|
|
148
|
+
else if (arg === '--compiler' || arg === '-c') {
|
|
149
|
+
options.compiler = args[++i];
|
|
150
|
+
}
|
|
151
|
+
else if (arg === '--template-file' || arg === '-t') {
|
|
152
|
+
options.templateFile = args[++i];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { command, name, options };
|
|
156
|
+
}
|
|
157
|
+
function registerCompiler(compiler) {
|
|
158
|
+
if (!compiler) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const [type, compilerPath] = compiler.split(':');
|
|
162
|
+
if (type === 'ts' && compilerPath) {
|
|
163
|
+
const absolutePath = path.resolve(process.cwd(), compilerPath);
|
|
164
|
+
const register = require(absolutePath);
|
|
165
|
+
if (typeof register === 'function') {
|
|
166
|
+
register();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function runDown(options) {
|
|
171
|
+
registerCompiler(options.compiler);
|
|
172
|
+
const stateStore = loadStateStore(options.store);
|
|
173
|
+
const runner = new migration_runner_1.MigrationRunner({
|
|
174
|
+
migrationsDirectory: options.migrationsDir,
|
|
175
|
+
stateStore,
|
|
176
|
+
});
|
|
177
|
+
await runner.down();
|
|
178
|
+
}
|
|
179
|
+
async function runUp(options) {
|
|
180
|
+
registerCompiler(options.compiler);
|
|
181
|
+
const stateStore = loadStateStore(options.store);
|
|
182
|
+
const runner = new migration_runner_1.MigrationRunner({
|
|
183
|
+
migrationsDirectory: options.migrationsDir,
|
|
184
|
+
stateStore,
|
|
185
|
+
});
|
|
186
|
+
await runner.up();
|
|
187
|
+
}
|
|
188
|
+
function showHelp() {
|
|
189
|
+
console.log(`
|
|
190
|
+
Migration CLI - Compatible with migrate package
|
|
191
|
+
|
|
192
|
+
Usage:
|
|
193
|
+
migrate create <name> [options] Create a new migration
|
|
194
|
+
migrate up [options] Run all pending migrations
|
|
195
|
+
migrate down [options] Rollback the last migration
|
|
196
|
+
migrate list [options] List migration status
|
|
197
|
+
|
|
198
|
+
Options:
|
|
199
|
+
--migrations-dir, -d <path> Directory containing migrations (default: ./migrations)
|
|
200
|
+
--store, -s <path> Path to state store module
|
|
201
|
+
--compiler, -c <compiler> Compiler to use (e.g., ts:./path/to/ts-compiler.js)
|
|
202
|
+
--template-file, -t <path> Template file for creating migrations
|
|
203
|
+
|
|
204
|
+
Examples:
|
|
205
|
+
migrate create add-user-email
|
|
206
|
+
migrate create add-user-email --template-file ./migrations-utils/template.ts
|
|
207
|
+
migrate up --store ./migrations-utils/migrate.js --migrations-dir ./migrations
|
|
208
|
+
migrate down --store ./migrations-utils/migrate.js
|
|
209
|
+
migrate list --store ./migrations-utils/migrate.js
|
|
210
|
+
|
|
211
|
+
Environment Variables:
|
|
212
|
+
NODE_ENV Set environment (e.g., development, production)
|
|
213
|
+
`);
|
|
214
|
+
}
|
|
215
|
+
if (require.main === module) {
|
|
216
|
+
main().catch((error) => {
|
|
217
|
+
console.error('Fatal error:', error);
|
|
218
|
+
process.exit(1);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=migrate-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-cli.js","sourceRoot":"","sources":["../../../../../src/core/modules/migrate/cli/migrate-cli.ts"],"names":[],"mappings":";;;AA8TS,oBAAI;AAtSb,yBAAyB;AACzB,6BAA6B;AAE7B,0DAAsD;AAatD,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,OAAmB;IAC9D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,GAAG,SAAS,IAAI,IAAI,KAAK,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAG5D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1C,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,QAAgB,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AAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Db, ObjectId } from 'mongodb';
|
|
2
|
+
export declare const getDb: (mongoUrl: string) => Promise<Db>;
|
|
3
|
+
export declare const uploadFileToGridFS: (mongoUrl: string, relativePath: string, options?: {
|
|
4
|
+
bucketName?: string;
|
|
5
|
+
filename?: string;
|
|
6
|
+
}) => Promise<ObjectId>;
|
|
7
|
+
export declare const createMigrationStore: (mongoUrl: string, collectionName?: string, lockCollectionName?: string) => {
|
|
8
|
+
new (): {
|
|
9
|
+
[x: string]: any;
|
|
10
|
+
};
|
|
11
|
+
[x: string]: any;
|
|
12
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMigrationStore = exports.uploadFileToGridFS = exports.getDb = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const mongodb_1 = require("mongodb");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const getDb = async (mongoUrl) => {
|
|
8
|
+
const client = await mongodb_1.MongoClient.connect(mongoUrl);
|
|
9
|
+
return client.db();
|
|
10
|
+
};
|
|
11
|
+
exports.getDb = getDb;
|
|
12
|
+
const uploadFileToGridFS = async (mongoUrl, relativePath, options) => {
|
|
13
|
+
if (!relativePath) {
|
|
14
|
+
throw new Error('relativePath is required');
|
|
15
|
+
}
|
|
16
|
+
const { bucketName, filename } = {
|
|
17
|
+
bucketName: 'fs',
|
|
18
|
+
filename: relativePath.split('/')[relativePath.split('/').length - 1],
|
|
19
|
+
...options,
|
|
20
|
+
};
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
22
|
+
let client;
|
|
23
|
+
try {
|
|
24
|
+
client = await mongodb_1.MongoClient.connect(mongoUrl);
|
|
25
|
+
const db = client.db();
|
|
26
|
+
const bucket = new mongodb_1.GridFSBucket(db, { bucketName });
|
|
27
|
+
const writeStream = bucket.openUploadStream(filename);
|
|
28
|
+
const rs = fs.createReadStream(path.resolve(__dirname, relativePath)).pipe(writeStream);
|
|
29
|
+
rs.on('finish', () => {
|
|
30
|
+
resolve(writeStream.id);
|
|
31
|
+
});
|
|
32
|
+
rs.on('error', (err) => {
|
|
33
|
+
reject(err);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
reject(err);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
exports.uploadFileToGridFS = uploadFileToGridFS;
|
|
44
|
+
const createMigrationStore = (mongoUrl, collectionName = 'migrations', lockCollectionName) => {
|
|
45
|
+
const { MongoStateStore } = require('../mongo-state-store');
|
|
46
|
+
return class MigrationStateStore extends MongoStateStore {
|
|
47
|
+
constructor() {
|
|
48
|
+
super({
|
|
49
|
+
collectionName,
|
|
50
|
+
lockCollectionName,
|
|
51
|
+
uri: mongoUrl,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.createMigrationStore = createMigrationStore;
|
|
57
|
+
//# sourceMappingURL=migration.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.helper.js","sourceRoot":"","sources":["../../../../../src/core/modules/migrate/helpers/migration.helper.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,qCAAkE;AAClE,6BAA6B;AAkBtB,MAAM,KAAK,GAAG,KAAK,EAAE,QAAgB,EAAe,EAAE;IAC3D,MAAM,MAAM,GAAgB,MAAM,qBAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC,EAAE,EAAE,CAAC;AACrB,CAAC,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AAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;gBAAS,CAAC;QAGX,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAvCW,QAAA,kBAAkB,sBAuC7B;AAmBK,MAAM,oBAAoB,GAAG,CAClC,QAAgB,EAChB,iBAAyB,YAAY,EACrC,kBAA2B,EAC3B,EAAE;IACF,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAE5D,OAAO,MAAM,mBAAoB,SAAQ,eAAe;QACtD;YACE,KAAK,CAAC;gBACJ,cAAc;gBACd,kBAAkB;gBAClB,GAAG,EAAE,QAAQ;aACd,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,oBAAoB,wBAgB/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ts-compiler.js","sourceRoot":"","sources":["../../../../../src/core/modules/migrate/helpers/ts-compiler.js"],"names":[],"mappings":"AAWA,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAElC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./cli/migrate-cli"), exports);
|
|
18
|
+
__exportStar(require("./helpers/migration.helper"), exports);
|
|
19
|
+
__exportStar(require("./migration-runner"), exports);
|
|
20
|
+
__exportStar(require("./mongo-state-store"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/modules/migrate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAqCA,oDAAkC;AAClC,6DAA2C;AAC3C,qDAAmC;AACnC,sDAAoC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MongoStateStore } from './mongo-state-store';
|
|
2
|
+
export interface MigrationFile {
|
|
3
|
+
down?: () => Promise<void>;
|
|
4
|
+
filePath: string;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
title: string;
|
|
7
|
+
up: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface MigrationRunnerOptions {
|
|
10
|
+
migrationsDirectory: string;
|
|
11
|
+
pattern?: RegExp;
|
|
12
|
+
stateStore: MongoStateStore;
|
|
13
|
+
}
|
|
14
|
+
export declare class MigrationRunner {
|
|
15
|
+
private options;
|
|
16
|
+
private pattern;
|
|
17
|
+
constructor(options: MigrationRunnerOptions);
|
|
18
|
+
private loadMigrationFiles;
|
|
19
|
+
up(): Promise<void>;
|
|
20
|
+
down(): Promise<void>;
|
|
21
|
+
status(): Promise<{
|
|
22
|
+
completed: string[];
|
|
23
|
+
pending: string[];
|
|
24
|
+
}>;
|
|
25
|
+
static create(migrationsDirectory: string, name: string): Promise<string>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MigrationRunner = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
class MigrationRunner {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
this.pattern = options.pattern || /\.(ts|js)$/;
|
|
10
|
+
}
|
|
11
|
+
async loadMigrationFiles() {
|
|
12
|
+
const files = fs
|
|
13
|
+
.readdirSync(this.options.migrationsDirectory)
|
|
14
|
+
.filter((file) => this.pattern.test(file))
|
|
15
|
+
.sort();
|
|
16
|
+
const migrations = [];
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const filePath = path.join(this.options.migrationsDirectory, file);
|
|
19
|
+
const module = require(filePath);
|
|
20
|
+
if (!module.up) {
|
|
21
|
+
console.warn(`Migration ${file} has no 'up' function, skipping...`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const timestampMatch = file.match(/^(\d+)-/);
|
|
25
|
+
const timestamp = timestampMatch ? parseInt(timestampMatch[1], 10) : Date.now();
|
|
26
|
+
migrations.push({
|
|
27
|
+
down: module.down,
|
|
28
|
+
filePath,
|
|
29
|
+
timestamp,
|
|
30
|
+
title: file,
|
|
31
|
+
up: module.up,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return migrations;
|
|
35
|
+
}
|
|
36
|
+
async up() {
|
|
37
|
+
const allMigrations = await this.loadMigrationFiles();
|
|
38
|
+
const state = await this.options.stateStore.loadAsync();
|
|
39
|
+
const completedMigrations = (state.migrations || []).map((m) => m.title);
|
|
40
|
+
const pendingMigrations = allMigrations.filter((m) => !completedMigrations.includes(m.title));
|
|
41
|
+
if (pendingMigrations.length === 0) {
|
|
42
|
+
console.log('No pending migrations');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
console.log(`Running ${pendingMigrations.length} pending migration(s)...`);
|
|
46
|
+
for (const migration of pendingMigrations) {
|
|
47
|
+
console.log(`Running migration: ${migration.title}`);
|
|
48
|
+
await migration.up();
|
|
49
|
+
const newState = await this.options.stateStore.loadAsync();
|
|
50
|
+
const migrations = newState.migrations || [];
|
|
51
|
+
migrations.push({
|
|
52
|
+
timestamp: migration.timestamp,
|
|
53
|
+
title: migration.title,
|
|
54
|
+
});
|
|
55
|
+
await this.options.stateStore.saveAsync({
|
|
56
|
+
lastRun: migration.title,
|
|
57
|
+
migrations,
|
|
58
|
+
up: () => { },
|
|
59
|
+
});
|
|
60
|
+
console.log(`✓ Migration completed: ${migration.title}`);
|
|
61
|
+
}
|
|
62
|
+
console.log('All migrations completed successfully');
|
|
63
|
+
}
|
|
64
|
+
async down() {
|
|
65
|
+
const state = await this.options.stateStore.loadAsync();
|
|
66
|
+
const completedMigrations = state.migrations || [];
|
|
67
|
+
if (completedMigrations.length === 0) {
|
|
68
|
+
console.log('No migrations to rollback');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const lastMigration = completedMigrations[completedMigrations.length - 1];
|
|
72
|
+
const allMigrations = await this.loadMigrationFiles();
|
|
73
|
+
const migrationToRollback = allMigrations.find((m) => m.title === lastMigration.title);
|
|
74
|
+
if (!migrationToRollback) {
|
|
75
|
+
throw new Error(`Migration file not found: ${lastMigration.title}`);
|
|
76
|
+
}
|
|
77
|
+
if (!migrationToRollback.down) {
|
|
78
|
+
throw new Error(`Migration ${lastMigration.title} has no 'down' function`);
|
|
79
|
+
}
|
|
80
|
+
console.log(`Rolling back migration: ${migrationToRollback.title}`);
|
|
81
|
+
await migrationToRollback.down();
|
|
82
|
+
const newMigrations = completedMigrations.slice(0, -1);
|
|
83
|
+
await this.options.stateStore.saveAsync({
|
|
84
|
+
lastRun: newMigrations.length > 0 ? newMigrations[newMigrations.length - 1].title : undefined,
|
|
85
|
+
migrations: newMigrations,
|
|
86
|
+
up: () => { },
|
|
87
|
+
});
|
|
88
|
+
console.log(`✓ Migration rolled back: ${migrationToRollback.title}`);
|
|
89
|
+
}
|
|
90
|
+
async status() {
|
|
91
|
+
const allMigrations = await this.loadMigrationFiles();
|
|
92
|
+
const state = await this.options.stateStore.loadAsync();
|
|
93
|
+
const completedMigrations = (state.migrations || []).map((m) => m.title);
|
|
94
|
+
return {
|
|
95
|
+
completed: completedMigrations,
|
|
96
|
+
pending: allMigrations.filter((m) => !completedMigrations.includes(m.title)).map((m) => m.title),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
static async create(migrationsDirectory, name) {
|
|
100
|
+
const timestamp = Date.now();
|
|
101
|
+
const fileName = `${timestamp}-${name}.ts`;
|
|
102
|
+
const filePath = path.join(migrationsDirectory, fileName);
|
|
103
|
+
const template = `/**
|
|
104
|
+
* Migration: ${name}
|
|
105
|
+
* Created: ${new Date().toISOString()}
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
export const up = async () => {
|
|
109
|
+
// TODO: Implement migration
|
|
110
|
+
console.log('Running migration: ${name}');
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const down = async () => {
|
|
114
|
+
// TODO: Implement rollback
|
|
115
|
+
console.log('Rolling back migration: ${name}');
|
|
116
|
+
};
|
|
117
|
+
`;
|
|
118
|
+
fs.writeFileSync(filePath, template, 'utf-8');
|
|
119
|
+
console.log(`✓ Created migration: ${fileName}`);
|
|
120
|
+
return filePath;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.MigrationRunner = MigrationRunner;
|
|
124
|
+
//# sourceMappingURL=migration-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../../../src/core/modules/migrate/migration-runner.ts"],"names":[],"mappings":";;;AAGA,yBAAyB;AACzB,6BAA6B;AAsD7B,MAAa,eAAe;IAI1B,YAAY,OAA+B;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAA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AI;;CAE5C,CAAC;QAEE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;QAEhD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA3KD,0CA2KC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface MigrationOptions {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
stateStore: MongoStateStore;
|
|
4
|
+
}
|
|
5
|
+
export interface MigrationSet {
|
|
6
|
+
down?: (done?: (err?: Error) => void) => void;
|
|
7
|
+
lastRun?: string;
|
|
8
|
+
migrations: Array<{
|
|
9
|
+
timestamp?: number;
|
|
10
|
+
title: string;
|
|
11
|
+
}>;
|
|
12
|
+
up: (done?: (err?: Error) => void) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface MongoStateStoreOptions {
|
|
15
|
+
collectionName?: string;
|
|
16
|
+
lockCollectionName?: string;
|
|
17
|
+
uri: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class MongoStateStore {
|
|
20
|
+
private readonly collectionName;
|
|
21
|
+
readonly mongodbHost: string;
|
|
22
|
+
readonly lockCollectionName?: string;
|
|
23
|
+
constructor(objectOrHost: MongoStateStoreOptions | string);
|
|
24
|
+
load(fn: (err?: Error, set?: MigrationSet) => void): void;
|
|
25
|
+
loadAsync(): Promise<MigrationSet>;
|
|
26
|
+
save(set: MigrationSet, fn: (err?: Error) => void): void;
|
|
27
|
+
saveAsync(set: MigrationSet): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function synchronizedMigration(opts: MigrationOptions, callback: (set: MigrationSet) => Promise<void>): Promise<void>;
|
|
30
|
+
export declare function synchronizedUp(opts: MigrationOptions): Promise<void>;
|