fragment-ts 1.0.11 ā 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/init.command.d.ts.map +1 -1
- package/dist/cli/commands/init.command.js +9 -4
- package/dist/cli/commands/init.command.js.map +1 -1
- package/dist/cli/commands/migrate.command.d.ts +14 -0
- package/dist/cli/commands/migrate.command.d.ts.map +1 -1
- package/dist/cli/commands/migrate.command.js +321 -56
- package/dist/cli/commands/migrate.command.js.map +1 -1
- package/dist/typeorm/typeorm-module.d.ts +1 -0
- package/dist/typeorm/typeorm-module.d.ts.map +1 -1
- package/dist/typeorm/typeorm-module.js +109 -52
- package/dist/typeorm/typeorm-module.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/init.command.ts +10 -4
- package/src/cli/commands/migrate.command.ts +416 -59
- package/src/typeorm/typeorm-module.ts +125 -60
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,qBAAa,WAAW;IACtB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;WAe1B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;mBAsF/C,wBAAwB;mBAyCxB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"init.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,qBAAa,WAAW;IACtB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;WAe1B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;mBAsF/C,wBAAwB;mBAyCxB,iBAAiB;mBAmGjB,gBAAgB;mBA+BhB,yBAAyB;mBAoBzB,sBAAsB;mBAmBtB,qBAAqB;mBA2BrB,iBAAiB;CA8CvC"}
|
|
@@ -177,7 +177,7 @@ class InitCommand {
|
|
|
177
177
|
"migrate:revert": "fragment migrate:revert",
|
|
178
178
|
},
|
|
179
179
|
dependencies: {
|
|
180
|
-
"fragment-ts": "^1.0.
|
|
180
|
+
"fragment-ts": "^1.0.13",
|
|
181
181
|
"reflect-metadata": "^0.1.13",
|
|
182
182
|
},
|
|
183
183
|
devDependencies: {
|
|
@@ -210,13 +210,18 @@ class InitCommand {
|
|
|
210
210
|
const fragmentConfig = {};
|
|
211
211
|
if (features.includes("database")) {
|
|
212
212
|
// Default SQLite config with env interpolation
|
|
213
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
213
214
|
fragmentConfig.database = {
|
|
214
215
|
type: "sqlite",
|
|
215
|
-
database:
|
|
216
|
+
database: process.env.DATABASE_FILE || "database.sqlite",
|
|
216
217
|
synchronize: true,
|
|
217
218
|
logging: false,
|
|
218
|
-
entities:
|
|
219
|
-
|
|
219
|
+
entities: isProd
|
|
220
|
+
? ["dist/**/*.entity.js"]
|
|
221
|
+
: ["src/**/*.entity.ts"],
|
|
222
|
+
migrations: isProd
|
|
223
|
+
? ["dist/migrations/**/*.js"]
|
|
224
|
+
: ["src/migrations/**/*.ts"],
|
|
220
225
|
subscribers: [],
|
|
221
226
|
};
|
|
222
227
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.command.js","sourceRoot":"","sources":["../../../src/cli/commands/init.command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6CAA+B;AAC/B,2CAA6B;AAC7B,wDAAgC;AAChC,8CAAsB;AACtB,kDAA0B;AAC1B,iDAAyC;AAEzC,MAAa,WAAW;IACtB,MAAM,CAAC,QAAQ,CAAC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iB,CAAC,WAAmB;QACxD,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;CAiB7B,CAAC;QAEE,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;CAe1B,CAAC;QAEE,MAAM,EAAE,CAAC,SAAS,CAChB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,oBAAoB,CAAC,EAClE,iBAAiB,CAClB,CAAC;QACF,MAAM,EAAE,CAAC,SAAS,CAChB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,iBAAiB,CAAC,EAC5D,cAAc,CACf,CAAC;IACJ,CAAC;CACF;AAjYD,kCAiYC"}
|
|
@@ -2,6 +2,14 @@ import { Command } from "commander";
|
|
|
2
2
|
export declare class MigrateCommand {
|
|
3
3
|
static register(program: Command): void;
|
|
4
4
|
private static generateMigration;
|
|
5
|
+
/**
|
|
6
|
+
* Verify entities are loaded and provide helpful debugging
|
|
7
|
+
*/
|
|
8
|
+
private static verifyEntities;
|
|
9
|
+
/**
|
|
10
|
+
* Build a single query statement with proper escaping
|
|
11
|
+
*/
|
|
12
|
+
private static buildQueryStatement;
|
|
5
13
|
private static createMigration;
|
|
6
14
|
private static runMigrations;
|
|
7
15
|
private static revertMigration;
|
|
@@ -11,5 +19,11 @@ export declare class MigrateCommand {
|
|
|
11
19
|
private static dropSchema;
|
|
12
20
|
private static runSeeds;
|
|
13
21
|
private static createSeed;
|
|
22
|
+
private static checkDatabase;
|
|
23
|
+
private static findEntityFiles;
|
|
24
|
+
/**
|
|
25
|
+
* Build the complete migration file template
|
|
26
|
+
*/
|
|
27
|
+
private static buildMigrationTemplate;
|
|
14
28
|
}
|
|
15
29
|
//# sourceMappingURL=migrate.command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/migrate.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,qBAAa,cAAc;IACzB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;mBAoFlB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"migrate.command.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/migrate.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,qBAAa,cAAc;IACzB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;mBAoFlB,iBAAiB;IA4HtC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IAoB7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;mBA2Bb,eAAe;mBA8Bf,aAAa;mBAoCb,eAAe;mBAqBf,iBAAiB;mBAsBjB,UAAU;mBA+CV,UAAU;mBAqBV,UAAU;mBAqBV,QAAQ;mBA6BR,UAAU;mBA2BV,aAAa;IAuGlC,OAAO,CAAC,MAAM,CAAC,eAAe;IAiB9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAkCtC"}
|
|
@@ -113,67 +113,134 @@ class MigrateCommand {
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
// -----------------------------------------
|
|
116
|
-
// MIGRATION GENERATE
|
|
116
|
+
// MIGRATION GENERATE - REBUILT FOR RELIABILITY
|
|
117
117
|
// -----------------------------------------
|
|
118
118
|
static async generateMigration(nameOrPath, options) {
|
|
119
119
|
const spinner = (0, ora_1.default)("Generating migration...").start();
|
|
120
|
+
let dataSource = null;
|
|
120
121
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
// 1ļøā£ Initialize DataSource
|
|
123
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
124
|
+
if (!dataSource?.isInitialized) {
|
|
125
|
+
throw new Error("Failed to initialize DataSource");
|
|
124
126
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// 1ļøā£ Check migrations folder
|
|
127
|
+
// 1.5ļøā£ Verify entities are loaded
|
|
128
|
+
this.verifyEntities(dataSource);
|
|
129
|
+
// 2ļøā£ Setup migrations directory
|
|
129
130
|
const migrationsDir = path.join(process.cwd(), "src", "migrations");
|
|
131
|
+
await fs.ensureDir(migrationsDir);
|
|
130
132
|
const existingMigrations = fs.existsSync(migrationsDir)
|
|
131
133
|
? fs.readdirSync(migrationsDir).filter((f) => f.endsWith(".ts"))
|
|
132
134
|
: [];
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
const isFirstMigration = existingMigrations.length === 0;
|
|
136
|
+
// 3ļøā£ Generate schema SQL by comparing entities with database
|
|
137
|
+
spinner.text = "Analyzing schema changes...";
|
|
138
|
+
const sqlInMemory = await dataSource.driver.createSchemaBuilder().log();
|
|
139
|
+
const upQueries = sqlInMemory.upQueries || [];
|
|
140
|
+
const downQueries = sqlInMemory.downQueries || [];
|
|
141
|
+
const hasChanges = upQueries.length > 0;
|
|
142
|
+
// 4ļøā£ Handle no changes scenario
|
|
143
|
+
if (!hasChanges && !isFirstMigration) {
|
|
140
144
|
spinner.info("No schema changes detected. Migration not generated.");
|
|
141
145
|
return;
|
|
142
146
|
}
|
|
143
|
-
|
|
147
|
+
if (!hasChanges && isFirstMigration) {
|
|
148
|
+
spinner.warn("No schema changes detected on first migration. Check that:\n" +
|
|
149
|
+
" - Your entities are in the correct location\n" +
|
|
150
|
+
" - You've compiled TypeScript (npm run build)\n" +
|
|
151
|
+
" - Entity paths in fragment.json are correct");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// 5ļøā£ Determine migration name
|
|
144
155
|
const migrationName = options.name ||
|
|
145
|
-
(nameOrPath ? path.basename(nameOrPath)
|
|
156
|
+
(nameOrPath ? path.basename(nameOrPath).replace(/\.ts$/, "") : null) ||
|
|
157
|
+
(isFirstMigration ? "InitialMigration" : "Migration");
|
|
146
158
|
const timestamp = Date.now();
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
const className = `${migrationName}${timestamp}`;
|
|
160
|
+
// 6ļøā£ Build UP queries with safe escaping
|
|
161
|
+
spinner.text = "Building migration file...";
|
|
162
|
+
const upStatements = upQueries.map((query) => {
|
|
163
|
+
return this.buildQueryStatement(query);
|
|
164
|
+
});
|
|
165
|
+
// 7ļøā£ Build DOWN queries with safe escaping
|
|
166
|
+
const downStatements = downQueries.map((query) => {
|
|
167
|
+
return this.buildQueryStatement(query);
|
|
168
|
+
});
|
|
169
|
+
// 8ļøā£ Generate migration file content
|
|
170
|
+
const migrationContent = this.buildMigrationTemplate(className, upStatements, downStatements, isFirstMigration);
|
|
171
|
+
// 9ļøā£ Write migration file
|
|
155
172
|
const fileName = `${timestamp}-${migrationName}.ts`;
|
|
156
173
|
const filePath = path.join(migrationsDir, fileName);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
${upSql || "// initial migration, no changes detected"}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async down(queryRunner: QueryRunner): Promise<void> {
|
|
165
|
-
${downSql || "// initial migration, no changes detected"}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
`;
|
|
169
|
-
await fs.ensureDir(migrationsDir);
|
|
170
|
-
await fs.writeFile(filePath, content);
|
|
171
|
-
spinner.succeed(`Migration generated successfully: ${filePath}`);
|
|
174
|
+
await fs.writeFile(filePath, migrationContent, "utf-8");
|
|
175
|
+
spinner.succeed(`Migration generated: ${chalk_1.default.cyan(fileName)}\n` +
|
|
176
|
+
` ${chalk_1.default.gray("Location:")} ${filePath}\n` +
|
|
177
|
+
` ${chalk_1.default.gray("Queries:")} ${upQueries.length} up, ${downQueries.length} down`);
|
|
172
178
|
}
|
|
173
179
|
catch (error) {
|
|
174
180
|
spinner.fail("Migration generation failed");
|
|
175
|
-
|
|
181
|
+
if (error instanceof Error) {
|
|
182
|
+
console.error(chalk_1.default.red("\nā Error: " + error.message));
|
|
183
|
+
if (error.message.includes("entities")) {
|
|
184
|
+
console.error(chalk_1.default.yellow("\nš” Tip: Make sure your entities are compiled and paths are correct in fragment.json"));
|
|
185
|
+
}
|
|
186
|
+
if (error.stack) {
|
|
187
|
+
console.error(chalk_1.default.gray("\nStack trace:"));
|
|
188
|
+
console.error(chalk_1.default.gray(error.stack));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
console.error(chalk_1.default.red(String(error)));
|
|
193
|
+
}
|
|
194
|
+
process.exit(1);
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
if (dataSource?.isInitialized) {
|
|
198
|
+
try {
|
|
199
|
+
await dataSource.destroy();
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
// Ignore cleanup errors
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Verify entities are loaded and provide helpful debugging
|
|
209
|
+
*/
|
|
210
|
+
static verifyEntities(dataSource) {
|
|
211
|
+
const entities = dataSource.entityMetadatas;
|
|
212
|
+
if (entities.length === 0) {
|
|
213
|
+
throw new Error("No entities found! Make sure:\n" +
|
|
214
|
+
" 1. Your entities are decorated with @Entity()\n" +
|
|
215
|
+
" 2. You've compiled TypeScript: npm run build\n" +
|
|
216
|
+
" 3. Entity paths in fragment.json point to dist/**/*.entity.js\n" +
|
|
217
|
+
" 4. Entity files are named *.entity.ts");
|
|
218
|
+
}
|
|
219
|
+
console.log(chalk_1.default.gray(`\nš¦ Loaded ${entities.length} entity/entities:`));
|
|
220
|
+
entities.forEach((entity) => {
|
|
221
|
+
console.log(chalk_1.default.gray(` - ${entity.name} (${entity.tableName})`));
|
|
222
|
+
});
|
|
223
|
+
console.log();
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Build a single query statement with proper escaping
|
|
227
|
+
*/
|
|
228
|
+
static buildQueryStatement(query) {
|
|
229
|
+
// Escape backslashes, backticks, and dollar signs for template literals
|
|
230
|
+
let sql = query.query
|
|
231
|
+
.replace(/\\/g, "\\\\") // Escape backslashes first
|
|
232
|
+
.replace(/`/g, "\\`") // Escape backticks
|
|
233
|
+
.replace(/\$/g, "\\$") // Escape dollar signs
|
|
234
|
+
.replace(/\r\n/g, " ") // Remove Windows line breaks
|
|
235
|
+
.replace(/\n/g, " ") // Remove Unix line breaks
|
|
236
|
+
.replace(/\s+/g, " ") // Collapse multiple spaces
|
|
237
|
+
.trim();
|
|
238
|
+
// Handle parameters if present
|
|
239
|
+
if (query.parameters && query.parameters.length > 0) {
|
|
240
|
+
const params = JSON.stringify(query.parameters);
|
|
241
|
+
return `await queryRunner.query(\`${sql}\`, ${params});`;
|
|
176
242
|
}
|
|
243
|
+
return `await queryRunner.query(\`${sql}\`);`;
|
|
177
244
|
}
|
|
178
245
|
// -----------------------------------------
|
|
179
246
|
// EXISTING METHODS
|
|
@@ -198,72 +265,146 @@ export class ${name}${timestamp} implements MigrationInterface {
|
|
|
198
265
|
}
|
|
199
266
|
catch (error) {
|
|
200
267
|
spinner.fail("Failed to create migration");
|
|
201
|
-
console.error(chalk_1.default.red(error));
|
|
268
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
269
|
+
process.exit(1);
|
|
202
270
|
}
|
|
203
271
|
}
|
|
204
272
|
static async runMigrations() {
|
|
205
273
|
const spinner = (0, ora_1.default)("Running migrations...").start();
|
|
274
|
+
let dataSource = null;
|
|
206
275
|
try {
|
|
207
|
-
await typeorm_module_1.TypeORMModule.initialize();
|
|
276
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
277
|
+
// Check if migrations directory exists and has migrations
|
|
278
|
+
const migrationsDir = path.join(process.cwd(), "dist", "migrations");
|
|
279
|
+
const hasMigrations = fs.existsSync(migrationsDir) &&
|
|
280
|
+
fs.readdirSync(migrationsDir).filter((f) => f.endsWith(".js")).length >
|
|
281
|
+
0;
|
|
282
|
+
if (!hasMigrations) {
|
|
283
|
+
spinner.info("No compiled migrations found. Run 'npm run build' first or generate migrations.");
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
208
286
|
await typeorm_module_1.TypeORMModule.runMigrations();
|
|
209
287
|
spinner.succeed("Migrations completed successfully");
|
|
210
288
|
}
|
|
211
289
|
catch (error) {
|
|
212
290
|
spinner.fail("Migration failed");
|
|
213
|
-
console.error(chalk_1.default.red(error));
|
|
291
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
292
|
+
process.exit(1);
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
if (dataSource?.isInitialized) {
|
|
296
|
+
await dataSource.destroy();
|
|
297
|
+
}
|
|
214
298
|
}
|
|
215
299
|
}
|
|
216
300
|
static async revertMigration() {
|
|
217
301
|
const spinner = (0, ora_1.default)("Reverting migration...").start();
|
|
302
|
+
let dataSource = null;
|
|
218
303
|
try {
|
|
219
|
-
await typeorm_module_1.TypeORMModule.initialize();
|
|
304
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
220
305
|
await typeorm_module_1.TypeORMModule.revertMigration();
|
|
221
306
|
spinner.succeed("Migration reverted successfully");
|
|
222
307
|
}
|
|
223
308
|
catch (error) {
|
|
224
309
|
spinner.fail("Revert failed");
|
|
225
|
-
console.error(chalk_1.default.red(error));
|
|
310
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
if (dataSource?.isInitialized) {
|
|
315
|
+
await dataSource.destroy();
|
|
316
|
+
}
|
|
226
317
|
}
|
|
227
318
|
}
|
|
228
319
|
static async refreshMigrations() {
|
|
229
320
|
const spinner = (0, ora_1.default)("Refreshing migrations...").start();
|
|
321
|
+
let dataSource = null;
|
|
230
322
|
try {
|
|
231
|
-
await typeorm_module_1.TypeORMModule.initialize();
|
|
323
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
232
324
|
await typeorm_module_1.TypeORMModule.dropSchema();
|
|
233
325
|
await typeorm_module_1.TypeORMModule.runMigrations();
|
|
234
326
|
spinner.succeed("Migrations refreshed successfully");
|
|
235
327
|
}
|
|
236
328
|
catch (error) {
|
|
237
329
|
spinner.fail("Refresh failed");
|
|
238
|
-
console.error(chalk_1.default.red(error));
|
|
330
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
331
|
+
process.exit(1);
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
if (dataSource?.isInitialized) {
|
|
335
|
+
await dataSource.destroy();
|
|
336
|
+
}
|
|
239
337
|
}
|
|
240
338
|
}
|
|
241
339
|
static async showStatus() {
|
|
242
|
-
|
|
243
|
-
|
|
340
|
+
let dataSource = null;
|
|
341
|
+
try {
|
|
342
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
343
|
+
const executedMigrations = await dataSource.query(`SELECT * FROM migrations ORDER BY timestamp DESC`);
|
|
344
|
+
console.log(chalk_1.default.blue("\nš Migration Status:\n"));
|
|
345
|
+
if (executedMigrations.length === 0) {
|
|
346
|
+
console.log(chalk_1.default.yellow(" No migrations have been executed yet."));
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
console.log(chalk_1.default.green(` ā Executed migrations: ${executedMigrations.length}\n`));
|
|
350
|
+
executedMigrations.forEach((m) => {
|
|
351
|
+
console.log(` ${chalk_1.default.cyan(m.name)} - ${new Date(m.timestamp).toLocaleString()}`);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
const migrationsDir = path.join(process.cwd(), "dist", "migrations");
|
|
355
|
+
if (fs.existsSync(migrationsDir)) {
|
|
356
|
+
const files = fs
|
|
357
|
+
.readdirSync(migrationsDir)
|
|
358
|
+
.filter((f) => f.endsWith(".js"));
|
|
359
|
+
console.log(chalk_1.default.blue(`\n Available migration files: ${files.length}`));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
console.error(chalk_1.default.red("Failed to show migration status"));
|
|
364
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
365
|
+
}
|
|
366
|
+
finally {
|
|
367
|
+
if (dataSource?.isInitialized) {
|
|
368
|
+
await dataSource.destroy();
|
|
369
|
+
}
|
|
370
|
+
}
|
|
244
371
|
}
|
|
245
372
|
static async syncSchema() {
|
|
246
373
|
const spinner = (0, ora_1.default)("Synchronizing schema...").start();
|
|
374
|
+
let dataSource = null;
|
|
247
375
|
try {
|
|
248
|
-
await typeorm_module_1.TypeORMModule.initialize();
|
|
376
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
249
377
|
await typeorm_module_1.TypeORMModule.syncSchema();
|
|
250
378
|
spinner.succeed("Schema synchronized");
|
|
251
379
|
}
|
|
252
380
|
catch (error) {
|
|
253
381
|
spinner.fail("Sync failed");
|
|
254
|
-
console.error(chalk_1.default.red(error));
|
|
382
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
383
|
+
process.exit(1);
|
|
384
|
+
}
|
|
385
|
+
finally {
|
|
386
|
+
if (dataSource?.isInitialized) {
|
|
387
|
+
await dataSource.destroy();
|
|
388
|
+
}
|
|
255
389
|
}
|
|
256
390
|
}
|
|
257
391
|
static async dropSchema() {
|
|
258
392
|
const spinner = (0, ora_1.default)("Dropping schema...").start();
|
|
393
|
+
let dataSource = null;
|
|
259
394
|
try {
|
|
260
|
-
await typeorm_module_1.TypeORMModule.initialize();
|
|
395
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
261
396
|
await typeorm_module_1.TypeORMModule.dropSchema();
|
|
262
397
|
spinner.succeed("Schema dropped");
|
|
263
398
|
}
|
|
264
399
|
catch (error) {
|
|
265
400
|
spinner.fail("Drop failed");
|
|
266
|
-
console.error(chalk_1.default.red(error));
|
|
401
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
402
|
+
process.exit(1);
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
if (dataSource?.isInitialized) {
|
|
406
|
+
await dataSource.destroy();
|
|
407
|
+
}
|
|
267
408
|
}
|
|
268
409
|
}
|
|
269
410
|
static async runSeeds() {
|
|
@@ -285,7 +426,8 @@ export class ${name}${timestamp} implements MigrationInterface {
|
|
|
285
426
|
}
|
|
286
427
|
catch (error) {
|
|
287
428
|
spinner.fail("Seed failed");
|
|
288
|
-
console.error(chalk_1.default.red(error));
|
|
429
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
430
|
+
process.exit(1);
|
|
289
431
|
}
|
|
290
432
|
}
|
|
291
433
|
static async createSeed(name) {
|
|
@@ -305,9 +447,132 @@ export class ${name}${timestamp} implements MigrationInterface {
|
|
|
305
447
|
}
|
|
306
448
|
catch (error) {
|
|
307
449
|
spinner.fail("Failed to create seed");
|
|
308
|
-
console.error(chalk_1.default.red(error));
|
|
450
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
451
|
+
process.exit(1);
|
|
309
452
|
}
|
|
310
453
|
}
|
|
454
|
+
static async checkDatabase() {
|
|
455
|
+
console.log(chalk_1.default.blue("\nš Database Diagnostic Check\n"));
|
|
456
|
+
let dataSource = null;
|
|
457
|
+
try {
|
|
458
|
+
// Check fragment.json
|
|
459
|
+
const configPath = path.join(process.cwd(), "fragment.json");
|
|
460
|
+
if (!fs.existsSync(configPath)) {
|
|
461
|
+
console.log(chalk_1.default.yellow("ā ļø fragment.json not found"));
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
console.log(chalk_1.default.green("ā fragment.json found"));
|
|
465
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
466
|
+
console.log(chalk_1.default.gray(` Database type: ${config.database?.type || "not specified"}`));
|
|
467
|
+
console.log(chalk_1.default.gray(` Entity paths: ${JSON.stringify(config.database?.entities || "default")}`));
|
|
468
|
+
}
|
|
469
|
+
// Check dist folder
|
|
470
|
+
const distPath = path.join(process.cwd(), "dist");
|
|
471
|
+
if (!fs.existsSync(distPath)) {
|
|
472
|
+
console.log(chalk_1.default.red("\nā dist/ folder not found - run 'npm run build' first!"));
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
console.log(chalk_1.default.green("\nā dist/ folder exists"));
|
|
477
|
+
}
|
|
478
|
+
// Check for entity files
|
|
479
|
+
const entityFiles = this.findEntityFiles(distPath);
|
|
480
|
+
if (entityFiles.length === 0) {
|
|
481
|
+
console.log(chalk_1.default.red("ā No .entity.js files found in dist/"));
|
|
482
|
+
console.log(chalk_1.default.yellow(" Make sure your entity files are named *.entity.ts"));
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
console.log(chalk_1.default.green(`ā Found ${entityFiles.length} entity file(s):`));
|
|
486
|
+
entityFiles.forEach((f) => console.log(chalk_1.default.gray(` - ${f}`)));
|
|
487
|
+
}
|
|
488
|
+
// Try to connect
|
|
489
|
+
console.log(chalk_1.default.blue("\nš” Attempting database connection..."));
|
|
490
|
+
dataSource = await typeorm_module_1.TypeORMModule.initialize();
|
|
491
|
+
console.log(chalk_1.default.green("ā Database connection successful"));
|
|
492
|
+
// Check loaded entities
|
|
493
|
+
const entities = dataSource.entityMetadatas;
|
|
494
|
+
console.log(chalk_1.default.blue(`\nš¦ Loaded Entities: ${entities.length}`));
|
|
495
|
+
if (entities.length === 0) {
|
|
496
|
+
console.log(chalk_1.default.red("ā No entities loaded by TypeORM!"));
|
|
497
|
+
console.log(chalk_1.default.yellow("\nPossible issues:"));
|
|
498
|
+
console.log(chalk_1.default.yellow(" 1. Entity files not compiled (run npm run build)"));
|
|
499
|
+
console.log(chalk_1.default.yellow(" 2. Entity paths in fragment.json incorrect"));
|
|
500
|
+
console.log(chalk_1.default.yellow(" 3. Missing @Entity() decorator"));
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
entities.forEach((entity) => {
|
|
504
|
+
console.log(chalk_1.default.cyan(`\n ${entity.name}:`));
|
|
505
|
+
console.log(chalk_1.default.gray(` Table: ${entity.tableName}`));
|
|
506
|
+
console.log(chalk_1.default.gray(` Columns: ${entity.columns.length}`));
|
|
507
|
+
entity.columns.forEach((col) => {
|
|
508
|
+
console.log(chalk_1.default.gray(` - ${col.propertyName}: ${col.type}`));
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
// Check database tables
|
|
513
|
+
console.log(chalk_1.default.blue("\nšļø Checking database tables..."));
|
|
514
|
+
const queryRunner = dataSource.createQueryRunner();
|
|
515
|
+
try {
|
|
516
|
+
const tables = await queryRunner.getTables();
|
|
517
|
+
console.log(chalk_1.default.green(`ā Database has ${tables.length} table(s):`));
|
|
518
|
+
tables.forEach((t) => console.log(chalk_1.default.gray(` - ${t.name}`)));
|
|
519
|
+
}
|
|
520
|
+
finally {
|
|
521
|
+
await queryRunner.release();
|
|
522
|
+
}
|
|
523
|
+
console.log(chalk_1.default.green("\nā
Database check complete!\n"));
|
|
524
|
+
}
|
|
525
|
+
catch (error) {
|
|
526
|
+
console.log(chalk_1.default.red("\nā Error during check:"));
|
|
527
|
+
console.error(chalk_1.default.red(error instanceof Error ? error.message : String(error)));
|
|
528
|
+
}
|
|
529
|
+
finally {
|
|
530
|
+
if (dataSource?.isInitialized) {
|
|
531
|
+
await dataSource.destroy();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
static findEntityFiles(dir, files = []) {
|
|
536
|
+
const items = fs.readdirSync(dir);
|
|
537
|
+
for (const item of items) {
|
|
538
|
+
const fullPath = path.join(dir, item);
|
|
539
|
+
const stat = fs.statSync(fullPath);
|
|
540
|
+
if (stat.isDirectory()) {
|
|
541
|
+
this.findEntityFiles(fullPath, files);
|
|
542
|
+
}
|
|
543
|
+
else if (item.endsWith(".entity.js")) {
|
|
544
|
+
files.push(fullPath.replace(process.cwd(), "."));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return files;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Build the complete migration file template
|
|
551
|
+
*/
|
|
552
|
+
static buildMigrationTemplate(className, upStatements, downStatements, isFirstMigration) {
|
|
553
|
+
const upBody = upStatements.length > 0
|
|
554
|
+
? upStatements.map((s) => ` ${s}`).join("\n")
|
|
555
|
+
: " // No changes";
|
|
556
|
+
const downBody = downStatements.length > 0
|
|
557
|
+
? downStatements.map((s) => ` ${s}`).join("\n")
|
|
558
|
+
: " // No changes";
|
|
559
|
+
const comment = isFirstMigration
|
|
560
|
+
? " // Initial migration - creates all tables\n"
|
|
561
|
+
: "";
|
|
562
|
+
return `import { MigrationInterface, QueryRunner } from "typeorm";
|
|
563
|
+
|
|
564
|
+
export class ${className} implements MigrationInterface {
|
|
565
|
+
${comment}
|
|
566
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
567
|
+
${upBody}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
571
|
+
${downBody}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
`;
|
|
575
|
+
}
|
|
311
576
|
}
|
|
312
577
|
exports.MigrateCommand = MigrateCommand;
|
|
313
578
|
//# sourceMappingURL=migrate.command.js.map
|