forge-sql-orm 1.0.29 → 1.0.31
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/README.md +71 -31
- package/dist/ForgeSQLORM.js +68 -3
- package/dist/ForgeSQLORM.js.map +1 -1
- package/dist/ForgeSQLORM.mjs +69 -4
- package/dist/ForgeSQLORM.mjs.map +1 -1
- package/dist/core/ComplexQuerySchemaBuilder.d.ts +38 -0
- package/dist/core/ComplexQuerySchemaBuilder.d.ts.map +1 -0
- package/dist/core/ForgeSQLORM.d.ts.map +1 -1
- package/dist/core/ForgeSQLQueryBuilder.d.ts +23 -1
- package/dist/core/ForgeSQLQueryBuilder.d.ts.map +1 -1
- package/dist/core/ForgeSQLSelectOperations.d.ts +9 -1
- package/dist/core/ForgeSQLSelectOperations.d.ts.map +1 -1
- package/dist/utils/sqlUtils.d.ts +1 -1
- package/dist/utils/sqlUtils.d.ts.map +1 -1
- package/dist-cli/cli.js +148 -21
- package/dist-cli/cli.js.map +1 -1
- package/dist-cli/cli.mjs +148 -21
- package/dist-cli/cli.mjs.map +1 -1
- package/dist-cli/forgeSqlOrmCLI.js +7 -12
- package/package.json +16 -15
- package/src/core/ComplexQuerySchemaBuilder.ts +63 -0
- package/src/core/ForgeSQLORM.ts +5 -2
- package/src/core/ForgeSQLQueryBuilder.ts +25 -1
- package/src/core/ForgeSQLSelectOperations.ts +22 -11
- package/src/utils/sqlUtils.ts +1 -1
package/dist-cli/cli.mjs
CHANGED
|
@@ -90,13 +90,17 @@ const generateModels = async (options) => {
|
|
|
90
90
|
process.exit(1);
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
|
-
function cleanSQLStatement$
|
|
93
|
+
function cleanSQLStatement$2(sql) {
|
|
94
|
+
sql = sql.replace(/create\s+table\s+(\w+)/gi, "create table if not exists $1");
|
|
95
|
+
sql = sql.replace(/create\s+index\s+(\w+)/gi, "create index if not exists $1");
|
|
96
|
+
sql = sql.replace(/alter\s+table\s+(\w+)\s+add\s+index\s+(\w+)/gi, "alter table $1 add index if not exists $2");
|
|
97
|
+
sql = sql.replace(/alter\s+table\s+(\w+)\s+add\s+constraint\s+(\w+)/gi, "alter table $1 add constraint if not exists $2");
|
|
94
98
|
return sql.replace(/\s+default\s+character\s+set\s+utf8mb4\s+engine\s*=\s*InnoDB;?/gi, "").trim();
|
|
95
99
|
}
|
|
96
|
-
function generateMigrationFile$
|
|
100
|
+
function generateMigrationFile$2(createStatements, version) {
|
|
97
101
|
const versionPrefix = `v${version}_MIGRATION`;
|
|
98
102
|
const migrationLines = createStatements.map(
|
|
99
|
-
(stmt, index) => ` .enqueue("${versionPrefix}${index}", "${cleanSQLStatement$
|
|
103
|
+
(stmt, index) => ` .enqueue("${versionPrefix}${index}", "${cleanSQLStatement$2(stmt)}")`
|
|
100
104
|
// eslint-disable-line no-useless-escape
|
|
101
105
|
).join("\n");
|
|
102
106
|
return `import { MigrationRunner } from "@forge/sql/out/migration";
|
|
@@ -106,7 +110,7 @@ export default (migrationRunner: MigrationRunner): MigrationRunner => {
|
|
|
106
110
|
${migrationLines};
|
|
107
111
|
};`;
|
|
108
112
|
}
|
|
109
|
-
function saveMigrationFiles$
|
|
113
|
+
function saveMigrationFiles$2(migrationCode, version, outputDir) {
|
|
110
114
|
if (!fs.existsSync(outputDir)) {
|
|
111
115
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
112
116
|
}
|
|
@@ -141,10 +145,10 @@ export default async (
|
|
|
141
145
|
const extractCreateStatements$1 = (schema) => {
|
|
142
146
|
const statements = schema.split(";").map((s) => s.trim());
|
|
143
147
|
return statements.filter(
|
|
144
|
-
(stmt) => stmt.startsWith("create table") || stmt.startsWith("alter table") && stmt.includes("add index") || stmt.startsWith("primary")
|
|
148
|
+
(stmt) => stmt.startsWith("create table") || stmt.startsWith("alter table") && (stmt.includes("add index") || stmt.includes("add constraint")) || stmt.startsWith("primary")
|
|
145
149
|
);
|
|
146
150
|
};
|
|
147
|
-
const loadEntities$
|
|
151
|
+
const loadEntities$2 = async (entitiesPath) => {
|
|
148
152
|
try {
|
|
149
153
|
const indexFilePath = path.resolve(path.join(entitiesPath, "index.ts"));
|
|
150
154
|
if (!fs.existsSync(indexFilePath)) {
|
|
@@ -177,11 +181,15 @@ const createMigration = async (options) => {
|
|
|
177
181
|
try {
|
|
178
182
|
let version = await loadMigrationVersion$1(options.output);
|
|
179
183
|
if (version > 0) {
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
if (options.force) {
|
|
185
|
+
console.warn(`⚠️ Warning: Migration already exists. Creating new migration with force flag...`);
|
|
186
|
+
} else {
|
|
187
|
+
console.error(`❌ Error: Migration has already been created. Use --force flag to override.`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
182
190
|
}
|
|
183
191
|
version = 1;
|
|
184
|
-
const entities = await loadEntities$
|
|
192
|
+
const entities = await loadEntities$2(options.entitiesPath);
|
|
185
193
|
const orm = MikroORM.initSync({
|
|
186
194
|
host: options.host,
|
|
187
195
|
port: options.port,
|
|
@@ -192,8 +200,8 @@ const createMigration = async (options) => {
|
|
|
192
200
|
});
|
|
193
201
|
const createSchemaSQL = await orm.schema.getCreateSchemaSQL({ wrap: true });
|
|
194
202
|
const statements = extractCreateStatements$1(createSchemaSQL);
|
|
195
|
-
const migrationFile = generateMigrationFile$
|
|
196
|
-
saveMigrationFiles$
|
|
203
|
+
const migrationFile = generateMigrationFile$2(statements, version);
|
|
204
|
+
saveMigrationFiles$2(migrationFile, version, options.output);
|
|
197
205
|
console.log(`✅ Migration successfully created!`);
|
|
198
206
|
process.exit(0);
|
|
199
207
|
} catch (error) {
|
|
@@ -201,13 +209,13 @@ const createMigration = async (options) => {
|
|
|
201
209
|
process.exit(1);
|
|
202
210
|
}
|
|
203
211
|
};
|
|
204
|
-
function cleanSQLStatement(sql) {
|
|
212
|
+
function cleanSQLStatement$1(sql) {
|
|
205
213
|
return sql.replace(/\s+default\s+character\s+set\s+utf8mb4\s+engine\s*=\s*InnoDB;?/gi, "").trim();
|
|
206
214
|
}
|
|
207
|
-
function generateMigrationFile(createStatements, version) {
|
|
215
|
+
function generateMigrationFile$1(createStatements, version) {
|
|
208
216
|
const versionPrefix = `v${version}_MIGRATION`;
|
|
209
217
|
const migrationLines = createStatements.map(
|
|
210
|
-
(stmt, index) => ` .enqueue("${versionPrefix}${index}", "${cleanSQLStatement(stmt)}")`
|
|
218
|
+
(stmt, index) => ` .enqueue("${versionPrefix}${index}", "${cleanSQLStatement$1(stmt)}")`
|
|
211
219
|
// eslint-disable-line no-useless-escape
|
|
212
220
|
).join("\n");
|
|
213
221
|
return `import { MigrationRunner } from "@forge/sql/out/migration";
|
|
@@ -217,7 +225,7 @@ export default (migrationRunner: MigrationRunner): MigrationRunner => {
|
|
|
217
225
|
${migrationLines};
|
|
218
226
|
};`;
|
|
219
227
|
}
|
|
220
|
-
function saveMigrationFiles(migrationCode, version, outputDir) {
|
|
228
|
+
function saveMigrationFiles$1(migrationCode, version, outputDir) {
|
|
221
229
|
if (!fs.existsSync(outputDir)) {
|
|
222
230
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
223
231
|
}
|
|
@@ -255,7 +263,7 @@ const extractCreateStatements = (schema) => {
|
|
|
255
263
|
(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")
|
|
256
264
|
);
|
|
257
265
|
};
|
|
258
|
-
const loadEntities = async (entitiesPath) => {
|
|
266
|
+
const loadEntities$1 = async (entitiesPath) => {
|
|
259
267
|
try {
|
|
260
268
|
const indexFilePath = path.resolve(path.join(entitiesPath, "index.ts"));
|
|
261
269
|
if (!fs.existsSync(indexFilePath)) {
|
|
@@ -297,7 +305,7 @@ const updateMigration = async (options) => {
|
|
|
297
305
|
process.exit(0);
|
|
298
306
|
}
|
|
299
307
|
version += 1;
|
|
300
|
-
const entities = await loadEntities(options.entitiesPath);
|
|
308
|
+
const entities = await loadEntities$1(options.entitiesPath);
|
|
301
309
|
const orm = MikroORM.initSync({
|
|
302
310
|
host: options.host,
|
|
303
311
|
port: options.port,
|
|
@@ -310,8 +318,8 @@ const updateMigration = async (options) => {
|
|
|
310
318
|
const createSchemaSQL = await orm.schema.getUpdateSchemaMigrationSQL({ wrap: true });
|
|
311
319
|
const statements = extractCreateStatements(createSchemaSQL?.down || "");
|
|
312
320
|
if (statements.length) {
|
|
313
|
-
const migrationFile = generateMigrationFile(statements, version);
|
|
314
|
-
saveMigrationFiles(migrationFile, version, options.output);
|
|
321
|
+
const migrationFile = generateMigrationFile$1(statements, version);
|
|
322
|
+
saveMigrationFiles$1(migrationFile, version, options.output);
|
|
315
323
|
console.log(`✅ Migration successfully updated!`);
|
|
316
324
|
process.exit(0);
|
|
317
325
|
} else {
|
|
@@ -517,6 +525,105 @@ function runPostInstallPatch() {
|
|
|
517
525
|
);
|
|
518
526
|
console.log("🎉 MikroORM & Knex patching completed!");
|
|
519
527
|
}
|
|
528
|
+
function generateMigrationUUID(version) {
|
|
529
|
+
const now = /* @__PURE__ */ new Date();
|
|
530
|
+
const timestamp = now.getTime();
|
|
531
|
+
return `MIGRATION_V${version}_${timestamp}`;
|
|
532
|
+
}
|
|
533
|
+
function cleanSQLStatement(sql) {
|
|
534
|
+
return sql.replace(/\s+default\s+character\s+set\s+utf8mb4\s+engine\s*=\s*InnoDB;?/gi, "").trim();
|
|
535
|
+
}
|
|
536
|
+
function generateMigrationFile(createStatements, version) {
|
|
537
|
+
const uniqId = generateMigrationUUID(version);
|
|
538
|
+
const migrationLines = createStatements.map(
|
|
539
|
+
(stmt, index) => ` .enqueue("${uniqId}_${index}", "${cleanSQLStatement(stmt)}")`
|
|
540
|
+
// eslint-disable-line no-useless-escape
|
|
541
|
+
).join("\n");
|
|
542
|
+
const clearMigrationsLine = ` .enqueue("${uniqId}", "DELETE FROM __migrations")`;
|
|
543
|
+
return `import { MigrationRunner } from "@forge/sql/out/migration";
|
|
544
|
+
|
|
545
|
+
export default (migrationRunner: MigrationRunner): MigrationRunner => {
|
|
546
|
+
return migrationRunner
|
|
547
|
+
${migrationLines}
|
|
548
|
+
${clearMigrationsLine};
|
|
549
|
+
};`;
|
|
550
|
+
}
|
|
551
|
+
function saveMigrationFiles(migrationCode, version, outputDir) {
|
|
552
|
+
if (!fs.existsSync(outputDir)) {
|
|
553
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
554
|
+
}
|
|
555
|
+
const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);
|
|
556
|
+
const migrationCountPath = path.join(outputDir, `migrationCount.ts`);
|
|
557
|
+
const indexFilePath = path.join(outputDir, `index.ts`);
|
|
558
|
+
fs.writeFileSync(migrationFilePath, migrationCode);
|
|
559
|
+
fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);
|
|
560
|
+
const indexFileContent = `import { MigrationRunner } from "@forge/sql/out/migration";
|
|
561
|
+
import { MIGRATION_VERSION } from "./migrationCount";
|
|
562
|
+
|
|
563
|
+
export type MigrationType = (
|
|
564
|
+
migrationRunner: MigrationRunner,
|
|
565
|
+
) => MigrationRunner;
|
|
566
|
+
|
|
567
|
+
export default async (
|
|
568
|
+
migrationRunner: MigrationRunner,
|
|
569
|
+
): Promise<MigrationRunner> => {
|
|
570
|
+
for (let i = 1; i <= MIGRATION_VERSION; i++) {
|
|
571
|
+
const migrations = (await import(\`./migrationV\${i}\`)) as {
|
|
572
|
+
default: MigrationType;
|
|
573
|
+
};
|
|
574
|
+
migrations.default(migrationRunner);
|
|
575
|
+
}
|
|
576
|
+
return migrationRunner;
|
|
577
|
+
};`;
|
|
578
|
+
fs.writeFileSync(indexFilePath, indexFileContent);
|
|
579
|
+
console.log(`✅ Migration file created: ${migrationFilePath}`);
|
|
580
|
+
console.log(`✅ Migration count file updated: ${migrationCountPath}`);
|
|
581
|
+
console.log(`✅ Migration index file created: ${indexFilePath}`);
|
|
582
|
+
}
|
|
583
|
+
const extractDropStatements = (schema) => {
|
|
584
|
+
const statements = schema.split(";").map((s) => s.trim());
|
|
585
|
+
return statements.filter((s) => {
|
|
586
|
+
return s.toLowerCase().startsWith("drop");
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
const loadEntities = async (entitiesPath) => {
|
|
590
|
+
try {
|
|
591
|
+
const indexFilePath = path.resolve(path.join(entitiesPath, "index.ts"));
|
|
592
|
+
if (!fs.existsSync(indexFilePath)) {
|
|
593
|
+
console.error(`❌ Error: index.ts not found in ${indexFilePath}`);
|
|
594
|
+
process.exit(1);
|
|
595
|
+
}
|
|
596
|
+
const { default: entities } = await import(indexFilePath);
|
|
597
|
+
console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);
|
|
598
|
+
return entities;
|
|
599
|
+
} catch (error) {
|
|
600
|
+
console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);
|
|
601
|
+
process.exit(1);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
const dropMigration = async (options) => {
|
|
605
|
+
try {
|
|
606
|
+
const version = 1;
|
|
607
|
+
const entities = await loadEntities(options.entitiesPath);
|
|
608
|
+
const orm = MikroORM.initSync({
|
|
609
|
+
host: options.host,
|
|
610
|
+
port: options.port,
|
|
611
|
+
user: options.user,
|
|
612
|
+
password: options.password,
|
|
613
|
+
dbName: options.dbName,
|
|
614
|
+
entities
|
|
615
|
+
});
|
|
616
|
+
const dropSchemaSQL = await orm.schema.getDropSchemaSQL({ wrap: true });
|
|
617
|
+
const statements = extractDropStatements(dropSchemaSQL);
|
|
618
|
+
const migrationFile = generateMigrationFile(statements, version);
|
|
619
|
+
saveMigrationFiles(migrationFile, version, options.output);
|
|
620
|
+
console.log(`✅ Migration successfully created!`);
|
|
621
|
+
process.exit(0);
|
|
622
|
+
} catch (error) {
|
|
623
|
+
console.error(`❌ Error during migration creation:`, error);
|
|
624
|
+
process.exit(1);
|
|
625
|
+
}
|
|
626
|
+
};
|
|
520
627
|
const ENV_PATH = path.resolve(process.cwd(), ".env");
|
|
521
628
|
dotenv.config({ path: ENV_PATH });
|
|
522
629
|
const saveEnvFile = (config) => {
|
|
@@ -630,12 +737,13 @@ program.command("generate:model").description("Generate MikroORM models from the
|
|
|
630
737
|
);
|
|
631
738
|
await generateModels(config);
|
|
632
739
|
});
|
|
633
|
-
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").option("--saveEnv", "Save configuration to .env file").action(async (cmd) => {
|
|
740
|
+
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").option("--force", "Force creation even if migrations exist").option("--saveEnv", "Save configuration to .env file").action(async (cmd) => {
|
|
634
741
|
const config = await getConfig(
|
|
635
742
|
cmd,
|
|
636
743
|
"./database/migration",
|
|
637
744
|
() => ({
|
|
638
|
-
entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH
|
|
745
|
+
entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH,
|
|
746
|
+
force: cmd.force || false
|
|
639
747
|
}),
|
|
640
748
|
(cfg, questions) => {
|
|
641
749
|
if (!cfg.entitiesPath)
|
|
@@ -668,6 +776,25 @@ program.command("migrations:update").description("Generate a migration to update
|
|
|
668
776
|
);
|
|
669
777
|
await updateMigration(config);
|
|
670
778
|
});
|
|
779
|
+
program.command("migrations:drop").description("Generate a migration to drop all tables and clear migrations history.").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").option("--saveEnv", "Save configuration to .env file").action(async (cmd) => {
|
|
780
|
+
const config = await getConfig(
|
|
781
|
+
cmd,
|
|
782
|
+
"./database/migration",
|
|
783
|
+
() => ({
|
|
784
|
+
entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH
|
|
785
|
+
}),
|
|
786
|
+
(cfg, questions) => {
|
|
787
|
+
if (!cfg.entitiesPath)
|
|
788
|
+
questions.push({
|
|
789
|
+
type: "input",
|
|
790
|
+
name: "entitiesPath",
|
|
791
|
+
message: "Enter the path to entities:",
|
|
792
|
+
default: "./database/entities"
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
);
|
|
796
|
+
await dropMigration(config);
|
|
797
|
+
});
|
|
671
798
|
program.command("patch:mikroorm").description("Patch MikroORM and Knex dependencies to work properly with Forge").action(async () => {
|
|
672
799
|
console.log("Running MikroORM patch...");
|
|
673
800
|
await runPostInstallPatch();
|
package/dist-cli/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","sources":["../scripts/actions/generate-models.ts","../scripts/actions/migrations-create.ts","../scripts/actions/migrations-update.ts","../scripts/actions/PatchPostinstall.ts","../scripts/cli.ts"],"sourcesContent":["import \"reflect-metadata\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { defineConfig, MikroORM, MongoNamingStrategy } from \"@mikro-orm/mysql\";\nimport { EntityGenerator } from \"@mikro-orm/entity-generator\";\nimport { EntityMetadata } from \"@mikro-orm/core/typings\";\n\nconst regenerateIndexFile = (outputPath: string) => {\n const entitiesDir = path.resolve(outputPath);\n const indexPath = path.join(entitiesDir, \"index.ts\");\n\n const entityFiles = fs\n .readdirSync(entitiesDir)\n .filter((file) => file.endsWith(\".ts\") && file !== \"index.ts\");\n\n const imports = entityFiles.map((file) => {\n const entityName = path.basename(file, \".ts\");\n return `import { ${entityName} } from \"./${entityName}\";`;\n });\n\n const indexContent = `${imports.join(\"\\n\")}\\n\\nexport default [${entityFiles.map((file) => path.basename(file, \".ts\")).join(\", \")}];\\n`;\n\n fs.writeFileSync(indexPath, indexContent, \"utf8\");\n console.log(`✅ Updated index.ts with ${entityFiles.length} entities.`);\n};\n\nexport const generateModels = async (options: any) => {\n try {\n const ormConfig = defineConfig({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n namingStrategy: MongoNamingStrategy,\n discovery: { warnWhenNoEntities: false },\n extensions: [EntityGenerator],\n debug: true,\n }) as Parameters<typeof MikroORM.initSync>[0];\n\n const orm = MikroORM.initSync(ormConfig);\n console.log(`✅ Connected to ${options.dbName} at ${options.host}:${options.port}`);\n\n const onCreatingVersionField = async (metadatas: EntityMetadata[]) => {\n metadatas.forEach((m) => {\n if (options.versionField) {\n const versionFieldName = Object.keys(m.properties).find((p) => {\n return (\n p === options.versionField ||\n m.properties[p]?.name === options.versionField ||\n m.properties[p]?.fieldNames?.find((f) => f === options.versionField)\n );\n });\n if (versionFieldName) {\n const property = m.properties[versionFieldName];\n if (\n property.type !== \"datetime\" &&\n property.type !== \"integer\" &&\n property.type !== \"decimal\"\n ) {\n console.warn(\n `Version field \"${property.name}\" can be only datetime or integer Table ${m.tableName} but now is \"${property.type}\"`,\n );\n return;\n }\n if (property.primary) {\n console.warn(\n `Version field \"${property.name}\" can not be primary key Table ${m.tableName}`,\n );\n return;\n }\n if (property.nullable) {\n console.warn(\n `Version field \"${property.name}\" should not be nullable Table ${m.tableName}`,\n );\n return;\n }\n property.version = true;\n }\n }\n });\n };\n await orm.entityGenerator.generate({\n entitySchema: true,\n bidirectionalRelations: true,\n identifiedReferences: false,\n forceUndefined: true,\n undefinedDefaults: true,\n useCoreBaseEntity: false,\n onlyPurePivotTables: false,\n outputPurePivotTables: false,\n scalarPropertiesForRelations: \"always\",\n save: true,\n path: options.output,\n onInitialMetadata: onCreatingVersionField,\n });\n\n regenerateIndexFile(options.output);\n\n console.log(`✅ Entities generated at: ${options.output}`);\n process.exit(0);\n } catch (error) {\n console.error(`❌ Error generating entities:`, error);\n process.exit(1);\n }\n};\n","import \"reflect-metadata\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { MikroORM } from \"@mikro-orm/mysql\";\nimport { execSync } from \"child_process\";\nimport { rmSync } from \"fs\";\n\n/**\n * Cleans SQL statements by removing unnecessary database options.\n * @param sql - The raw SQL statement.\n * @returns The cleaned SQL statement.\n */\nfunction cleanSQLStatement(sql: string): string {\n return sql.replace(/\\s+default\\s+character\\s+set\\s+utf8mb4\\s+engine\\s*=\\s*InnoDB;?/gi, \"\").trim();\n}\n\n/**\n * Generates a migration file using the provided SQL statements.\n * @param createStatements - Array of SQL statements.\n * @param version - Migration version number.\n * @returns TypeScript migration file content.\n */\nfunction generateMigrationFile(createStatements: string[], version: number): string {\n const versionPrefix = `v${version}_MIGRATION`;\n\n // Clean each SQL statement and generate migration lines with .enqueue()\n const migrationLines = createStatements\n .map(\n (stmt, index) =>\n ` .enqueue(\"${versionPrefix}${index}\", \\\"${cleanSQLStatement(stmt)}\\\")`, // eslint-disable-line no-useless-escape\n )\n .join(\"\\n\");\n\n // Migration template\n return `import { MigrationRunner } from \"@forge/sql/out/migration\";\n\nexport default (migrationRunner: MigrationRunner): MigrationRunner => {\n return migrationRunner\n${migrationLines};\n};`;\n}\n\n/**\n * Saves the generated migration file along with `migrationCount.ts` and `index.ts`.\n * @param migrationCode - The migration code to be written to the file.\n * @param version - Migration version number.\n * @param outputDir - Directory where the migration files will be saved.\n */\nfunction saveMigrationFiles(migrationCode: string, version: number, outputDir: string) {\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);\n const migrationCountPath = path.join(outputDir, `migrationCount.ts`);\n const indexFilePath = path.join(outputDir, `index.ts`);\n\n // Write the migration file\n fs.writeFileSync(migrationFilePath, migrationCode);\n\n // Write the migration count file\n fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);\n\n // Generate the migration index file\n const indexFileContent = `import { MigrationRunner } from \"@forge/sql/out/migration\";\nimport { MIGRATION_VERSION } from \"./migrationCount\";\n\nexport type MigrationType = (\n migrationRunner: MigrationRunner,\n) => MigrationRunner;\n\nexport default async (\n migrationRunner: MigrationRunner,\n): Promise<MigrationRunner> => {\n for (let i = 1; i <= MIGRATION_VERSION; i++) {\n const migrations = (await import(\\`./migrationV\\${i}\\`)) as {\n default: MigrationType;\n };\n migrations.default(migrationRunner);\n }\n return migrationRunner;\n};`;\n\n fs.writeFileSync(indexFilePath, indexFileContent);\n\n console.log(`✅ Migration file created: ${migrationFilePath}`);\n console.log(`✅ Migration count file updated: ${migrationCountPath}`);\n console.log(`✅ Migration index file created: ${indexFilePath}`);\n}\n\n/**\n * Extracts only the relevant SQL statements for migration.\n * @param schema - The full database schema as SQL.\n * @returns Filtered list of SQL statements.\n */\nconst extractCreateStatements = (schema: string): string[] => {\n const statements = schema.split(\";\").map((s) => s.trim());\n\n return statements.filter(\n (stmt) =>\n stmt.startsWith(\"create table\") ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"add index\")) ||\n stmt.startsWith(\"primary\"),\n );\n};\n\n/**\n * Dynamically loads `entities` from `index.ts` in the specified directory.\n * @param entitiesPath - Path to the directory containing `index.ts`.\n * @returns Array of entity classes.\n */\nconst loadEntities = async (entitiesPath: string) => {\n try {\n const indexFilePath = path.resolve(path.join(entitiesPath, \"index.ts\"));\n if (!fs.existsSync(indexFilePath)) {\n console.error(`❌ Error: index.ts not found in ${indexFilePath}`);\n process.exit(1);\n }\n\n const { default: entities } = await import(indexFilePath);\n console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);\n return entities;\n } catch (error) {\n console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Loads the current migration version from `migrationCount.ts`.\n * @param migrationPath - Path to the migration folder.\n * @returns The latest migration version.\n */\nconst loadMigrationVersion = async (migrationPath: string): Promise<number> => {\n try {\n const migrationCountFilePath = path.resolve(path.join(migrationPath, \"migrationCount.ts\"));\n if (!fs.existsSync(migrationCountFilePath)) {\n return 0;\n }\n\n const { MIGRATION_VERSION } = await import(migrationCountFilePath);\n console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);\n return MIGRATION_VERSION as number;\n } catch (error) {\n console.error(`❌ Error loading migrationCount:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Creates a full database migration.\n * @param options - Database connection settings and output paths.\n */\nexport const createMigration = async (options: any) => {\n try {\n let version = await loadMigrationVersion(options.output);\n\n if (version > 0) {\n console.error(`❌ Error: Migration has already been created.`);\n process.exit(1);\n }\n\n // Start from version 1 if no previous migrations exist\n version = 1;\n\n // Load entities dynamically from index.ts\n const entities = await loadEntities(options.entitiesPath);\n\n // Initialize MikroORM\n const orm = MikroORM.initSync({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n entities: entities,\n });\n\n // Generate SQL schema\n const createSchemaSQL = await orm.schema.getCreateSchemaSQL({ wrap: true });\n const statements = extractCreateStatements(createSchemaSQL);\n\n // Generate and save migration files\n const migrationFile = generateMigrationFile(statements, version);\n saveMigrationFiles(migrationFile, version, options.output);\n\n console.log(`✅ Migration successfully created!`);\n process.exit(0);\n } catch (error) {\n console.error(`❌ Error during migration creation:`, error);\n process.exit(1);\n }\n};\n","import \"reflect-metadata\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { MikroORM } from \"@mikro-orm/mysql\";\n\n/**\n * Cleans SQL statements by removing unnecessary database options.\n * @param sql - The raw SQL statement.\n * @returns The cleaned SQL statement.\n */\nfunction cleanSQLStatement(sql: string): string {\n return sql.replace(/\\s+default\\s+character\\s+set\\s+utf8mb4\\s+engine\\s*=\\s*InnoDB;?/gi, \"\").trim();\n}\n\n/**\n * Generates a migration file using the provided SQL statements.\n * @param createStatements - Array of SQL statements.\n * @param version - Migration version number.\n * @returns TypeScript migration file content.\n */\nfunction generateMigrationFile(createStatements: string[], version: number): string {\n const versionPrefix = `v${version}_MIGRATION`;\n\n // Clean each SQL statement and generate migration lines with .enqueue()\n const migrationLines = createStatements\n .map(\n (stmt, index) =>\n ` .enqueue(\"${versionPrefix}${index}\", \\\"${cleanSQLStatement(stmt)}\\\")`, // eslint-disable-line no-useless-escape\n )\n .join(\"\\n\");\n\n // Migration template\n return `import { MigrationRunner } from \"@forge/sql/out/migration\";\n\nexport default (migrationRunner: MigrationRunner): MigrationRunner => {\n return migrationRunner\n${migrationLines};\n};`;\n}\n\n/**\n * Saves the generated migration file along with `migrationCount.ts` and `index.ts`.\n * @param migrationCode - The migration code to be written to the file.\n * @param version - Migration version number.\n * @param outputDir - Directory where the migration files will be saved.\n */\nfunction saveMigrationFiles(migrationCode: string, version: number, outputDir: string) {\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);\n const migrationCountPath = path.join(outputDir, `migrationCount.ts`);\n const indexFilePath = path.join(outputDir, `index.ts`);\n\n // Write the migration file\n fs.writeFileSync(migrationFilePath, migrationCode);\n\n // Write the migration count file\n fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);\n\n // Generate the migration index file\n const indexFileContent = `import { MigrationRunner } from \"@forge/sql/out/migration\";\nimport { MIGRATION_VERSION } from \"./migrationCount\";\n\nexport type MigrationType = (\n migrationRunner: MigrationRunner,\n) => MigrationRunner;\n\nexport default async (\n migrationRunner: MigrationRunner,\n): Promise<MigrationRunner> => {\n for (let i = 1; i <= MIGRATION_VERSION; i++) {\n const migrations = (await import(\\`./migrationV\\${i}\\`)) as {\n default: MigrationType;\n };\n migrations.default(migrationRunner);\n }\n return migrationRunner;\n};`;\n\n fs.writeFileSync(indexFilePath, indexFileContent);\n\n console.log(`✅ Migration file created: ${migrationFilePath}`);\n console.log(`✅ Migration count file updated: ${migrationCountPath}`);\n console.log(`✅ Migration index file created: ${indexFilePath}`);\n}\n\n/**\n * Extracts only the relevant SQL statements for migration.\n * @param schema - The full database schema as SQL.\n * @returns Filtered list of SQL statements.\n */\nconst extractCreateStatements = (schema: string): string[] => {\n const statements = schema.split(\";\").map((s) => s.trim());\n\n return statements.filter(\n (stmt) =>\n stmt.startsWith(\"create table\") ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"add index\")) ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"add\") && !stmt.includes(\"foreign\")) ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"modify\") && !stmt.includes(\"foreign\")),\n );\n};\n\n/**\n * Dynamically loads `entities` from `index.ts` in the specified directory.\n * @param entitiesPath - Path to the directory containing `index.ts`.\n * @returns Array of entity classes.\n */\nconst loadEntities = async (entitiesPath: string) => {\n try {\n const indexFilePath = path.resolve(path.join(entitiesPath, \"index.ts\"));\n if (!fs.existsSync(indexFilePath)) {\n console.error(`❌ Error: index.ts not found in ${entitiesPath}`);\n process.exit(1);\n }\n\n const { default: entities } = await import(indexFilePath);\n console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);\n return entities;\n } catch (error) {\n console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Loads the current migration version from `migrationCount.ts`.\n * @param migrationPath - Path to the migration folder.\n * @returns The latest migration version.\n */\nconst loadMigrationVersion = async (migrationPath: string): Promise<number> => {\n try {\n const migrationCountFilePath = path.resolve(path.join(migrationPath, \"migrationCount.ts\"));\n if (!fs.existsSync(migrationCountFilePath)) {\n console.warn(\n `⚠️ Warning: migrationCount.ts not found in ${migrationCountFilePath}, assuming no previous migrations.`,\n );\n return 0;\n }\n\n const { MIGRATION_VERSION } = await import(migrationCountFilePath);\n console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);\n return MIGRATION_VERSION as number;\n } catch (error) {\n console.error(`❌ Error loading migrationCount:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Updates an existing database migration by generating schema modifications.\n * @param options - Database connection settings and output paths.\n */\nexport const updateMigration = async (options: any) => {\n try {\n let version = await loadMigrationVersion(options.output);\n\n if (version < 1) {\n console.log(\n `⚠️ Initial migration not found. Run \"npx forge-sql-orm migrations:create\" first.`,\n );\n process.exit(0);\n }\n version += 1;\n\n // Load entities dynamically from index.ts\n const entities = await loadEntities(options.entitiesPath);\n\n // Initialize MikroORM\n const orm = MikroORM.initSync({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n entities,\n debug: true,\n });\n\n // Generate SQL schema updates\n const createSchemaSQL = await orm.schema.getUpdateSchemaMigrationSQL({ wrap: true });\n const statements = extractCreateStatements(createSchemaSQL?.down || \"\");\n\n if (statements.length) {\n const migrationFile = generateMigrationFile(statements, version);\n saveMigrationFiles(migrationFile, version, options.output);\n\n console.log(`✅ Migration successfully updated!`);\n process.exit(0);\n } else {\n console.log(`⚠️ No new migration changes detected.`);\n process.exit(0);\n }\n } catch (error) {\n console.error(`❌ Error during migration update:`, error);\n process.exit(1);\n }\n};\n","import fs from \"fs\";\nimport path from \"path\";\n\n/**\n * Automates patches for MikroORM and Knex to fix Webpack issues.\n * - Removes problematic `require()` calls.\n * - Deletes unnecessary files and folders.\n * - Fixes dynamic imports (`import(id)`) in MikroORM.\n */\n\ninterface Patch {\n file?: string; // File to modify (optional)\n search?: RegExp; // Regex pattern to find problematic code\n replace?: string; // Replacement string for problematic code\n deleteLines?: RegExp[]; // List of regex patterns to remove specific lines\n description: string; // Description of the patch\n deleteFile?: string; // Path of the file to delete (optional)\n deleteFolder?: string; // Path of the folder to delete (optional)\n}\n\nconst PATCHES: Patch[] = [\n // 🗑️ Remove unused dialects (mssql, postgres, sqlite) in MikroORM\n {\n file: \"node_modules/@mikro-orm/knex/MonkeyPatchable.d.ts\",\n deleteLines: [\n /^.*mssql.*$/gim,\n /^.*MsSql.*$/gim,\n /^\\s*Postgres.*$/gm,\n /^.*Sqlite3.*$/gm,\n /^.*BetterSqlite3.*$/gim,\n ],\n description: \"Removing unused dialects from MonkeyPatchable.d.ts\",\n },\n {\n file: \"node_modules/@mikro-orm/knex/MonkeyPatchable.js\",\n deleteLines: [\n /^.*mssql.*$/gim,\n /^.*MsSql.*$/gim,\n /^.*postgres.*$/gim,\n /^.*sqlite.*$/gim,\n /^.*Sqlite.*$/gim,\n ],\n description: \"Removing unused dialects from MonkeyPatchable.js\",\n },\n {\n file: \"node_modules/@mikro-orm/knex/dialects/index.js\",\n deleteLines: [/^.*mssql.*$/gim, /^.*MsSql.*$/gim, /^.*postgresql.*$/gim, /^.*sqlite.*$/gim],\n description: \"Removing unused dialects from @mikro-orm/knex/dialects/index.js\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/dialects/mssql\",\n description: \"Removing mssql dialect from MikroORM\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/dialects/postgresql\",\n description: \"Removing postgresql dialect from MikroORM\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/dialects/sqlite\",\n description: \"Removing sqlite dialect from MikroORM\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/mysql/node_modules\",\n description: \"Removing node_modules from @mikro-orm/mysql\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/node_modules\",\n description: \"Removing node_modules from @mikro-orm/knex\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/core/node_modules\",\n description: \"Removing sqlite dialect from MikroORM\",\n },\n\n // 🔄 Fix Webpack `Critical dependency: the request of a dependency is an expression`\n {\n file: \"node_modules/@mikro-orm/core/utils/Configuration.js\",\n search: /dynamicImportProvider:\\s*\\/\\* istanbul ignore next \\*\\/\\s*\\(id\\) => import\\(id\\),/g,\n replace: \"dynamicImportProvider: /* istanbul ignore next */ () => Promise.resolve({}),\",\n description: \"Fixing dynamic imports in MikroORM Configuration\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /static dynamicImportProvider = \\(id\\) => import\\(id\\);/g,\n replace: \"static dynamicImportProvider = () => Promise.resolve({});\",\n description: \"Fixing dynamic imports in MikroORM Utils.js\",\n },\n\n // 🛑 Remove deprecated `require.extensions` usage\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /\\s\\|\\|\\s*\\(require\\.extensions\\s*&&\\s*!!require\\.extensions\\['\\.ts'\\]\\);\\s*/g,\n replace: \";\",\n description: \"Removing deprecated `require.extensions` check in MikroORM\",\n },\n\n // 🛠️ Patch Knex to remove `Migrator` and `Seeder`\n {\n file: \"node_modules/knex/lib/knex-builder/make-knex.js\",\n deleteLines: [\n /^const \\{ Migrator \\} = require\\('\\.\\.\\/migrations\\/migrate\\/Migrator'\\);$/gm,\n /^const Seeder = require\\('\\.\\.\\/migrations\\/seed\\/Seeder'\\);$/gm,\n ],\n description: \"Removing `Migrator` and `Seeder` requires from make-knex.js\",\n },\n {\n file: \"node_modules/knex/lib/knex-builder/make-knex.js\",\n search: /\\sreturn new Migrator\\(this\\);/g,\n replace: \"return null;\",\n description: \"Replacing `return new Migrator(this);` with `return null;`\",\n },\n {\n file: \"node_modules/knex/lib/knex-builder/make-knex.js\",\n search: /\\sreturn new Seeder\\(this\\);/g,\n replace: \"return null;\",\n description: \"Replacing `return new Seeder(this);` with `return null;`\",\n },\n {\n file: \"node_modules/knex/lib/dialects/index.js\",\n deleteLines: [\n /^.*mssql.*$/gim,\n /^.*MsSql.*$/gim,\n /^.*postgresql.*$/gim,\n /^.*sqlite.*$/gim,\n /^.*oracle.*$/gim,\n /^.*oracledb.*$/gim,\n /^.*pgnative.*$/gim,\n /^.*postgres.*$/gim,\n /^.*redshift.*$/gim,\n /^.*sqlite3.*$/gim,\n /^.*cockroachdb.*$/gim,\n ],\n description: \"Removing unused dialects from @mikro-orm/knex/dialects/index.js\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /\\s\\|\\|\\s*\\(require\\.extensions\\s*&&\\s*!!require\\.extensions\\['\\.ts'\\]\\);\\s*/g,\n replace: \";\", // Replaces with semicolon to keep syntax valid\n description: \"Removing deprecated `require.extensions` check from MikroORM\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /^.*extensions.*$/gim,\n replace: \"{\", // Replaces with semicolon to keep syntax valid\n description: \"Removing deprecated `require.extensions` check from MikroORM\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /^.*package.json.*$/gim,\n replace: \"return 0;\", // Replaces with semicolon to keep syntax valid\n description: \"Removing deprecated `require.extensions` check from MikroORM\",\n },\n {\n file: \"node_modules/@mikro-orm/knex/dialects/mysql/index.js\",\n deleteLines: [/^.*MariaDbKnexDialect.*$/gim],\n description: \"Removing MariaDbKnexDialect\",\n },\n];\n\n/**\n * Runs the MikroORM & Knex patching logic.\n */\nexport function runPostInstallPatch() {\n console.log(\"🔧 Applying MikroORM & Knex patches...\");\n PATCHES.forEach(\n ({ file, search, replace, deleteLines, deleteFile, deleteFolder, description }) => {\n if (file) {\n const filePath = path.resolve(file);\n if (fs.existsSync(filePath)) {\n let content = fs.readFileSync(filePath, \"utf8\");\n let originalContent = content;\n\n // 🔄 Replace text\n if (search && replace) {\n if (typeof search === \"string\" ? content.includes(search) : search.test(content)) {\n content = content.replace(search, replace);\n console.log(`[PATCHED] ${description}`);\n }\n }\n\n // 🗑️ Remove matching lines\n if (deleteLines) {\n deleteLines.forEach((pattern) => {\n content = content\n .split(\"\\n\")\n .filter((line) => !pattern.test(line))\n .join(\"\\n\");\n });\n if (content !== originalContent) {\n console.log(`[CLEANED] Removed matching lines in ${file}`);\n }\n }\n\n // 💾 Save changes only if file was modified\n if (content !== originalContent) {\n fs.writeFileSync(filePath, content, \"utf8\");\n }\n\n // 🚮 Remove empty files\n if (content.trim() === \"\") {\n fs.unlinkSync(filePath);\n console.log(`[REMOVED] ${filePath} (file is now empty)`);\n }\n } else {\n console.warn(`[WARNING] File not found: ${file}`);\n }\n }\n\n // 🚮 Delete specific files\n if (deleteFile) {\n const deleteFilePath = path.resolve(deleteFile);\n if (fs.existsSync(deleteFilePath)) {\n fs.unlinkSync(deleteFilePath);\n console.log(`[DELETED] ${deleteFilePath} ${description}`);\n } else {\n console.log(`[SKIPPED] ${deleteFilePath} ${description}`);\n }\n }\n\n // 🚮 Delete entire folders\n if (deleteFolder) {\n const deleteFolderPath = path.resolve(deleteFolder);\n if (fs.existsSync(deleteFolderPath)) {\n fs.rmSync(deleteFolderPath, { recursive: true, force: true });\n console.log(`[DELETED] ${deleteFolderPath} ${description}`);\n } else {\n console.log(`[SKIPPED] ${deleteFolderPath} ${description}`);\n }\n }\n },\n );\n\n console.log(\"🎉 MikroORM & Knex patching completed!\");\n}\n","#!/usr/bin/env node\n\nimport { Command } from \"commander\";\nimport dotenv from \"dotenv\";\nimport inquirer from \"inquirer\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { generateModels } from \"./actions/generate-models\";\nimport { createMigration } from \"./actions/migrations-create\";\nimport { updateMigration } from \"./actions/migrations-update\";\nimport { runPostInstallPatch } from \"./actions/PatchPostinstall\";\n\nconst ENV_PATH = path.resolve(process.cwd(), \".env\");\n// 🔄 Load environment variables from `.env` file\ndotenv.config({ path: ENV_PATH });\n\nconst saveEnvFile = (config: any) => {\n let envContent = \"\";\n const envFilePath = ENV_PATH;\n\n if (fs.existsSync(envFilePath)) {\n envContent = fs.readFileSync(envFilePath, \"utf8\");\n }\n\n const envVars = envContent\n .split(\"\\n\")\n .filter((line) => line.trim() !== \"\" && !line.startsWith(\"#\"))\n .reduce((acc: any, line) => {\n const [key, ...value] = line.split(\"=\");\n acc[key] = value.join(\"=\");\n return acc;\n }, {});\n\n Object.entries(config).forEach(([key, value]) => {\n envVars[`FORGE_SQL_ORM_${key.toUpperCase()}`] = value;\n });\n\n const updatedEnvContent = Object.entries(envVars)\n .map(([key, value]) => `${key}=${value}`)\n .join(\"\\n\");\n\n fs.writeFileSync(envFilePath, updatedEnvContent, { encoding: \"utf8\" });\n\n console.log(\"✅ Configuration saved to .env without overwriting other variables.\");\n};\n\n/**\n * Prompts the user for missing parameters using Inquirer.js.\n * @param config - The current configuration object.\n * @param defaultOutput - Default output path.\n * @param customAskMissingParams - Optional function for additional prompts.\n * @returns Updated configuration with user input.\n */\nconst askMissingParams = async (\n config: any,\n defaultOutput: string,\n customAskMissingParams?: (cfg: any, questions: unknown[]) => void,\n) => {\n const questions: unknown[] = [];\n\n if (!config.host)\n questions.push({\n type: \"input\",\n name: \"host\",\n message: \"Enter database host:\",\n default: \"localhost\",\n });\n\n if (!config.port)\n questions.push({\n type: \"input\",\n name: \"port\",\n message: \"Enter database port:\",\n default: \"3306\",\n validate: (input: string) => !isNaN(parseInt(input, 10)),\n });\n\n if (!config.user)\n questions.push({\n type: \"input\",\n name: \"user\",\n message: \"Enter database user:\",\n default: \"root\",\n });\n\n if (!config.password)\n questions.push({\n type: \"password\",\n name: \"password\",\n message: \"Enter database password:\",\n mask: \"*\",\n });\n\n if (!config.dbName)\n questions.push({\n type: \"input\",\n name: \"dbName\",\n message: \"Enter database name:\",\n });\n\n if (!config.output)\n questions.push({\n type: \"input\",\n name: \"output\",\n message: \"Enter output path:\",\n default: defaultOutput,\n });\n\n // Allow additional questions from the caller\n if (customAskMissingParams) {\n customAskMissingParams(config, questions);\n }\n\n // If there are missing parameters, prompt the user\n if (questions.length > 0) {\n // @ts-ignore - Ignore TypeScript warning for dynamic question type\n const answers = await inquirer.prompt(questions);\n return { ...config, ...answers, port: parseInt(config.port ?? answers.port, 10) };\n }\n\n return config;\n};\n\n/**\n * Retrieves configuration parameters from command-line arguments and environment variables.\n * If any required parameters are missing, prompts the user for input.\n * @param cmd - The command object containing CLI options.\n * @param defaultOutput - Default output directory.\n * @param customConfig - Optional function for additional configuration parameters.\n * @param customAskMissingParams - Optional function for additional prompts.\n * @returns A fully resolved configuration object.\n */\nconst getConfig = async (\n cmd: any,\n defaultOutput: string,\n customConfig?: () => any,\n customAskMissingParams?: (cfg: any, questions: unknown[]) => void,\n) => {\n let config = {\n host: cmd.host || process.env.FORGE_SQL_ORM_HOST,\n port: cmd.port\n ? parseInt(cmd.port, 10)\n : process.env.FORGE_SQL_ORM_PORT\n ? parseInt(process.env.FORGE_SQL_ORM_PORT, 10)\n : undefined,\n user: cmd.user || process.env.FORGE_SQL_ORM_USER,\n password: cmd.password || process.env.FORGE_SQL_ORM_PASSWORD,\n dbName: cmd.dbName || process.env.FORGE_SQL_ORM_DBNAME,\n output: cmd.output || process.env.FORGE_SQL_ORM_OUTPUT,\n };\n\n // Merge additional configurations if provided\n if (customConfig) {\n config = { ...config, ...customConfig() };\n }\n\n const conf = await askMissingParams(config, defaultOutput, customAskMissingParams);\n if (cmd.saveEnv) {\n saveEnvFile(conf);\n }\n return conf;\n};\n\n// 📌 Initialize CLI\nconst program = new Command();\nprogram.version(\"1.0.0\");\n\n// ✅ Command: Generate database models (Entities)\nprogram\n .command(\"generate:model\")\n .description(\"Generate MikroORM models from the database.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for entities\")\n .option(\"--versionField <string>\", \"Field name for versioning\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/entities\",\n () => ({\n versionField: cmd.versionField || process.env.FORGE_SQL_ORM_VERSIONFIELD,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.versionField) {\n questions.push({\n type: \"input\",\n name: \"versionField\",\n message: \"Enter the field name for versioning (leave empty to skip):\",\n default: \"\",\n });\n }\n },\n );\n await generateModels(config);\n });\n\n// ✅ Command: Create initial database migration\nprogram\n .command(\"migrations:create\")\n .description(\"Generate an initial migration for the entire database.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for migrations\")\n .option(\"--entitiesPath <string>\", \"Path to the folder containing entities\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/migration\",\n () => ({\n entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.entitiesPath)\n questions.push({\n type: \"input\",\n name: \"entitiesPath\",\n message: \"Enter the path to entities:\",\n default: \"./database/entities\",\n });\n },\n );\n await createMigration(config);\n });\n\n// ✅ Command: Update migration for schema changes\nprogram\n .command(\"migrations:update\")\n .description(\"Generate a migration to update the database schema.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for migrations\")\n .option(\"--entitiesPath <string>\", \"Path to the folder containing entities\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/migration\",\n () => ({\n entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.entitiesPath)\n questions.push({\n type: \"input\",\n name: \"entitiesPath\",\n message: \"Enter the path to entities:\",\n default: \"./database/entities\",\n });\n },\n );\n await updateMigration(config);\n });\n\n// Patch MikroORM and Knex\nprogram\n .command(\"patch:mikroorm\")\n .description(\"Patch MikroORM and Knex dependencies to work properly with Forge\")\n .action(async () => {\n console.log(\"Running MikroORM patch...\");\n await runPostInstallPatch();\n await runPostInstallPatch();\n await runPostInstallPatch();\n console.log(\"✅ MikroORM patch applied successfully!\");\n });\n\n// 🔥 Execute CLI\nprogram.parse(process.argv);\n"],"names":["cleanS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gB,MAAM;AAC9B,CAAC;AAGH,QACG,QAAQ,mBAAmB,EAC3B,YAAY,qDAAqD,EACjE,OAAO,mBAAmB,eAAe,EACzC,OAAO,mBAAmB,eAAe,EACzC,OAAO,mBAAmB,eAAe,EACzC,OAAO,uBAAuB,mBAAmB,EACjD,OAAO,qBAAqB,eAAe,EAC3C,OAAO,qBAAqB,4BAA4B,EACxD,OAAO,2BAA2B,wCAAwC,EAC1E,OAAO,aAAa,iCAAiC,EACrD,OAAO,OAAO,QAAQ;AACrB,QAAM,SAAS,MAAM;AAAA,IACnB;AAAA,IACA;AAAA,IACA,OAAO;AAAA,MACL,cAAc,IAAI,gBAAgB,QAAQ,IAAI;AAAA,IAAA;AAAA,IAEhD,CAAC,KAAK,cAAyB;AAC7B,UAAI,CAAC,IAAI;AACP,kBAAU,KAAK;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS;AAAA,QAAA,CACV;AAAA,IAAA;AAAA,EAEP;AACA,QAAM,gBAAgB,MAAM;AAC9B,CAAC;AAGH,QACG,QAAQ,gBAAgB,EACxB,YAAY,kEAAkE,EAC9E,OAAO,YAAY;AAClB,UAAQ,IAAI,2BAA2B;AACvC,QAAM,oBAAoB;AAC1B,QAAM,oBAAoB;AAC1B,QAAM,oBAAoB;AAC1B,UAAQ,IAAI,wCAAwC;AACtD,CAAC;AAGH,QAAQ,MAAM,QAAQ,IAAI;"}
|
|
1
|
+
{"version":3,"file":"cli.mjs","sources":["../scripts/actions/generate-models.ts","../scripts/actions/migrations-create.ts","../scripts/actions/migrations-update.ts","../scripts/actions/PatchPostinstall.ts","../scripts/actions/migrations-drops.ts","../scripts/cli.ts"],"sourcesContent":["import \"reflect-metadata\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { defineConfig, MikroORM, MongoNamingStrategy } from \"@mikro-orm/mysql\";\nimport { EntityGenerator } from \"@mikro-orm/entity-generator\";\nimport { EntityMetadata } from \"@mikro-orm/core/typings\";\n\nconst regenerateIndexFile = (outputPath: string) => {\n const entitiesDir = path.resolve(outputPath);\n const indexPath = path.join(entitiesDir, \"index.ts\");\n\n const entityFiles = fs\n .readdirSync(entitiesDir)\n .filter((file) => file.endsWith(\".ts\") && file !== \"index.ts\");\n\n const imports = entityFiles.map((file) => {\n const entityName = path.basename(file, \".ts\");\n return `import { ${entityName} } from \"./${entityName}\";`;\n });\n\n const indexContent = `${imports.join(\"\\n\")}\\n\\nexport default [${entityFiles.map((file) => path.basename(file, \".ts\")).join(\", \")}];\\n`;\n\n fs.writeFileSync(indexPath, indexContent, \"utf8\");\n console.log(`✅ Updated index.ts with ${entityFiles.length} entities.`);\n};\n\nexport const generateModels = async (options: any) => {\n try {\n const ormConfig = defineConfig({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n namingStrategy: MongoNamingStrategy,\n discovery: { warnWhenNoEntities: false },\n extensions: [EntityGenerator],\n debug: true,\n }) as Parameters<typeof MikroORM.initSync>[0];\n\n const orm = MikroORM.initSync(ormConfig);\n console.log(`✅ Connected to ${options.dbName} at ${options.host}:${options.port}`);\n\n const onCreatingVersionField = async (metadatas: EntityMetadata[]) => {\n metadatas.forEach((m) => {\n if (options.versionField) {\n const versionFieldName = Object.keys(m.properties).find((p) => {\n return (\n p === options.versionField ||\n m.properties[p]?.name === options.versionField ||\n m.properties[p]?.fieldNames?.find((f) => f === options.versionField)\n );\n });\n if (versionFieldName) {\n const property = m.properties[versionFieldName];\n if (\n property.type !== \"datetime\" &&\n property.type !== \"integer\" &&\n property.type !== \"decimal\"\n ) {\n console.warn(\n `Version field \"${property.name}\" can be only datetime or integer Table ${m.tableName} but now is \"${property.type}\"`,\n );\n return;\n }\n if (property.primary) {\n console.warn(\n `Version field \"${property.name}\" can not be primary key Table ${m.tableName}`,\n );\n return;\n }\n if (property.nullable) {\n console.warn(\n `Version field \"${property.name}\" should not be nullable Table ${m.tableName}`,\n );\n return;\n }\n property.version = true;\n }\n }\n });\n };\n await orm.entityGenerator.generate({\n entitySchema: true,\n bidirectionalRelations: true,\n identifiedReferences: false,\n forceUndefined: true,\n undefinedDefaults: true,\n useCoreBaseEntity: false,\n onlyPurePivotTables: false,\n outputPurePivotTables: false,\n scalarPropertiesForRelations: \"always\",\n save: true,\n path: options.output,\n onInitialMetadata: onCreatingVersionField,\n });\n\n regenerateIndexFile(options.output);\n\n console.log(`✅ Entities generated at: ${options.output}`);\n process.exit(0);\n } catch (error) {\n console.error(`❌ Error generating entities:`, error);\n process.exit(1);\n }\n};\n","import \"reflect-metadata\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { MikroORM } from \"@mikro-orm/mysql\";\nimport { execSync } from \"child_process\";\nimport { rmSync } from \"fs\";\n\n/**\n * Cleans SQL statements by removing unnecessary database options.\n * @param sql - The raw SQL statement.\n * @returns The cleaned SQL statement.\n */\nfunction cleanSQLStatement(sql: string): string {\n // Add IF NOT EXISTS to CREATE TABLE statements\n sql = sql.replace(/create\\s+table\\s+(\\w+)/gi, \"create table if not exists $1\");\n\n // Add IF NOT EXISTS to CREATE INDEX statements\n sql = sql.replace(/create\\s+index\\s+(\\w+)/gi, \"create index if not exists $1\");\n\n // Add IF NOT EXISTS to ADD INDEX statements\n sql = sql.replace(/alter\\s+table\\s+(\\w+)\\s+add\\s+index\\s+(\\w+)/gi, \"alter table $1 add index if not exists $2\");\n\n // Add IF NOT EXISTS to ADD CONSTRAINT statements\n sql = sql.replace(/alter\\s+table\\s+(\\w+)\\s+add\\s+constraint\\s+(\\w+)/gi, \"alter table $1 add constraint if not exists $2\");\n\n // Remove unnecessary database options\n return sql.replace(/\\s+default\\s+character\\s+set\\s+utf8mb4\\s+engine\\s*=\\s*InnoDB;?/gi, \"\").trim();\n}\n\n/**\n * Generates a migration file using the provided SQL statements.\n * @param createStatements - Array of SQL statements.\n * @param version - Migration version number.\n * @returns TypeScript migration file content.\n */\nfunction generateMigrationFile(createStatements: string[], version: number): string {\n const versionPrefix = `v${version}_MIGRATION`;\n\n // Clean each SQL statement and generate migration lines with .enqueue()\n const migrationLines = createStatements\n .map(\n (stmt, index) =>\n ` .enqueue(\"${versionPrefix}${index}\", \\\"${cleanSQLStatement(stmt)}\\\")`, // eslint-disable-line no-useless-escape\n )\n .join(\"\\n\");\n\n // Migration template\n return `import { MigrationRunner } from \"@forge/sql/out/migration\";\n\nexport default (migrationRunner: MigrationRunner): MigrationRunner => {\n return migrationRunner\n${migrationLines};\n};`;\n}\n\n/**\n * Saves the generated migration file along with `migrationCount.ts` and `index.ts`.\n * @param migrationCode - The migration code to be written to the file.\n * @param version - Migration version number.\n * @param outputDir - Directory where the migration files will be saved.\n */\nfunction saveMigrationFiles(migrationCode: string, version: number, outputDir: string) {\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);\n const migrationCountPath = path.join(outputDir, `migrationCount.ts`);\n const indexFilePath = path.join(outputDir, `index.ts`);\n\n // Write the migration file\n fs.writeFileSync(migrationFilePath, migrationCode);\n\n // Write the migration count file\n fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);\n\n // Generate the migration index file\n const indexFileContent = `import { MigrationRunner } from \"@forge/sql/out/migration\";\nimport { MIGRATION_VERSION } from \"./migrationCount\";\n\nexport type MigrationType = (\n migrationRunner: MigrationRunner,\n) => MigrationRunner;\n\nexport default async (\n migrationRunner: MigrationRunner,\n): Promise<MigrationRunner> => {\n for (let i = 1; i <= MIGRATION_VERSION; i++) {\n const migrations = (await import(\\`./migrationV\\${i}\\`)) as {\n default: MigrationType;\n };\n migrations.default(migrationRunner);\n }\n return migrationRunner;\n};`;\n\n fs.writeFileSync(indexFilePath, indexFileContent);\n\n console.log(`✅ Migration file created: ${migrationFilePath}`);\n console.log(`✅ Migration count file updated: ${migrationCountPath}`);\n console.log(`✅ Migration index file created: ${indexFilePath}`);\n}\n\n/**\n * Extracts only the relevant SQL statements for migration.\n * @param schema - The full database schema as SQL.\n * @returns Filtered list of SQL statements.\n */\nconst extractCreateStatements = (schema: string): string[] => {\n const statements = schema.split(\";\").map((s) => s.trim());\n\n return statements.filter(\n (stmt) =>\n stmt.startsWith(\"create table\") ||\n (stmt.startsWith(\"alter table\") && (stmt.includes(\"add index\") || stmt.includes(\"add constraint\"))) ||\n stmt.startsWith(\"primary\"),\n );\n};\n\n/**\n * Dynamically loads `entities` from `index.ts` in the specified directory.\n * @param entitiesPath - Path to the directory containing `index.ts`.\n * @returns Array of entity classes.\n */\nconst loadEntities = async (entitiesPath: string) => {\n try {\n const indexFilePath = path.resolve(path.join(entitiesPath, \"index.ts\"));\n if (!fs.existsSync(indexFilePath)) {\n console.error(`❌ Error: index.ts not found in ${indexFilePath}`);\n process.exit(1);\n }\n\n const { default: entities } = await import(indexFilePath);\n console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);\n return entities;\n } catch (error) {\n console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Loads the current migration version from `migrationCount.ts`.\n * @param migrationPath - Path to the migration folder.\n * @returns The latest migration version.\n */\nconst loadMigrationVersion = async (migrationPath: string): Promise<number> => {\n try {\n const migrationCountFilePath = path.resolve(path.join(migrationPath, \"migrationCount.ts\"));\n if (!fs.existsSync(migrationCountFilePath)) {\n return 0;\n }\n\n const { MIGRATION_VERSION } = await import(migrationCountFilePath);\n console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);\n return MIGRATION_VERSION as number;\n } catch (error) {\n console.error(`❌ Error loading migrationCount:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Creates a full database migration.\n * @param options - Database connection settings and output paths.\n */\nexport const createMigration = async (options: any) => {\n try {\n let version = await loadMigrationVersion(options.output);\n\n if (version > 0) {\n if (options.force) {\n console.warn(`⚠️ Warning: Migration already exists. Creating new migration with force flag...`);\n } else {\n console.error(`❌ Error: Migration has already been created. Use --force flag to override.`);\n process.exit(1);\n }\n }\n\n // Start from version 1 if no previous migrations exist\n version = 1;\n\n // Load entities dynamically from index.ts\n const entities = await loadEntities(options.entitiesPath);\n\n // Initialize MikroORM\n const orm = MikroORM.initSync({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n entities: entities,\n });\n\n // Generate SQL schema\n const createSchemaSQL = await orm.schema.getCreateSchemaSQL({ wrap: true });\n const statements = extractCreateStatements(createSchemaSQL);\n\n // Generate and save migration files\n const migrationFile = generateMigrationFile(statements, version);\n saveMigrationFiles(migrationFile, version, options.output);\n\n console.log(`✅ Migration successfully created!`);\n process.exit(0);\n } catch (error) {\n console.error(`❌ Error during migration creation:`, error);\n process.exit(1);\n }\n};\n","import \"reflect-metadata\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { MikroORM } from \"@mikro-orm/mysql\";\n\n/**\n * Cleans SQL statements by removing unnecessary database options.\n * @param sql - The raw SQL statement.\n * @returns The cleaned SQL statement.\n */\nfunction cleanSQLStatement(sql: string): string {\n return sql.replace(/\\s+default\\s+character\\s+set\\s+utf8mb4\\s+engine\\s*=\\s*InnoDB;?/gi, \"\").trim();\n}\n\n/**\n * Generates a migration file using the provided SQL statements.\n * @param createStatements - Array of SQL statements.\n * @param version - Migration version number.\n * @returns TypeScript migration file content.\n */\nfunction generateMigrationFile(createStatements: string[], version: number): string {\n const versionPrefix = `v${version}_MIGRATION`;\n\n // Clean each SQL statement and generate migration lines with .enqueue()\n const migrationLines = createStatements\n .map(\n (stmt, index) =>\n ` .enqueue(\"${versionPrefix}${index}\", \\\"${cleanSQLStatement(stmt)}\\\")`, // eslint-disable-line no-useless-escape\n )\n .join(\"\\n\");\n\n // Migration template\n return `import { MigrationRunner } from \"@forge/sql/out/migration\";\n\nexport default (migrationRunner: MigrationRunner): MigrationRunner => {\n return migrationRunner\n${migrationLines};\n};`;\n}\n\n/**\n * Saves the generated migration file along with `migrationCount.ts` and `index.ts`.\n * @param migrationCode - The migration code to be written to the file.\n * @param version - Migration version number.\n * @param outputDir - Directory where the migration files will be saved.\n */\nfunction saveMigrationFiles(migrationCode: string, version: number, outputDir: string) {\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);\n const migrationCountPath = path.join(outputDir, `migrationCount.ts`);\n const indexFilePath = path.join(outputDir, `index.ts`);\n\n // Write the migration file\n fs.writeFileSync(migrationFilePath, migrationCode);\n\n // Write the migration count file\n fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);\n\n // Generate the migration index file\n const indexFileContent = `import { MigrationRunner } from \"@forge/sql/out/migration\";\nimport { MIGRATION_VERSION } from \"./migrationCount\";\n\nexport type MigrationType = (\n migrationRunner: MigrationRunner,\n) => MigrationRunner;\n\nexport default async (\n migrationRunner: MigrationRunner,\n): Promise<MigrationRunner> => {\n for (let i = 1; i <= MIGRATION_VERSION; i++) {\n const migrations = (await import(\\`./migrationV\\${i}\\`)) as {\n default: MigrationType;\n };\n migrations.default(migrationRunner);\n }\n return migrationRunner;\n};`;\n\n fs.writeFileSync(indexFilePath, indexFileContent);\n\n console.log(`✅ Migration file created: ${migrationFilePath}`);\n console.log(`✅ Migration count file updated: ${migrationCountPath}`);\n console.log(`✅ Migration index file created: ${indexFilePath}`);\n}\n\n/**\n * Extracts only the relevant SQL statements for migration.\n * @param schema - The full database schema as SQL.\n * @returns Filtered list of SQL statements.\n */\nconst extractCreateStatements = (schema: string): string[] => {\n const statements = schema.split(\";\").map((s) => s.trim());\n\n return statements.filter(\n (stmt) =>\n stmt.startsWith(\"create table\") ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"add index\")) ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"add\") && !stmt.includes(\"foreign\")) ||\n (stmt.startsWith(\"alter table\") && stmt.includes(\"modify\") && !stmt.includes(\"foreign\")),\n );\n};\n\n/**\n * Dynamically loads `entities` from `index.ts` in the specified directory.\n * @param entitiesPath - Path to the directory containing `index.ts`.\n * @returns Array of entity classes.\n */\nconst loadEntities = async (entitiesPath: string) => {\n try {\n const indexFilePath = path.resolve(path.join(entitiesPath, \"index.ts\"));\n if (!fs.existsSync(indexFilePath)) {\n console.error(`❌ Error: index.ts not found in ${entitiesPath}`);\n process.exit(1);\n }\n\n const { default: entities } = await import(indexFilePath);\n console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);\n return entities;\n } catch (error) {\n console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Loads the current migration version from `migrationCount.ts`.\n * @param migrationPath - Path to the migration folder.\n * @returns The latest migration version.\n */\nconst loadMigrationVersion = async (migrationPath: string): Promise<number> => {\n try {\n const migrationCountFilePath = path.resolve(path.join(migrationPath, \"migrationCount.ts\"));\n if (!fs.existsSync(migrationCountFilePath)) {\n console.warn(\n `⚠️ Warning: migrationCount.ts not found in ${migrationCountFilePath}, assuming no previous migrations.`,\n );\n return 0;\n }\n\n const { MIGRATION_VERSION } = await import(migrationCountFilePath);\n console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);\n return MIGRATION_VERSION as number;\n } catch (error) {\n console.error(`❌ Error loading migrationCount:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Updates an existing database migration by generating schema modifications.\n * @param options - Database connection settings and output paths.\n */\nexport const updateMigration = async (options: any) => {\n try {\n let version = await loadMigrationVersion(options.output);\n\n if (version < 1) {\n console.log(\n `⚠️ Initial migration not found. Run \"npx forge-sql-orm migrations:create\" first.`,\n );\n process.exit(0);\n }\n version += 1;\n\n // Load entities dynamically from index.ts\n const entities = await loadEntities(options.entitiesPath);\n\n // Initialize MikroORM\n const orm = MikroORM.initSync({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n entities,\n debug: true,\n });\n\n // Generate SQL schema updates\n const createSchemaSQL = await orm.schema.getUpdateSchemaMigrationSQL({ wrap: true });\n const statements = extractCreateStatements(createSchemaSQL?.down || \"\");\n\n if (statements.length) {\n const migrationFile = generateMigrationFile(statements, version);\n saveMigrationFiles(migrationFile, version, options.output);\n\n console.log(`✅ Migration successfully updated!`);\n process.exit(0);\n } else {\n console.log(`⚠️ No new migration changes detected.`);\n process.exit(0);\n }\n } catch (error) {\n console.error(`❌ Error during migration update:`, error);\n process.exit(1);\n }\n};\n","import fs from \"fs\";\nimport path from \"path\";\n\n/**\n * Automates patches for MikroORM and Knex to fix Webpack issues.\n * - Removes problematic `require()` calls.\n * - Deletes unnecessary files and folders.\n * - Fixes dynamic imports (`import(id)`) in MikroORM.\n */\n\ninterface Patch {\n file?: string; // File to modify (optional)\n search?: RegExp; // Regex pattern to find problematic code\n replace?: string; // Replacement string for problematic code\n deleteLines?: RegExp[]; // List of regex patterns to remove specific lines\n description: string; // Description of the patch\n deleteFile?: string; // Path of the file to delete (optional)\n deleteFolder?: string; // Path of the folder to delete (optional)\n}\n\nconst PATCHES: Patch[] = [\n // 🗑️ Remove unused dialects (mssql, postgres, sqlite) in MikroORM\n {\n file: \"node_modules/@mikro-orm/knex/MonkeyPatchable.d.ts\",\n deleteLines: [\n /^.*mssql.*$/gim,\n /^.*MsSql.*$/gim,\n /^\\s*Postgres.*$/gm,\n /^.*Sqlite3.*$/gm,\n /^.*BetterSqlite3.*$/gim,\n ],\n description: \"Removing unused dialects from MonkeyPatchable.d.ts\",\n },\n {\n file: \"node_modules/@mikro-orm/knex/MonkeyPatchable.js\",\n deleteLines: [\n /^.*mssql.*$/gim,\n /^.*MsSql.*$/gim,\n /^.*postgres.*$/gim,\n /^.*sqlite.*$/gim,\n /^.*Sqlite.*$/gim,\n ],\n description: \"Removing unused dialects from MonkeyPatchable.js\",\n },\n {\n file: \"node_modules/@mikro-orm/knex/dialects/index.js\",\n deleteLines: [/^.*mssql.*$/gim, /^.*MsSql.*$/gim, /^.*postgresql.*$/gim, /^.*sqlite.*$/gim],\n description: \"Removing unused dialects from @mikro-orm/knex/dialects/index.js\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/dialects/mssql\",\n description: \"Removing mssql dialect from MikroORM\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/dialects/postgresql\",\n description: \"Removing postgresql dialect from MikroORM\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/dialects/sqlite\",\n description: \"Removing sqlite dialect from MikroORM\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/mysql/node_modules\",\n description: \"Removing node_modules from @mikro-orm/mysql\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/knex/node_modules\",\n description: \"Removing node_modules from @mikro-orm/knex\",\n },\n {\n deleteFolder: \"node_modules/@mikro-orm/core/node_modules\",\n description: \"Removing sqlite dialect from MikroORM\",\n },\n\n // 🔄 Fix Webpack `Critical dependency: the request of a dependency is an expression`\n {\n file: \"node_modules/@mikro-orm/core/utils/Configuration.js\",\n search: /dynamicImportProvider:\\s*\\/\\* istanbul ignore next \\*\\/\\s*\\(id\\) => import\\(id\\),/g,\n replace: \"dynamicImportProvider: /* istanbul ignore next */ () => Promise.resolve({}),\",\n description: \"Fixing dynamic imports in MikroORM Configuration\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /static dynamicImportProvider = \\(id\\) => import\\(id\\);/g,\n replace: \"static dynamicImportProvider = () => Promise.resolve({});\",\n description: \"Fixing dynamic imports in MikroORM Utils.js\",\n },\n\n // 🛑 Remove deprecated `require.extensions` usage\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /\\s\\|\\|\\s*\\(require\\.extensions\\s*&&\\s*!!require\\.extensions\\['\\.ts'\\]\\);\\s*/g,\n replace: \";\",\n description: \"Removing deprecated `require.extensions` check in MikroORM\",\n },\n\n // 🛠️ Patch Knex to remove `Migrator` and `Seeder`\n {\n file: \"node_modules/knex/lib/knex-builder/make-knex.js\",\n deleteLines: [\n /^const \\{ Migrator \\} = require\\('\\.\\.\\/migrations\\/migrate\\/Migrator'\\);$/gm,\n /^const Seeder = require\\('\\.\\.\\/migrations\\/seed\\/Seeder'\\);$/gm,\n ],\n description: \"Removing `Migrator` and `Seeder` requires from make-knex.js\",\n },\n {\n file: \"node_modules/knex/lib/knex-builder/make-knex.js\",\n search: /\\sreturn new Migrator\\(this\\);/g,\n replace: \"return null;\",\n description: \"Replacing `return new Migrator(this);` with `return null;`\",\n },\n {\n file: \"node_modules/knex/lib/knex-builder/make-knex.js\",\n search: /\\sreturn new Seeder\\(this\\);/g,\n replace: \"return null;\",\n description: \"Replacing `return new Seeder(this);` with `return null;`\",\n },\n {\n file: \"node_modules/knex/lib/dialects/index.js\",\n deleteLines: [\n /^.*mssql.*$/gim,\n /^.*MsSql.*$/gim,\n /^.*postgresql.*$/gim,\n /^.*sqlite.*$/gim,\n /^.*oracle.*$/gim,\n /^.*oracledb.*$/gim,\n /^.*pgnative.*$/gim,\n /^.*postgres.*$/gim,\n /^.*redshift.*$/gim,\n /^.*sqlite3.*$/gim,\n /^.*cockroachdb.*$/gim,\n ],\n description: \"Removing unused dialects from @mikro-orm/knex/dialects/index.js\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /\\s\\|\\|\\s*\\(require\\.extensions\\s*&&\\s*!!require\\.extensions\\['\\.ts'\\]\\);\\s*/g,\n replace: \";\", // Replaces with semicolon to keep syntax valid\n description: \"Removing deprecated `require.extensions` check from MikroORM\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /^.*extensions.*$/gim,\n replace: \"{\", // Replaces with semicolon to keep syntax valid\n description: \"Removing deprecated `require.extensions` check from MikroORM\",\n },\n {\n file: \"node_modules/@mikro-orm/core/utils/Utils.js\",\n search: /^.*package.json.*$/gim,\n replace: \"return 0;\", // Replaces with semicolon to keep syntax valid\n description: \"Removing deprecated `require.extensions` check from MikroORM\",\n },\n {\n file: \"node_modules/@mikro-orm/knex/dialects/mysql/index.js\",\n deleteLines: [/^.*MariaDbKnexDialect.*$/gim],\n description: \"Removing MariaDbKnexDialect\",\n },\n];\n\n/**\n * Runs the MikroORM & Knex patching logic.\n */\nexport function runPostInstallPatch() {\n console.log(\"🔧 Applying MikroORM & Knex patches...\");\n PATCHES.forEach(\n ({ file, search, replace, deleteLines, deleteFile, deleteFolder, description }) => {\n if (file) {\n const filePath = path.resolve(file);\n if (fs.existsSync(filePath)) {\n let content = fs.readFileSync(filePath, \"utf8\");\n let originalContent = content;\n\n // 🔄 Replace text\n if (search && replace) {\n if (typeof search === \"string\" ? content.includes(search) : search.test(content)) {\n content = content.replace(search, replace);\n console.log(`[PATCHED] ${description}`);\n }\n }\n\n // 🗑️ Remove matching lines\n if (deleteLines) {\n deleteLines.forEach((pattern) => {\n content = content\n .split(\"\\n\")\n .filter((line) => !pattern.test(line))\n .join(\"\\n\");\n });\n if (content !== originalContent) {\n console.log(`[CLEANED] Removed matching lines in ${file}`);\n }\n }\n\n // 💾 Save changes only if file was modified\n if (content !== originalContent) {\n fs.writeFileSync(filePath, content, \"utf8\");\n }\n\n // 🚮 Remove empty files\n if (content.trim() === \"\") {\n fs.unlinkSync(filePath);\n console.log(`[REMOVED] ${filePath} (file is now empty)`);\n }\n } else {\n console.warn(`[WARNING] File not found: ${file}`);\n }\n }\n\n // 🚮 Delete specific files\n if (deleteFile) {\n const deleteFilePath = path.resolve(deleteFile);\n if (fs.existsSync(deleteFilePath)) {\n fs.unlinkSync(deleteFilePath);\n console.log(`[DELETED] ${deleteFilePath} ${description}`);\n } else {\n console.log(`[SKIPPED] ${deleteFilePath} ${description}`);\n }\n }\n\n // 🚮 Delete entire folders\n if (deleteFolder) {\n const deleteFolderPath = path.resolve(deleteFolder);\n if (fs.existsSync(deleteFolderPath)) {\n fs.rmSync(deleteFolderPath, { recursive: true, force: true });\n console.log(`[DELETED] ${deleteFolderPath} ${description}`);\n } else {\n console.log(`[SKIPPED] ${deleteFolderPath} ${description}`);\n }\n }\n },\n );\n\n console.log(\"🎉 MikroORM & Knex patching completed!\");\n}\n","import \"reflect-metadata\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { MikroORM } from \"@mikro-orm/mysql\";\nimport { execSync } from \"child_process\";\nimport { rmSync } from \"fs\";\n\n/**\n * Generates a migration ID using current date\n * @returns Migration ID string with current date\n */\nfunction generateMigrationUUID(version:number): string {\n const now = new Date();\n const timestamp = now.getTime();\n return `MIGRATION_V${version}_${timestamp}`;\n}\n\n/**\n * Cleans SQL statements by removing unnecessary database options.\n * @param sql - The raw SQL statement.\n * @returns The cleaned SQL statement.\n */\nfunction cleanSQLStatement(sql: string): string {\n // Remove unnecessary database options\n return sql.replace(/\\s+default\\s+character\\s+set\\s+utf8mb4\\s+engine\\s*=\\s*InnoDB;?/gi, \"\").trim();\n}\n\n/**\n * Generates a migration file using the provided SQL statements.\n * @param createStatements - Array of SQL statements.\n * @param version - Migration version number.\n * @returns TypeScript migration file content.\n */\nfunction generateMigrationFile(createStatements: string[], version: number): string {\n const uniqId = generateMigrationUUID(version);\n // Clean each SQL statement and generate migration lines with .enqueue()\n const migrationLines = createStatements\n .map(\n (stmt, index) =>\n ` .enqueue(\"${uniqId}_${index}\", \\\"${cleanSQLStatement(stmt)}\\\")`, // eslint-disable-line no-useless-escape\n )\n .join(\"\\n\");\n\n // Add migration to clear migrations table\n const clearMigrationsLine = ` .enqueue(\"${uniqId}\", \"DELETE FROM __migrations\")`;\n\n // Migration template\n return `import { MigrationRunner } from \"@forge/sql/out/migration\";\n\nexport default (migrationRunner: MigrationRunner): MigrationRunner => {\n return migrationRunner\n${migrationLines}\n${clearMigrationsLine};\n};`;\n}\n\n/**\n * Saves the generated migration file along with `migrationCount.ts` and `index.ts`.\n * @param migrationCode - The migration code to be written to the file.\n * @param version - Migration version number.\n * @param outputDir - Directory where the migration files will be saved.\n */\nfunction saveMigrationFiles(migrationCode: string, version: number, outputDir: string) {\n if (!fs.existsSync(outputDir)) {\n fs.mkdirSync(outputDir, { recursive: true });\n }\n\n const migrationFilePath = path.join(outputDir, `migrationV${version}.ts`);\n const migrationCountPath = path.join(outputDir, `migrationCount.ts`);\n const indexFilePath = path.join(outputDir, `index.ts`);\n\n // Write the migration file\n fs.writeFileSync(migrationFilePath, migrationCode);\n\n // Write the migration count file\n fs.writeFileSync(migrationCountPath, `export const MIGRATION_VERSION = ${version};`);\n\n // Generate the migration index file\n const indexFileContent = `import { MigrationRunner } from \"@forge/sql/out/migration\";\nimport { MIGRATION_VERSION } from \"./migrationCount\";\n\nexport type MigrationType = (\n migrationRunner: MigrationRunner,\n) => MigrationRunner;\n\nexport default async (\n migrationRunner: MigrationRunner,\n): Promise<MigrationRunner> => {\n for (let i = 1; i <= MIGRATION_VERSION; i++) {\n const migrations = (await import(\\`./migrationV\\${i}\\`)) as {\n default: MigrationType;\n };\n migrations.default(migrationRunner);\n }\n return migrationRunner;\n};`;\n\n fs.writeFileSync(indexFilePath, indexFileContent);\n\n console.log(`✅ Migration file created: ${migrationFilePath}`);\n console.log(`✅ Migration count file updated: ${migrationCountPath}`);\n console.log(`✅ Migration index file created: ${indexFilePath}`);\n}\n\n/**\n * Extracts only the relevant SQL statements for migration.\n * @param schema - The full database schema as SQL.\n * @returns Filtered list of SQL statements.\n */\nconst extractDropStatements = (schema: string): string[] => {\n const statements = schema.split(\";\").map((s) => s.trim());\n return statements.filter((s)=>{\n return s.toLowerCase().startsWith(\"drop\");\n });\n};\n\n/**\n * Dynamically loads `entities` from `index.ts` in the specified directory.\n * @param entitiesPath - Path to the directory containing `index.ts`.\n * @returns Array of entity classes.\n */\nconst loadEntities = async (entitiesPath: string) => {\n try {\n const indexFilePath = path.resolve(path.join(entitiesPath, \"index.ts\"));\n if (!fs.existsSync(indexFilePath)) {\n console.error(`❌ Error: index.ts not found in ${indexFilePath}`);\n process.exit(1);\n }\n\n const { default: entities } = await import(indexFilePath);\n console.log(`✅ Loaded ${entities.length} entities from ${entitiesPath}`);\n return entities;\n } catch (error) {\n console.error(`❌ Error loading index.ts from ${entitiesPath}:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Loads the current migration version from `migrationCount.ts`.\n * @param migrationPath - Path to the migration folder.\n * @returns The latest migration version.\n */\nconst loadMigrationVersion = async (migrationPath: string): Promise<number> => {\n try {\n const migrationCountFilePath = path.resolve(path.join(migrationPath, \"migrationCount.ts\"));\n if (!fs.existsSync(migrationCountFilePath)) {\n return 0;\n }\n\n const { MIGRATION_VERSION } = await import(migrationCountFilePath);\n console.log(`✅ Current migration version: ${MIGRATION_VERSION}`);\n return MIGRATION_VERSION as number;\n } catch (error) {\n console.error(`❌ Error loading migrationCount:`, error);\n process.exit(1);\n }\n};\n\n/**\n * Creates a full database migration.\n * @param options - Database connection settings and output paths.\n */\nexport const dropMigration = async (options: any) => {\n try {\n\n // Start from version 1 if no previous migrations exist\n const version = 1;\n\n // Load entities dynamically from index.ts\n const entities = await loadEntities(options.entitiesPath);\n\n // Initialize MikroORM\n const orm = MikroORM.initSync({\n host: options.host,\n port: options.port,\n user: options.user,\n password: options.password,\n dbName: options.dbName,\n entities: entities,\n });\n\n // Generate SQL schema\n const dropSchemaSQL = await orm.schema.getDropSchemaSQL({ wrap: true });\n const statements = extractDropStatements(dropSchemaSQL);\n\n // Generate and save migration files\n const migrationFile = generateMigrationFile(statements, version);\n saveMigrationFiles(migrationFile, version, options.output);\n\n console.log(`✅ Migration successfully created!`);\n process.exit(0);\n } catch (error) {\n console.error(`❌ Error during migration creation:`, error);\n process.exit(1);\n }\n};\n","#!/usr/bin/env node\n\nimport { Command } from \"commander\";\nimport dotenv from \"dotenv\";\nimport inquirer from \"inquirer\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { generateModels } from \"./actions/generate-models\";\nimport { createMigration } from \"./actions/migrations-create\";\nimport { updateMigration } from \"./actions/migrations-update\";\nimport { runPostInstallPatch } from \"./actions/PatchPostinstall\";\nimport { dropMigration } from \"./actions/migrations-drops\";\n\nconst ENV_PATH = path.resolve(process.cwd(), \".env\");\n// 🔄 Load environment variables from `.env` file\ndotenv.config({ path: ENV_PATH });\n\nconst saveEnvFile = (config: any) => {\n let envContent = \"\";\n const envFilePath = ENV_PATH;\n\n if (fs.existsSync(envFilePath)) {\n envContent = fs.readFileSync(envFilePath, \"utf8\");\n }\n\n const envVars = envContent\n .split(\"\\n\")\n .filter((line) => line.trim() !== \"\" && !line.startsWith(\"#\"))\n .reduce((acc: any, line) => {\n const [key, ...value] = line.split(\"=\");\n acc[key] = value.join(\"=\");\n return acc;\n }, {});\n\n Object.entries(config).forEach(([key, value]) => {\n envVars[`FORGE_SQL_ORM_${key.toUpperCase()}`] = value;\n });\n\n const updatedEnvContent = Object.entries(envVars)\n .map(([key, value]) => `${key}=${value}`)\n .join(\"\\n\");\n\n fs.writeFileSync(envFilePath, updatedEnvContent, { encoding: \"utf8\" });\n\n console.log(\"✅ Configuration saved to .env without overwriting other variables.\");\n};\n\n/**\n * Prompts the user for missing parameters using Inquirer.js.\n * @param config - The current configuration object.\n * @param defaultOutput - Default output path.\n * @param customAskMissingParams - Optional function for additional prompts.\n * @returns Updated configuration with user input.\n */\nconst askMissingParams = async (\n config: any,\n defaultOutput: string,\n customAskMissingParams?: (cfg: any, questions: unknown[]) => void,\n) => {\n const questions: unknown[] = [];\n\n if (!config.host)\n questions.push({\n type: \"input\",\n name: \"host\",\n message: \"Enter database host:\",\n default: \"localhost\",\n });\n\n if (!config.port)\n questions.push({\n type: \"input\",\n name: \"port\",\n message: \"Enter database port:\",\n default: \"3306\",\n validate: (input: string) => !isNaN(parseInt(input, 10)),\n });\n\n if (!config.user)\n questions.push({\n type: \"input\",\n name: \"user\",\n message: \"Enter database user:\",\n default: \"root\",\n });\n\n if (!config.password)\n questions.push({\n type: \"password\",\n name: \"password\",\n message: \"Enter database password:\",\n mask: \"*\",\n });\n\n if (!config.dbName)\n questions.push({\n type: \"input\",\n name: \"dbName\",\n message: \"Enter database name:\",\n });\n\n if (!config.output)\n questions.push({\n type: \"input\",\n name: \"output\",\n message: \"Enter output path:\",\n default: defaultOutput,\n });\n\n // Allow additional questions from the caller\n if (customAskMissingParams) {\n customAskMissingParams(config, questions);\n }\n\n // If there are missing parameters, prompt the user\n if (questions.length > 0) {\n // @ts-ignore - Ignore TypeScript warning for dynamic question type\n const answers = await inquirer.prompt(questions);\n return { ...config, ...answers, port: parseInt(config.port ?? answers.port, 10) };\n }\n\n return config;\n};\n\n/**\n * Retrieves configuration parameters from command-line arguments and environment variables.\n * If any required parameters are missing, prompts the user for input.\n * @param cmd - The command object containing CLI options.\n * @param defaultOutput - Default output directory.\n * @param customConfig - Optional function for additional configuration parameters.\n * @param customAskMissingParams - Optional function for additional prompts.\n * @returns A fully resolved configuration object.\n */\nconst getConfig = async (\n cmd: any,\n defaultOutput: string,\n customConfig?: () => any,\n customAskMissingParams?: (cfg: any, questions: unknown[]) => void,\n) => {\n let config = {\n host: cmd.host || process.env.FORGE_SQL_ORM_HOST,\n port: cmd.port\n ? parseInt(cmd.port, 10)\n : process.env.FORGE_SQL_ORM_PORT\n ? parseInt(process.env.FORGE_SQL_ORM_PORT, 10)\n : undefined,\n user: cmd.user || process.env.FORGE_SQL_ORM_USER,\n password: cmd.password || process.env.FORGE_SQL_ORM_PASSWORD,\n dbName: cmd.dbName || process.env.FORGE_SQL_ORM_DBNAME,\n output: cmd.output || process.env.FORGE_SQL_ORM_OUTPUT,\n };\n\n // Merge additional configurations if provided\n if (customConfig) {\n config = { ...config, ...customConfig() };\n }\n\n const conf = await askMissingParams(config, defaultOutput, customAskMissingParams);\n if (cmd.saveEnv) {\n saveEnvFile(conf);\n }\n return conf;\n};\n\n// 📌 Initialize CLI\nconst program = new Command();\nprogram.version(\"1.0.0\");\n\n// ✅ Command: Generate database models (Entities)\nprogram\n .command(\"generate:model\")\n .description(\"Generate MikroORM models from the database.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for entities\")\n .option(\"--versionField <string>\", \"Field name for versioning\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/entities\",\n () => ({\n versionField: cmd.versionField || process.env.FORGE_SQL_ORM_VERSIONFIELD,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.versionField) {\n questions.push({\n type: \"input\",\n name: \"versionField\",\n message: \"Enter the field name for versioning (leave empty to skip):\",\n default: \"\",\n });\n }\n },\n );\n await generateModels(config);\n });\n\n// ✅ Command: Create initial database migration\nprogram\n .command(\"migrations:create\")\n .description(\"Generate an initial migration for the entire database.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for migrations\")\n .option(\"--entitiesPath <string>\", \"Path to the folder containing entities\")\n .option(\"--force\", \"Force creation even if migrations exist\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/migration\",\n () => ({\n entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH,\n force: cmd.force || false,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.entitiesPath)\n questions.push({\n type: \"input\",\n name: \"entitiesPath\",\n message: \"Enter the path to entities:\",\n default: \"./database/entities\",\n });\n },\n );\n await createMigration(config);\n });\n\n// ✅ Command: Update migration for schema changes\nprogram\n .command(\"migrations:update\")\n .description(\"Generate a migration to update the database schema.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for migrations\")\n .option(\"--entitiesPath <string>\", \"Path to the folder containing entities\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/migration\",\n () => ({\n entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.entitiesPath)\n questions.push({\n type: \"input\",\n name: \"entitiesPath\",\n message: \"Enter the path to entities:\",\n default: \"./database/entities\",\n });\n },\n );\n await updateMigration(config);\n });\n\n// ✅ Command: Drop all migrations\nprogram\n .command(\"migrations:drop\")\n .description(\"Generate a migration to drop all tables and clear migrations history.\")\n .option(\"--host <string>\", \"Database host\")\n .option(\"--port <number>\", \"Database port\")\n .option(\"--user <string>\", \"Database user\")\n .option(\"--password <string>\", \"Database password\")\n .option(\"--dbName <string>\", \"Database name\")\n .option(\"--output <string>\", \"Output path for migrations\")\n .option(\"--entitiesPath <string>\", \"Path to the folder containing entities\")\n .option(\"--saveEnv\", \"Save configuration to .env file\")\n .action(async (cmd) => {\n const config = await getConfig(\n cmd,\n \"./database/migration\",\n () => ({\n entitiesPath: cmd.entitiesPath || process.env.FORGE_SQL_ORM_ENTITIESPATH,\n }),\n (cfg, questions: unknown[]) => {\n if (!cfg.entitiesPath)\n questions.push({\n type: \"input\",\n name: \"entitiesPath\",\n message: \"Enter the path to entities:\",\n default: \"./database/entities\",\n });\n },\n );\n await dropMigration(config);\n });\n\n// Patch MikroORM and Knex\nprogram\n .command(\"patch:mikroorm\")\n .description(\"Patch MikroORM and Knex dependencies to work properly with Forge\")\n .action(async () => {\n console.log(\"Running MikroORM patch...\");\n await runPostInstallPatch();\n await runPostInstallPatch();\n await runPostInstallPatch();\n console.log(\"✅ MikroORM patch applied successfully!\");\n });\n\n// 🔥 Execute CLI\nprogram.parse(process.argv);\n"],"names":["cleanSQLStatement","generateMigrationFile","saveMigrationFiles","extractCreateStatements","loadEntities","loadMigrationVersion"],"mappings":";;;;;;;;;AAOA,MAAM,sBAAsB,CAAC,eAAuB;AAC5C,QAAA,cAAc,KAAK,Q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A,OAAO;AAAA,MACL,cAAc,IAAI,gBAAgB,QAAQ,IAAI;AAAA,IAAA;AAAA,IAEhD,CAAC,KAAK,cAAyB;AAC7B,UAAI,CAAC,IAAI;AACP,kBAAU,KAAK;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS;AAAA,QAAA,CACV;AAAA,IAAA;AAAA,EAEP;AACA,QAAM,cAAc,MAAM;AAC5B,CAAC;AAGH,QACG,QAAQ,gBAAgB,EACxB,YAAY,kEAAkE,EAC9E,OAAO,YAAY;AAClB,UAAQ,IAAI,2BAA2B;AACvC,QAAM,oBAAoB;AAC1B,QAAM,oBAAoB;AAC1B,QAAM,oBAAoB;AAC1B,UAAQ,IAAI,wCAAwC;AACtD,CAAC;AAGH,QAAQ,MAAM,QAAQ,IAAI;"}
|
|
@@ -10,15 +10,10 @@ const args = process.argv.slice(2).join(" ");
|
|
|
10
10
|
// Resolve the path to cli.ts (your TypeScript entry file)
|
|
11
11
|
const cliPath = path.resolve(__dirname, "cli.js");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
runCommand(`npx --yes tsm --no-warnings ${cliPath} ${args}`);
|
|
13
|
+
try {
|
|
14
|
+
execSync(`npx --yes tsm --no-warnings ${cliPath} ${args}`, { stdio: "inherit", shell: true });
|
|
15
|
+
process.exit(0);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error("⚠️ Command execution failed:", e.message);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|