@rws-framework/db 3.12.0 → 3.12.2
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.
|
@@ -22,6 +22,7 @@ export declare class SchemaGenerator {
|
|
|
22
22
|
*/
|
|
23
23
|
static generateModelSections(model: OpModelType<any>, configService: IDbConfigHandler): Promise<string>;
|
|
24
24
|
private static getSuperFieldFromModel;
|
|
25
|
+
private static getPrismaExec;
|
|
25
26
|
/**
|
|
26
27
|
* Install Prisma with the generated schema
|
|
27
28
|
* @param configService The configuration service
|
|
@@ -7,6 +7,7 @@ exports.SchemaGenerator = void 0;
|
|
|
7
7
|
const console_1 = require("@rws-framework/console");
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const _model_1 = require("../../models/_model");
|
|
11
12
|
const utils_1 = require("./utils");
|
|
12
13
|
const type_converter_1 = require("./type-converter");
|
|
@@ -274,6 +275,9 @@ datasource db {
|
|
|
274
275
|
}
|
|
275
276
|
return superFieldElemName;
|
|
276
277
|
}
|
|
278
|
+
static getPrismaExec() {
|
|
279
|
+
return path_1.default.join(console_1.rwsPath.findRootWorkspacePath(), 'node_modules', 'prisma/build/index.js');
|
|
280
|
+
}
|
|
277
281
|
/**
|
|
278
282
|
* Install Prisma with the generated schema
|
|
279
283
|
* @param configService The configuration service
|
|
@@ -324,8 +328,20 @@ datasource db {
|
|
|
324
328
|
fs_1.default.unlinkSync(schemaPath);
|
|
325
329
|
}
|
|
326
330
|
fs_1.default.writeFileSync(schemaPath, template);
|
|
327
|
-
if (_EXECUTE_PRISMA_CMD)
|
|
328
|
-
|
|
331
|
+
if (_EXECUTE_PRISMA_CMD) {
|
|
332
|
+
const prismaPath = this.getPrismaExec();
|
|
333
|
+
// Set environment variables
|
|
334
|
+
const env = {
|
|
335
|
+
...process.env,
|
|
336
|
+
[this.dbUrlVarName]: configService.get('db_url')
|
|
337
|
+
};
|
|
338
|
+
// Execute prisma db push programmatically
|
|
339
|
+
(0, child_process_1.execSync)(`node ${prismaPath} generate --schema=${schemaPath}`, {
|
|
340
|
+
cwd: process.cwd(),
|
|
341
|
+
stdio: 'inherit',
|
|
342
|
+
env
|
|
343
|
+
});
|
|
344
|
+
}
|
|
329
345
|
console.log(chalk_1.default.green('[RWS Init]') + ' prisma schema generated from ', schemaPath);
|
|
330
346
|
if (_REMOVE_SCHEMA_FILE) {
|
|
331
347
|
fs_1.default.unlinkSync(schemaPath);
|
|
@@ -340,9 +356,9 @@ datasource db {
|
|
|
340
356
|
*/
|
|
341
357
|
static async pushDBModels(configService, dbService, leaveFile = false) {
|
|
342
358
|
process.env = { ...process.env, [this.dbUrlVarName]: configService.get('db_url') };
|
|
343
|
-
console.log({ env: process.env.PRISMA_DB_URL });
|
|
344
359
|
const [_, schemaPath] = utils_1.DbUtils.getProcessedSchemaDir();
|
|
345
|
-
const prismaPath =
|
|
360
|
+
const prismaPath = this.getPrismaExec();
|
|
361
|
+
console.log({ prismaPath });
|
|
346
362
|
// Set environment variables
|
|
347
363
|
const env = {
|
|
348
364
|
...process.env,
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rwsShell } from '@rws-framework/console';
|
|
1
|
+
import { rwsPath, rwsShell } from '@rws-framework/console';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
@@ -355,6 +355,10 @@ datasource db {
|
|
|
355
355
|
return superFieldElemName;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
+
private static getPrismaExec(): string {
|
|
359
|
+
return path.join(rwsPath.findRootWorkspacePath(), 'node_modules', 'prisma/build/index.js');
|
|
360
|
+
}
|
|
361
|
+
|
|
358
362
|
/**
|
|
359
363
|
* Install Prisma with the generated schema
|
|
360
364
|
* @param configService The configuration service
|
|
@@ -424,9 +428,22 @@ datasource db {
|
|
|
424
428
|
|
|
425
429
|
fs.writeFileSync(schemaPath, template);
|
|
426
430
|
|
|
427
|
-
if(_EXECUTE_PRISMA_CMD)
|
|
428
|
-
|
|
429
|
-
|
|
431
|
+
if(_EXECUTE_PRISMA_CMD){
|
|
432
|
+
const prismaPath = this.getPrismaExec();
|
|
433
|
+
|
|
434
|
+
// Set environment variables
|
|
435
|
+
const env = {
|
|
436
|
+
...process.env,
|
|
437
|
+
[this.dbUrlVarName]: configService.get('db_url')
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// Execute prisma db push programmatically
|
|
441
|
+
execSync(`node ${prismaPath} generate --schema=${schemaPath}`, {
|
|
442
|
+
cwd: process.cwd(),
|
|
443
|
+
stdio: 'inherit',
|
|
444
|
+
env
|
|
445
|
+
});
|
|
446
|
+
}
|
|
430
447
|
|
|
431
448
|
console.log(chalk.green('[RWS Init]') + ' prisma schema generated from ', schemaPath);
|
|
432
449
|
|
|
@@ -445,11 +462,11 @@ datasource db {
|
|
|
445
462
|
static async pushDBModels(configService: IDbConfigHandler, dbService: DBService, leaveFile = false): Promise<void> {
|
|
446
463
|
process.env = { ...process.env, [this.dbUrlVarName]: configService.get('db_url') };
|
|
447
464
|
|
|
448
|
-
console.log({ env: process.env.PRISMA_DB_URL });
|
|
449
|
-
|
|
450
465
|
const [_, schemaPath] = DbUtils.getProcessedSchemaDir();
|
|
451
466
|
|
|
452
|
-
|
|
467
|
+
const prismaPath = this.getPrismaExec();
|
|
468
|
+
|
|
469
|
+
console.log({prismaPath});
|
|
453
470
|
|
|
454
471
|
// Set environment variables
|
|
455
472
|
const env = {
|