forge-sql-orm 1.0.13 → 1.0.16

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/dist-cli/cli.mjs DELETED
@@ -1,570 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import dotenv from "dotenv";
4
- import inquirer from "inquirer";
5
- import "reflect-metadata";
6
- import path from "path";
7
- import fs from "fs";
8
- import { defineConfig, MongoNamingStrategy, MikroORM } from "@mikro-orm/mysql";
9
- import { EntityGenerator } from "@mikro-orm/entity-generator";
10
- const regenerateIndexFile = (outputPath) => {
11
- const entitiesDir = path.resolve(outputPath);
12
- const indexPath = path.join(entitiesDir, "index.ts");
13
- const entityFiles = fs.readdirSync(entitiesDir).filter((file) => file.endsWith(".ts") && file !== "index.ts");
14
- const imports = entityFiles.map((file) => {
15
- const entityName = path.basename(file, ".ts");
16
- return `import { ${entityName} } from "./${entityName}";`;
17
- });
18
- const indexContent = `${imports.join("\n")}
19
-
20
- export default [${entityFiles.map((file) => path.basename(file, ".ts")).join(", ")}];
21
- `;
22
- fs.writeFileSync(indexPath, indexContent, "utf8");
23
- console.log(`✅ Updated index.ts with ${entityFiles.length} entities.`);
24
- };
25
- const generateModels = async (options) => {
26
- try {
27
- const ormConfig = defineConfig({
28
- host: options.host,
29
- port: options.port,
30
- user: options.user,
31
- password: options.password,
32
- dbName: options.dbName,
33
- namingStrategy: MongoNamingStrategy,
34
- discovery: { warnWhenNoEntities: false },
35
- extensions: [EntityGenerator],
36
- debug: true
37
- });
38
- const orm = MikroORM.initSync(ormConfig);
39
- console.log(`✅ Connected to ${options.dbName} at ${options.host}:${options.port}`);
40
- await orm.entityGenerator.generate({
41
- entitySchema: true,
42
- bidirectionalRelations: false,
43
- identifiedReferences: false,
44
- forceUndefined: true,
45
- undefinedDefaults: true,
46
- useCoreBaseEntity: false,
47
- onlyPurePivotTables: false,
48
- outputPurePivotTables: false,
49
- scalarPropertiesForRelations: "always",
50
- save: true,
51
- path: options.output
52
- });
53
- regenerateIndexFile(options.output);
54
- console.log(`✅ Entities generated at: ${options.output}`);
55
- process.exit(0);
56
- } catch (error) {
57
- console.error(`❌ Error generating entities:`, error);
58
- process.exit(1);
59
- }
60
- };
61
- function cleanSQLStatement$1(sql) {
62
- return sql.replace(/\s+default\s+character\s+set\s+utf8mb4\s+engine\s*=\s*InnoDB;?/gi, "").trim();
63
- }
64
- function generateMigrationFile$1(createStatements, version) {
65
- const versionPrefix = `v${version}_MIGRATION`;
66
- const migrationLines = createStatements.map(
67
- (stmt, index) => ` .enqueue("${versionPrefix}${index}", "${cleanSQLStatement$1(stmt)}")`
68
- // eslint-disable-line no-useless-escape
69
- ).join("\n");
70
- return `import { MigrationRunner } from "@forge/sql/out/migration";
71
-
72
- export default (migrationRunner: MigrationRunner): MigrationRunner => {
73
- return migrationRunner
74
- ${migrationLines};
75
- };`;
76
- }
77
- function saveMigrationFiles$1(migrationCode, version, outputDir) {
78
- if (!fs.existsSync(outputDir)) {
79
- fs.mkdirSync(outputDir, { recursive: true });
80
- }
81
- const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);
82
- const migrationCountPath = path.join(outputDir, `migrationCount.ts`);
83
- const indexFilePath = path.join(outputDir, `index.ts`);
84
- fs.writeFileSync(migrationFilePath, migrationCode);
85
- fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);
86
- const indexFileContent = `import { MigrationRunner } from "@forge/sql/out/migration";
87
- import { MIGRATION_VERSION } from "./migrationCount";
88
-
89
- export type MigrationType = (
90
- migrationRunner: MigrationRunner,
91
- ) => MigrationRunner;
92
-
93
- export default async (
94
- migrationRunner: MigrationRunner,
95
- ): Promise<MigrationRunner> => {
96
- for (let i = 1; i <= MIGRATION_VERSION; i++) {
97
- const migrations = (await import(\`./migrationV\${i}\`)) as {
98
- default: MigrationType;
99
- };
100
- migrations.default(migrationRunner);
101
- }
102
- return migrationRunner;
103
- };`;
104
- fs.writeFileSync(indexFilePath, indexFileContent);
105
- console.log(`✅ Migration file created: ${migrationFilePath}`);
106
- console.log(`✅ Migration count file updated: ${migrationCountPath}`);
107
- console.log(`✅ Migration index file created: ${indexFilePath}`);
108
- }
109
- const extractCreateStatements$1 = (schema) => {
110
- const statements = schema.split(";").map((s) => s.trim());
111
- return statements.filter(
112
- (stmt) => stmt.startsWith("create table") || stmt.startsWith("alter table") && stmt.includes("add index") || stmt.startsWith("primary")
113
- );
114
- };
115
- const loadEntities$1 = async (entitiesPath) => {
116
- try {
117
- const indexFilePath = path.resolve(path.join(entitiesPath, "index.ts"));
118
- if (!fs.existsSync(indexFilePath)) {
119
- console.error(`❌ Error: index.ts not found in ${entitiesPath}`);
120
- process.exit(1);
121
- }
122
- const { default: entities } = await import(indexFilePath);
123
- console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);
124
- return entities;
125
- } catch (error) {
126
- console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);
127
- process.exit(1);
128
- }
129
- };
130
- const loadMigrationVersion$1 = async (migrationPath) => {
131
- try {
132
- const migrationCountFilePath = path.resolve(path.join(migrationPath, "migrationCount.ts"));
133
- if (!fs.existsSync(migrationCountFilePath)) {
134
- return 0;
135
- }
136
- const { MIGRATION_VERSION } = await import(migrationCountFilePath);
137
- console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);
138
- return MIGRATION_VERSION;
139
- } catch (error) {
140
- console.error(`❌ Error loading migrationCount:`, error);
141
- process.exit(1);
142
- }
143
- };
144
- const createMigration = async (options) => {
145
- try {
146
- let version = await loadMigrationVersion$1(options.output);
147
- if (version > 0) {
148
- console.error(`❌ Error: Migration has already been created.`);
149
- process.exit(1);
150
- }
151
- version = 1;
152
- const entities = await loadEntities$1(options.entitiesPath);
153
- const orm = MikroORM.initSync({
154
- host: options.host,
155
- port: options.port,
156
- user: options.user,
157
- password: options.password,
158
- dbName: options.dbName,
159
- entities
160
- });
161
- const createSchemaSQL = await orm.schema.getCreateSchemaSQL({ wrap: true });
162
- const statements = extractCreateStatements$1(createSchemaSQL);
163
- const migrationFile = generateMigrationFile$1(statements, version);
164
- saveMigrationFiles$1(migrationFile, version, options.output);
165
- console.log(`✅ Migration successfully created!`);
166
- process.exit(0);
167
- } catch (error) {
168
- console.error(`❌ Error during migration creation:`, error);
169
- process.exit(1);
170
- }
171
- };
172
- function cleanSQLStatement(sql) {
173
- return sql.replace(/\s+default\s+character\s+set\s+utf8mb4\s+engine\s*=\s*InnoDB;?/gi, "").trim();
174
- }
175
- function generateMigrationFile(createStatements, version) {
176
- const versionPrefix = `v${version}_MIGRATION`;
177
- const migrationLines = createStatements.map(
178
- (stmt, index) => ` .enqueue("${versionPrefix}${index}", "${cleanSQLStatement(stmt)}")`
179
- // eslint-disable-line no-useless-escape
180
- ).join("\n");
181
- return `import { MigrationRunner } from "@forge/sql/out/migration";
182
-
183
- export default (migrationRunner: MigrationRunner): MigrationRunner => {
184
- return migrationRunner
185
- ${migrationLines};
186
- };`;
187
- }
188
- function saveMigrationFiles(migrationCode, version, outputDir) {
189
- if (!fs.existsSync(outputDir)) {
190
- fs.mkdirSync(outputDir, { recursive: true });
191
- }
192
- const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);
193
- const migrationCountPath = path.join(outputDir, `migrationCount.ts`);
194
- const indexFilePath = path.join(outputDir, `index.ts`);
195
- fs.writeFileSync(migrationFilePath, migrationCode);
196
- fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);
197
- const indexFileContent = `import { MigrationRunner } from "@forge/sql/out/migration";
198
- import { MIGRATION_VERSION } from "./migrationCount";
199
-
200
- export type MigrationType = (
201
- migrationRunner: MigrationRunner,
202
- ) => MigrationRunner;
203
-
204
- export default async (
205
- migrationRunner: MigrationRunner,
206
- ): Promise<MigrationRunner> => {
207
- for (let i = 1; i <= MIGRATION_VERSION; i++) {
208
- const migrations = (await import(\`./migrationV\${i}\`)) as {
209
- default: MigrationType;
210
- };
211
- migrations.default(migrationRunner);
212
- }
213
- return migrationRunner;
214
- };`;
215
- fs.writeFileSync(indexFilePath, indexFileContent);
216
- console.log(`✅ Migration file created: ${migrationFilePath}`);
217
- console.log(`✅ Migration count file updated: ${migrationCountPath}`);
218
- console.log(`✅ Migration index file created: ${indexFilePath}`);
219
- }
220
- const extractCreateStatements = (schema) => {
221
- const statements = schema.split(";").map((s) => s.trim());
222
- return statements.filter(
223
- (stmt) => stmt.startsWith("create table") || stmt.startsWith("alter table") && stmt.includes("add index") || stmt.startsWith("alter table") && stmt.includes("add") && !stmt.includes("foreign") || stmt.startsWith("alter table") && stmt.includes("modify") && !stmt.includes("foreign")
224
- );
225
- };
226
- const loadEntities = async (entitiesPath) => {
227
- try {
228
- const indexFilePath = path.resolve(path.join(entitiesPath, "index.ts"));
229
- if (!fs.existsSync(indexFilePath)) {
230
- console.error(`❌ Error: index.ts not found in ${entitiesPath}`);
231
- process.exit(1);
232
- }
233
- const { default: entities } = await import(indexFilePath);
234
- console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);
235
- return entities;
236
- } catch (error) {
237
- console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);
238
- process.exit(1);
239
- }
240
- };
241
- const loadMigrationVersion = async (migrationPath) => {
242
- try {
243
- const migrationCountFilePath = path.resolve(path.join(migrationPath, "migrationCount.ts"));
244
- if (!fs.existsSync(migrationCountFilePath)) {
245
- console.warn(
246
- `⚠️ Warning: migrationCount.ts not found in ${migrationCountFilePath}, assuming no previous migrations.`
247
- );
248
- return 0;
249
- }
250
- const { MIGRATION_VERSION } = await import(migrationCountFilePath);
251
- console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);
252
- return MIGRATION_VERSION;
253
- } catch (error) {
254
- console.error(`❌ Error loading migrationCount:`, error);
255
- process.exit(1);
256
- }
257
- };
258
- const updateMigration = async (options) => {
259
- try {
260
- let version = await loadMigrationVersion(options.output);
261
- if (version < 1) {
262
- console.log(
263
- `⚠️ Initial migration not found. Run "npx forge-sql-orm migrations:create" first.`
264
- );
265
- process.exit(0);
266
- }
267
- version += 1;
268
- const entities = await loadEntities(options.entitiesPath);
269
- const orm = MikroORM.initSync({
270
- host: options.host,
271
- port: options.port,
272
- user: options.user,
273
- password: options.password,
274
- dbName: options.dbName,
275
- entities,
276
- debug: true
277
- });
278
- const createSchemaSQL = await orm.schema.getUpdateSchemaMigrationSQL({ wrap: true });
279
- const statements = extractCreateStatements(createSchemaSQL?.down || "");
280
- if (statements.length) {
281
- const migrationFile = generateMigrationFile(statements, version);
282
- saveMigrationFiles(migrationFile, version, options.output);
283
- console.log(`✅ Migration successfully updated!`);
284
- process.exit(0);
285
- } else {
286
- console.log(`⚠️ No new migration changes detected.`);
287
- process.exit(0);
288
- }
289
- } catch (error) {
290
- console.error(`❌ Error during migration update:`, error);
291
- process.exit(1);
292
- }
293
- };
294
- const PATCHES = [
295
- // 🗑️ Remove unused dialects (mssql, postgres, sqlite) in MikroORM
296
- {
297
- file: "node_modules/@mikro-orm/knex/MonkeyPatchable.d.ts",
298
- deleteLines: [/^.*mssql.*$/gim, /^.*MsSql.*$/gim, /^\s*Postgres.*$/gm, /^.*Sqlite3.*$/gm, /^.*BetterSqlite3.*$/gim],
299
- description: "Removing unused dialects from MonkeyPatchable.d.ts"
300
- },
301
- {
302
- file: "node_modules/@mikro-orm/knex/MonkeyPatchable.js",
303
- deleteLines: [/^.*mssql.*$/gim, /^.*MsSql.*$/gim, /^.*postgres.*$/gim, /^.*sqlite.*$/gim, /^.*Sqlite.*$/gim],
304
- description: "Removing unused dialects from MonkeyPatchable.js"
305
- },
306
- {
307
- file: "node_modules/@mikro-orm/knex/dialects/index.js",
308
- deleteLines: [/^.*mssql.*$/gim, /^.*MsSql.*$/gim, /^.*postgresql.*$/gim, /^.*sqlite.*$/gim],
309
- description: "Removing unused dialects from @mikro-orm/knex/dialects/index.js"
310
- },
311
- {
312
- deleteFolder: "node_modules/@mikro-orm/knex/dialects/mssql",
313
- description: "Removing mssql dialect from MikroORM"
314
- },
315
- {
316
- deleteFolder: "node_modules/@mikro-orm/knex/dialects/postgresql",
317
- description: "Removing postgresql dialect from MikroORM"
318
- },
319
- {
320
- deleteFolder: "node_modules/@mikro-orm/knex/dialects/sqlite",
321
- description: "Removing sqlite dialect from MikroORM"
322
- },
323
- // 🔄 Fix Webpack `Critical dependency: the request of a dependency is an expression`
324
- {
325
- file: "node_modules/@mikro-orm/core/utils/Configuration.js",
326
- search: /dynamicImportProvider:\s*\/\* istanbul ignore next \*\/\s*\(id\) => import\(id\),/g,
327
- replace: "dynamicImportProvider: /* istanbul ignore next */ () => Promise.resolve({}),",
328
- description: "Fixing dynamic imports in MikroORM Configuration"
329
- },
330
- {
331
- file: "node_modules/@mikro-orm/core/utils/Utils.js",
332
- search: /static dynamicImportProvider = \(id\) => import\(id\);/g,
333
- replace: "static dynamicImportProvider = () => Promise.resolve({});",
334
- description: "Fixing dynamic imports in MikroORM Utils.js"
335
- },
336
- // 🛑 Remove deprecated `require.extensions` usage
337
- {
338
- file: "node_modules/@mikro-orm/core/utils/Utils.js",
339
- search: /\s\|\|\s*\(require\.extensions\s*&&\s*!!require\.extensions\['\.ts'\]\);\s*/g,
340
- replace: ";",
341
- description: "Removing deprecated `require.extensions` check in MikroORM"
342
- },
343
- // 🛠️ Patch Knex to remove `Migrator` and `Seeder`
344
- {
345
- file: "node_modules/knex/lib/knex-builder/make-knex.js",
346
- deleteLines: [/^const \{ Migrator \} = require\('\.\.\/migrations\/migrate\/Migrator'\);$/gm, /^const Seeder = require\('\.\.\/migrations\/seed\/Seeder'\);$/gm],
347
- description: "Removing `Migrator` and `Seeder` requires from make-knex.js"
348
- },
349
- {
350
- file: "node_modules/knex/lib/knex-builder/make-knex.js",
351
- search: /\sreturn new Migrator\(this\);/g,
352
- replace: "return null;",
353
- description: "Replacing `return new Migrator(this);` with `return null;`"
354
- },
355
- {
356
- file: "node_modules/knex/lib/knex-builder/make-knex.js",
357
- search: /\sreturn new Seeder\(this\);/g,
358
- replace: "return null;",
359
- description: "Replacing `return new Seeder(this);` with `return null;`"
360
- },
361
- // 🔄 Patch for MikroORM Entity Generator to use 'forge-sql-orm'
362
- // {
363
- // file: "node_modules/@mikro-orm/entity-generator/SourceFile.js",
364
- // search: /^.* from '@mikro-orm.*$/gim,
365
- // replace: " }).join(', '))} } from 'forge-sql-orm';`);",
366
- // description: "Replacing entity generator imports with 'forge-sql-orm'"
367
- // },
368
- {
369
- file: "node_modules/knex/lib/dialects/index.js",
370
- deleteLines: [/^.*mssql.*$/gim, /^.*MsSql.*$/gim, /^.*postgresql.*$/gim, /^.*sqlite.*$/gim, /^.*oracle.*$/gim, /^.*oracledb.*$/gim, /^.*pgnative.*$/gim, /^.*postgres.*$/gim, /^.*redshift.*$/gim, /^.*sqlite3.*$/gim, /^.*cockroachdb.*$/gim],
371
- description: "Removing unused dialects from @mikro-orm/knex/dialects/index.js"
372
- },
373
- {
374
- file: "node_modules/@mikro-orm/core/utils/Utils.js",
375
- search: /\s\|\|\s*\(require\.extensions\s*&&\s*!!require\.extensions\['\.ts'\]\);\s*/g,
376
- replace: ";",
377
- // Replaces with semicolon to keep syntax valid
378
- description: "Removing deprecated `require.extensions` check from MikroORM"
379
- },
380
- {
381
- file: "node_modules/@mikro-orm/core/utils/Utils.js",
382
- search: /^.*extensions.*$/gim,
383
- replace: "{",
384
- // Replaces with semicolon to keep syntax valid
385
- description: "Removing deprecated `require.extensions` check from MikroORM"
386
- },
387
- {
388
- file: "node_modules/@mikro-orm/core/utils/Utils.js",
389
- search: /^.*package.json.*$/gim,
390
- replace: "return 0;",
391
- // Replaces with semicolon to keep syntax valid
392
- description: "Removing deprecated `require.extensions` check from MikroORM"
393
- },
394
- {
395
- file: "node_modules/@mikro-orm/knex/dialects/mysql/index.js",
396
- deleteLines: [/^.*MariaDbKnexDialect.*$/gim],
397
- description: "Removing MariaDbKnexDialect"
398
- }
399
- ];
400
- function runPostInstallPatch() {
401
- console.log("🔧 Applying MikroORM & Knex patches...");
402
- PATCHES.forEach(({ file, search, replace, deleteLines, deleteFile, deleteFolder, description }) => {
403
- if (file) {
404
- const filePath = path.resolve(file);
405
- if (fs.existsSync(filePath)) {
406
- let content = fs.readFileSync(filePath, "utf8");
407
- let originalContent = content;
408
- if (search && replace) {
409
- if (typeof search === "string" ? content.includes(search) : search.test(content)) {
410
- content = content.replace(search, replace);
411
- console.log(`[PATCHED] ${description}`);
412
- }
413
- }
414
- if (deleteLines) {
415
- deleteLines.forEach((pattern) => {
416
- content = content.split("\n").filter((line) => !pattern.test(line)).join("\n");
417
- });
418
- if (content !== originalContent) {
419
- console.log(`[CLEANED] Removed matching lines in ${file}`);
420
- }
421
- }
422
- if (content !== originalContent) {
423
- fs.writeFileSync(filePath, content, "utf8");
424
- }
425
- if (content.trim() === "") {
426
- fs.unlinkSync(filePath);
427
- console.log(`[REMOVED] ${filePath} (file is now empty)`);
428
- }
429
- } else {
430
- console.warn(`[WARNING] File not found: ${file}`);
431
- }
432
- }
433
- if (deleteFile) {
434
- const deleteFilePath = path.resolve(__dirname, "../", deleteFile);
435
- if (fs.existsSync(deleteFilePath)) {
436
- fs.unlinkSync(deleteFilePath);
437
- console.log(`[DELETED] ${description}`);
438
- }
439
- }
440
- if (deleteFolder) {
441
- const deleteFolderPath = path.resolve(__dirname, "../", deleteFolder);
442
- if (fs.existsSync(deleteFolderPath)) {
443
- fs.rmSync(deleteFolderPath, { recursive: true, force: true });
444
- console.log(`[DELETED] ${description}`);
445
- }
446
- }
447
- });
448
- console.log("🎉 MikroORM & Knex patching completed!");
449
- }
450
- dotenv.config();
451
- const askMissingParams = async (config, defaultOutput, customAskMissingParams) => {
452
- const questions = [];
453
- if (!config.host)
454
- questions.push({
455
- type: "input",
456
- name: "host",
457
- message: "Enter database host:",
458
- default: "localhost"
459
- });
460
- if (!config.port)
461
- questions.push({
462
- type: "input",
463
- name: "port",
464
- message: "Enter database port:",
465
- default: "3306",
466
- validate: (input) => !isNaN(parseInt(input, 10))
467
- });
468
- if (!config.user)
469
- questions.push({
470
- type: "input",
471
- name: "user",
472
- message: "Enter database user:",
473
- default: "root"
474
- });
475
- if (!config.password)
476
- questions.push({
477
- type: "password",
478
- name: "password",
479
- message: "Enter database password:",
480
- mask: "*"
481
- });
482
- if (!config.dbName)
483
- questions.push({
484
- type: "input",
485
- name: "dbName",
486
- message: "Enter database name:"
487
- });
488
- if (!config.output)
489
- questions.push({
490
- type: "input",
491
- name: "output",
492
- message: "Enter output path:",
493
- default: defaultOutput
494
- });
495
- if (customAskMissingParams) {
496
- customAskMissingParams(config, questions);
497
- }
498
- if (questions.length > 0) {
499
- const answers = await inquirer.prompt(questions);
500
- return { ...config, ...answers, port: parseInt(answers.port, 10) };
501
- }
502
- return config;
503
- };
504
- const getConfig = async (cmd, defaultOutput, customConfig, customAskMissingParams) => {
505
- let config = {
506
- host: cmd.host || process.env.FORGE_SQL_ORM_HOST,
507
- port: cmd.port ? parseInt(cmd.port, 10) : process.env.FORGE_SQL_ORM_PORT ? parseInt(process.env.FORGE_SQL_ORM_PORT, 10) : void 0,
508
- user: cmd.user || process.env.FORGE_SQL_ORM_USER,
509
- password: cmd.password || process.env.FORGE_SQL_ORM_PASSWORD,
510
- dbName: cmd.dbName || process.env.FORGE_SQL_ORM_DBNAME,
511
- output: cmd.output || process.env.FORGE_SQL_ORM_OUTPUT
512
- };
513
- if (customConfig) {
514
- config = { ...config, ...customConfig() };
515
- }
516
- return await askMissingParams(config, defaultOutput, customAskMissingParams);
517
- };
518
- const program = new Command();
519
- program.version("1.0.0");
520
- program.command("generate:model").description("Generate MikroORM models from the database.").option("--host <string>", "Database host").option("--port <number>", "Database port").option("--user <string>", "Database user").option("--password <string>", "Database password").option("--dbName <string>", "Database name").option("--output <string>", "Output path for entities").action(async (cmd) => {
521
- const config = await getConfig(cmd, "./database/entities");
522
- await generateModels(config);
523
- });
524
- program.command("migrations:create").description("Generate an initial migration for the entire database.").option("--host <string>", "Database host").option("--port <number>", "Database port").option("--user <string>", "Database user").option("--password <string>", "Database password").option("--dbName <string>", "Database name").option("--output <string>", "Output path for migrations").option("--entitiesPath <string>", "Path to the folder containing entities").action(async (cmd) => {
525
- const config = await getConfig(
526
- cmd,
527
- "./database/migration",
528
- () => ({
529
- entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIES_PATH
530
- }),
531
- (cfg, questions) => {
532
- if (!cfg.entitiesPath)
533
- questions.push({
534
- type: "input",
535
- name: "entitiesPath",
536
- message: "Enter the path to entities:",
537
- default: "./database/entities"
538
- });
539
- }
540
- );
541
- await createMigration(config);
542
- });
543
- program.command("migrations:update").description("Generate a migration to update the database schema.").option("--host <string>", "Database host").option("--port <number>", "Database port").option("--user <string>", "Database user").option("--password <string>", "Database password").option("--dbName <string>", "Database name").option("--output <string>", "Output path for migrations").option("--entitiesPath <string>", "Path to the folder containing entities").action(async (cmd) => {
544
- const config = await getConfig(
545
- cmd,
546
- "./database/migration",
547
- () => ({
548
- entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIES_PATH
549
- }),
550
- (cfg, questions) => {
551
- if (!cfg.entitiesPath)
552
- questions.push({
553
- type: "input",
554
- name: "entitiesPath",
555
- message: "Enter the path to entities:",
556
- default: "./database/entities"
557
- });
558
- }
559
- );
560
- await updateMigration(config);
561
- });
562
- program.command("patch:mikroorm").description("Patch MikroORM and Knex dependencies to work properly with Forge").action(async () => {
563
- console.log("Running MikroORM patch...");
564
- await runPostInstallPatch();
565
- await runPostInstallPatch();
566
- await runPostInstallPatch();
567
- console.log("✅ MikroORM patch applied successfully!");
568
- });
569
- program.parse(process.argv);
570
- //# sourceMappingURL=cli.mjs.map