forge-sql-orm 1.0.5 → 1.0.7

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