@memberjunction/codegen-lib 2.7.1 → 2.8.0
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/Angular/angular-codegen.js +3 -3
- package/dist/Angular/angular-codegen.js.map +1 -1
- package/dist/Config/config.d.ts +7 -7
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +2 -2
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/dbSchema.js +2 -2
- package/dist/Database/dbSchema.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +1 -9
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +95 -164
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/sql.js +5 -5
- package/dist/Database/sql.js.map +1 -1
- package/dist/Database/sql_codegen.js +25 -25
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Misc/action_subclasses_codegen.d.ts.map +1 -0
- package/dist/{action_subclasses_codegen.js → Misc/action_subclasses_codegen.js} +3 -3
- package/dist/Misc/action_subclasses_codegen.js.map +1 -0
- package/dist/Misc/createNewUser.js +6 -6
- package/dist/Misc/createNewUser.js.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -0
- package/dist/{entity_subclasses_codegen.js → Misc/entity_subclasses_codegen.js} +4 -4
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -0
- package/dist/Misc/graphql_server_codegen.d.ts.map +1 -0
- package/dist/{graphql_server_codegen.js → Misc/graphql_server_codegen.js} +10 -10
- package/dist/Misc/graphql_server_codegen.js.map +1 -0
- package/dist/Misc/runCommand.js +10 -10
- package/dist/Misc/runCommand.js.map +1 -1
- package/dist/Misc/sql_logging.d.ts +21 -0
- package/dist/Misc/sql_logging.d.ts.map +1 -0
- package/dist/Misc/sql_logging.js +128 -0
- package/dist/Misc/sql_logging.js.map +1 -0
- package/dist/Misc/{logging.d.ts → status_logging.d.ts} +1 -1
- package/dist/Misc/status_logging.d.ts.map +1 -0
- package/dist/Misc/{logging.js → status_logging.js} +1 -1
- package/dist/Misc/status_logging.js.map +1 -0
- package/dist/Misc/util.js +2 -2
- package/dist/Misc/util.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/runCodeGen.d.ts.map +1 -1
- package/dist/runCodeGen.js +54 -52
- package/dist/runCodeGen.js.map +1 -1
- package/package.json +7 -7
- package/dist/Misc/logging.d.ts.map +0 -1
- package/dist/Misc/logging.js.map +0 -1
- package/dist/action_subclasses_codegen.d.ts.map +0 -1
- package/dist/action_subclasses_codegen.js.map +0 -1
- package/dist/entity_subclasses_codegen.d.ts.map +0 -1
- package/dist/entity_subclasses_codegen.js.map +0 -1
- package/dist/graphql_server_codegen.d.ts.map +0 -1
- package/dist/graphql_server_codegen.js.map +0 -1
- /package/dist/{action_subclasses_codegen.d.ts → Misc/action_subclasses_codegen.d.ts} +0 -0
- /package/dist/{entity_subclasses_codegen.d.ts → Misc/entity_subclasses_codegen.d.ts} +0 -0
- /package/dist/{graphql_server_codegen.d.ts → Misc/graphql_server_codegen.d.ts} +0 -0
|
@@ -36,12 +36,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.ManageMetadataBase = void 0;
|
|
37
37
|
const config_1 = require("../Config/config");
|
|
38
38
|
const core_1 = require("@memberjunction/core");
|
|
39
|
-
const
|
|
39
|
+
const status_logging_1 = require("../Misc/status_logging");
|
|
40
40
|
const sql_1 = require("./sql");
|
|
41
41
|
const advanced_generation_1 = require("../Misc/advanced_generation");
|
|
42
42
|
const global_1 = require("@memberjunction/global");
|
|
43
43
|
const fs = __importStar(require("fs"));
|
|
44
44
|
const path_1 = __importDefault(require("path"));
|
|
45
|
+
const sql_logging_1 = require("../Misc/sql_logging");
|
|
45
46
|
/**
|
|
46
47
|
* Base class for managing metadata within the CodeGen system. This class can be sub-classed to extend/override base class functionality. Make sure to use the RegisterClass decorator from the @memberjunction/global package
|
|
47
48
|
* to properly register your subclass with a priority of 1+ to ensure it gets instantiated.
|
|
@@ -56,73 +57,6 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
56
57
|
static get newEntityList() {
|
|
57
58
|
return this._newEntityList;
|
|
58
59
|
}
|
|
59
|
-
async manageMetaDataLogging(config) {
|
|
60
|
-
if (!config) {
|
|
61
|
-
(0, logging_1.logError)("MetadataLoggingConfig is required to enable metadata logging");
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (!config.folderPath && !config.filePath) {
|
|
65
|
-
(0, logging_1.logError)("Either folderPath or filePath is required to enable metadata logging");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (config.folderPath) {
|
|
69
|
-
const dirExists = fs.existsSync(config.folderPath);
|
|
70
|
-
if (!dirExists) {
|
|
71
|
-
fs.mkdirSync(config.folderPath, { recursive: true });
|
|
72
|
-
}
|
|
73
|
-
const fileName = this.createFileName();
|
|
74
|
-
this.FilePath = path_1.default.join(config.folderPath, `${fileName}.sql`);
|
|
75
|
-
//create an empty file
|
|
76
|
-
fs.writeFileSync(this.FilePath, '');
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this.FilePath = config.filePath;
|
|
80
|
-
if (this.FilePath && config.overwriteFile) {
|
|
81
|
-
//append to the file
|
|
82
|
-
fs.writeFileSync(this.FilePath, '');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
this.Config = config;
|
|
86
|
-
(0, core_1.LogStatus)(`Metadata logging enabled. File path: ${this.FilePath}`);
|
|
87
|
-
}
|
|
88
|
-
createFileName() {
|
|
89
|
-
const date = new Date();
|
|
90
|
-
const year = date.getUTCFullYear();
|
|
91
|
-
const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // Month is 0-based
|
|
92
|
-
const day = String(date.getUTCDate()).padStart(2, '0');
|
|
93
|
-
const hour = String(date.getUTCHours()).padStart(2, '0');
|
|
94
|
-
const minute = String(date.getUTCMinutes()).padStart(2, '0');
|
|
95
|
-
const second = String(date.getUTCSeconds()).padStart(2, '0');
|
|
96
|
-
const fileName = `CodeGen_Run_${year}-${month}-${day}_${hour}-${minute}-${second}`;
|
|
97
|
-
return fileName;
|
|
98
|
-
}
|
|
99
|
-
async appendToFile(contents, description) {
|
|
100
|
-
try {
|
|
101
|
-
if (!contents || !this.FilePath) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (description) {
|
|
105
|
-
const comment = `/* ${description} */\n`;
|
|
106
|
-
contents = `${comment}${contents}`;
|
|
107
|
-
}
|
|
108
|
-
contents = `${contents}\n\n`;
|
|
109
|
-
fs.appendFileSync(this.FilePath, contents);
|
|
110
|
-
}
|
|
111
|
-
catch (ex) {
|
|
112
|
-
(0, logging_1.logError)("Unable to log metadata SQL text to file", ex);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
convertCoreSchemaToFlywaySchema() {
|
|
116
|
-
if (!this.FilePath) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const coreSchema = (0, config_1.mj_core_schema)();
|
|
120
|
-
const regex = new RegExp(coreSchema, 'g');
|
|
121
|
-
const data = fs.readFileSync(`${this.FilePath}`, 'utf-8');
|
|
122
|
-
const replacedData = data.replace(regex, "${flyway:defaultSchema}");
|
|
123
|
-
fs.writeFileSync(`${this.FilePath}`, replacedData);
|
|
124
|
-
(0, logging_1.logStatus)(`Replaced all instances of ${coreSchema} with \${flyway:defaultSchema} in the metadata log file`);
|
|
125
|
-
}
|
|
126
60
|
/**
|
|
127
61
|
* Primary function to manage metadata within the CodeGen system. This function will call a series of sub-functions to manage the metadata.
|
|
128
62
|
* @param ds - the DataSource object to use for querying and updating the database
|
|
@@ -133,62 +67,59 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
133
67
|
const excludeSchemas = config_1.configInfo.excludeSchemas ? config_1.configInfo.excludeSchemas : [];
|
|
134
68
|
let bSuccess = true;
|
|
135
69
|
let start = new Date();
|
|
136
|
-
(0,
|
|
70
|
+
(0, status_logging_1.logStatus)(' Creating new entities...');
|
|
137
71
|
if (!await this.createNewEntities(ds)) {
|
|
138
|
-
(0,
|
|
72
|
+
(0, status_logging_1.logError)(' Error creating new entities');
|
|
139
73
|
bSuccess = false;
|
|
140
74
|
}
|
|
141
|
-
(0,
|
|
75
|
+
(0, status_logging_1.logStatus)(` > Created new entities in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
142
76
|
start = new Date();
|
|
143
|
-
(0,
|
|
77
|
+
(0, status_logging_1.logStatus)(' Updating existing entities...');
|
|
144
78
|
if (!await this.updateExistingEntitiesFromSchema(ds, excludeSchemas)) {
|
|
145
|
-
(0,
|
|
79
|
+
(0, status_logging_1.logError)(' Error updating existing entities');
|
|
146
80
|
bSuccess = false;
|
|
147
81
|
}
|
|
148
|
-
(0,
|
|
82
|
+
(0, status_logging_1.logStatus)(` > Updated existing entities in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
149
83
|
start = new Date();
|
|
150
|
-
(0,
|
|
84
|
+
(0, status_logging_1.logStatus)(' Scanning for tables that were deleted where entity metadata still exists...');
|
|
151
85
|
if (!await this.checkAndRemoveMetadataForDeletedTables(ds, excludeSchemas)) {
|
|
152
|
-
(0,
|
|
86
|
+
(0, status_logging_1.logError)(' Error removing metadata for tables that were removed');
|
|
153
87
|
bSuccess = false;
|
|
154
88
|
}
|
|
155
|
-
(0,
|
|
89
|
+
(0, status_logging_1.logStatus)(` > Removed metadata for deleted tables in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
156
90
|
start = new Date();
|
|
157
|
-
(0,
|
|
91
|
+
(0, status_logging_1.logStatus)(' Recompiling base views...');
|
|
158
92
|
const sqlUtility = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(sql_1.SQLUtilityBase);
|
|
159
93
|
if (!await sqlUtility.recompileAllBaseViews(ds, excludeSchemas, true)) {
|
|
160
|
-
(0,
|
|
94
|
+
(0, status_logging_1.logMessage)(' Warning: Non-Fatal error recompiling base views', core_1.SeverityType.Warning, false);
|
|
161
95
|
// many times the former versions of base views will NOT succesfully recompile, so don't consider that scenario to be a
|
|
162
96
|
// failure for this entire function
|
|
163
97
|
}
|
|
164
|
-
(0,
|
|
98
|
+
(0, status_logging_1.logStatus)(` > Recompiled base views in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
165
99
|
start = new Date();
|
|
166
|
-
(0,
|
|
100
|
+
(0, status_logging_1.logStatus)(' Managing entity fields...');
|
|
167
101
|
if (!await this.manageEntityFields(ds, excludeSchemas, false, false)) {
|
|
168
|
-
(0,
|
|
102
|
+
(0, status_logging_1.logError)(' Error managing entity fields');
|
|
169
103
|
bSuccess = false;
|
|
170
104
|
}
|
|
171
|
-
(0,
|
|
105
|
+
(0, status_logging_1.logStatus)(` > Managed entity fields in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
172
106
|
start = new Date();
|
|
173
|
-
(0,
|
|
107
|
+
(0, status_logging_1.logStatus)(' Managing entity relationships...');
|
|
174
108
|
if (!await this.manageEntityRelationships(ds, excludeSchemas, md)) {
|
|
175
|
-
(0,
|
|
109
|
+
(0, status_logging_1.logError)(' Error managing entity relationships');
|
|
176
110
|
bSuccess = false;
|
|
177
111
|
}
|
|
178
|
-
(0,
|
|
112
|
+
(0, status_logging_1.logStatus)(` > Managed entity relationships in ${(new Date().getTime() - start.getTime()) / 1000} seconds`);
|
|
179
113
|
if (ManageMetadataBase_1.newEntityList.length > 0) {
|
|
180
114
|
await this.generateNewEntityDescriptions(ds, md); // don't pass excludeSchemas becuase by definition this is the NEW entities we created
|
|
181
115
|
}
|
|
182
116
|
const veResult = await this.manageVirtualEntities(ds);
|
|
183
117
|
if (!veResult.success) {
|
|
184
|
-
(0,
|
|
118
|
+
(0, status_logging_1.logError)(' Error managing virtual entities');
|
|
185
119
|
bSuccess = false;
|
|
186
120
|
}
|
|
187
121
|
// now - we need to tell our metadata object to refresh itself
|
|
188
122
|
await md.Refresh();
|
|
189
|
-
if (this.Config && this.Config.convertCoreSchemaToFlywaySchema) {
|
|
190
|
-
this.convertCoreSchemaToFlywaySchema();
|
|
191
|
-
}
|
|
192
123
|
return bSuccess;
|
|
193
124
|
}
|
|
194
125
|
async manageVirtualEntities(ds) {
|
|
@@ -205,7 +136,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
205
136
|
const { success, updatedEntity } = await this.manageSingleVirtualEntity(ds, ve);
|
|
206
137
|
anyUpdates = anyUpdates || updatedEntity;
|
|
207
138
|
if (!success) {
|
|
208
|
-
(0,
|
|
139
|
+
(0, status_logging_1.logError)(` Error managing virtual entity ${ve.Name}`);
|
|
209
140
|
bSuccess = false;
|
|
210
141
|
}
|
|
211
142
|
}
|
|
@@ -246,7 +177,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
246
177
|
if (removeList.length > 0) {
|
|
247
178
|
const sqlRemove = `DELETE FROM [${(0, config_1.mj_core_schema)()}].EntityField WHERE ID IN (${removeList.map(removeId => `'${removeId}'`).join(',')})`;
|
|
248
179
|
// this removes the fields that shouldn't be there anymore
|
|
249
|
-
this.
|
|
180
|
+
this.LogSQLAndExecute(ds, sqlRemove, `SQL text to remove fields from entity ${virtualEntity.Name}`);
|
|
250
181
|
bUpdated = true;
|
|
251
182
|
}
|
|
252
183
|
// check to see if any of the fields in the virtual entity have Pkey attribute set. If not, we will default to the first field
|
|
@@ -258,7 +189,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
258
189
|
const { success, updatedField } = await this.manageSingleVirtualEntityField(ds, virtualEntity, vef, i + 1, !hasPkey && i === 0);
|
|
259
190
|
bUpdated = bUpdated || updatedField;
|
|
260
191
|
if (!success) {
|
|
261
|
-
(0,
|
|
192
|
+
(0, status_logging_1.logError)(`Error managing virtual entity field ${vef.FieldName} for virtual entity ${virtualEntity.Name}`);
|
|
262
193
|
bSuccess = false;
|
|
263
194
|
}
|
|
264
195
|
}
|
|
@@ -267,12 +198,12 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
267
198
|
if (bUpdated) {
|
|
268
199
|
// finally make sure we update the UpdatedAt field for the entity if we made changes to its fields
|
|
269
200
|
const sqlUpdate = `UPDATE [${(0, config_1.mj_core_schema)()}].Entity SET [${core_1.EntityInfo.UpdatedAtFieldName}]=GETUTCDATE() WHERE ID='${virtualEntity.ID}'`;
|
|
270
|
-
await
|
|
201
|
+
await this.LogSQLAndExecute(ds, sqlUpdate, `SQL text to update virtual entity updated date for ${virtualEntity.Name}`);
|
|
271
202
|
}
|
|
272
203
|
return { success: bSuccess, updatedEntity: bUpdated };
|
|
273
204
|
}
|
|
274
205
|
catch (e) {
|
|
275
|
-
(0,
|
|
206
|
+
(0, status_logging_1.logError)(e);
|
|
276
207
|
return { success: false, updatedEntity: bUpdated };
|
|
277
208
|
}
|
|
278
209
|
}
|
|
@@ -307,7 +238,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
307
238
|
Scale=${veField.Scale}
|
|
308
239
|
WHERE
|
|
309
240
|
ID = '${field.ID}'`; // don't need to update the __mj_UpdatedAt field here, that happens automatically via the trigger
|
|
310
|
-
await this.
|
|
241
|
+
await this.LogSQLAndExecute(ds, sqlUpdate, `SQL text to update virtual entity field ${veField.FieldName} for entity ${virtualEntity.Name}`);
|
|
311
242
|
didUpdate = true;
|
|
312
243
|
}
|
|
313
244
|
}
|
|
@@ -321,7 +252,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
321
252
|
${veField.Length}, ${veField.Precision}, ${veField.Scale},
|
|
322
253
|
${fieldSequence}, ${makePrimaryKey ? 1 : 0}, ${makePrimaryKey ? 1 : 0}
|
|
323
254
|
)`;
|
|
324
|
-
await this.
|
|
255
|
+
await this.LogSQLAndExecute(ds, sqlAdd, `SQL text to add virtual entity field ${veField.FieldName} for entity ${virtualEntity.Name}`);
|
|
325
256
|
didUpdate = true;
|
|
326
257
|
}
|
|
327
258
|
}
|
|
@@ -400,7 +331,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
400
331
|
}
|
|
401
332
|
});
|
|
402
333
|
if (batchSQL.length > 0) {
|
|
403
|
-
await this.
|
|
334
|
+
await this.LogSQLAndExecute(ds, batchSQL, `SQL text to create Entitiy Relationships`);
|
|
404
335
|
}
|
|
405
336
|
};
|
|
406
337
|
// Split entityFields into batches and process each batch
|
|
@@ -411,7 +342,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
411
342
|
return true;
|
|
412
343
|
}
|
|
413
344
|
catch (e) {
|
|
414
|
-
(0,
|
|
345
|
+
(0, status_logging_1.logError)(e);
|
|
415
346
|
return false;
|
|
416
347
|
}
|
|
417
348
|
}
|
|
@@ -432,8 +363,8 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
432
363
|
// for the admin to handle manually
|
|
433
364
|
try {
|
|
434
365
|
const sqlDelete = `__mj.spDeleteEntityWithCoreDependencies @EntityID='${e.ID}'`;
|
|
435
|
-
await
|
|
436
|
-
(0,
|
|
366
|
+
await this.LogSQLAndExecute(ds, sqlDelete, `SQL text to remove entity ${e.Name}`);
|
|
367
|
+
(0, status_logging_1.logStatus)(` > Removed metadata for table ${e.SchemaName}.${e.BaseTable}`);
|
|
437
368
|
// next up we need to remove the spCreate, spDelete, spUpdate, BaseView, and FullTextSearchFunction, if provided.
|
|
438
369
|
// We only remoe these artifcacts when they are generated which is info we have in the BaseViewGenerated, spCreateGenerated, etc. fields
|
|
439
370
|
await this.checkDropSQLObject(ds, e.BaseViewGenerated, 'view', e.SchemaName, e.BaseView);
|
|
@@ -443,7 +374,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
443
374
|
await this.checkDropSQLObject(ds, e.FullTextSearchFunctionGenerated, 'function', e.SchemaName, e.FullTextSearchFunction);
|
|
444
375
|
}
|
|
445
376
|
catch (ex) {
|
|
446
|
-
(0,
|
|
377
|
+
(0, status_logging_1.logError)(`Error removing metadata for entity ${ex.Name}, error: ${ex}`);
|
|
447
378
|
}
|
|
448
379
|
}
|
|
449
380
|
// if we get here we now need to refresh our metadata object
|
|
@@ -453,7 +384,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
453
384
|
return true;
|
|
454
385
|
}
|
|
455
386
|
catch (e) {
|
|
456
|
-
(0,
|
|
387
|
+
(0, status_logging_1.logError)(e);
|
|
457
388
|
return false;
|
|
458
389
|
}
|
|
459
390
|
}
|
|
@@ -461,7 +392,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
461
392
|
try {
|
|
462
393
|
if (proceed && schemaName && name && schemaName.trim().length > 0 && name.trim().length > 0) {
|
|
463
394
|
const sqlDelete = `DROP ${type} IF EXISTS [${schemaName}].[${name}]`;
|
|
464
|
-
await
|
|
395
|
+
await this.LogSQLAndExecute(ds, sqlDelete, `SQL text to remove ${type} ${schemaName}.${name}`);
|
|
465
396
|
// next up, we need to clean up the cache of saved DB objects that may exist for this entity in the appropriate sub-directory.
|
|
466
397
|
const sqlOutputDir = (0, config_1.outputDir)('SQL', true);
|
|
467
398
|
if (sqlOutputDir) {
|
|
@@ -475,11 +406,11 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
475
406
|
if (fs.existsSync(filePathPermissions))
|
|
476
407
|
fs.unlinkSync(filePathPermissions);
|
|
477
408
|
}
|
|
478
|
-
(0,
|
|
409
|
+
(0, status_logging_1.logStatus)(` > Removed ${type} ${schemaName}.${name}`);
|
|
479
410
|
}
|
|
480
411
|
}
|
|
481
412
|
catch (e) {
|
|
482
|
-
(0,
|
|
413
|
+
(0, status_logging_1.logError)(` > Error removing ${type} ${schemaName}.${name}, error: ${e}`);
|
|
483
414
|
}
|
|
484
415
|
}
|
|
485
416
|
/**
|
|
@@ -505,51 +436,51 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
505
436
|
if (!skipCreatedAtUpdatedAtDeletedAtFieldValidation) {
|
|
506
437
|
if (!await this.ensureCreatedAtUpdatedAtFieldsExist(ds, excludeSchemas) ||
|
|
507
438
|
!await this.ensureDeletedAtFieldsExist(ds, excludeSchemas)) {
|
|
508
|
-
(0,
|
|
439
|
+
(0, status_logging_1.logError)(`Error ensuring ${core_1.EntityInfo.CreatedAtFieldName}, ${core_1.EntityInfo.UpdatedAtFieldName} and ${core_1.EntityInfo.DeletedAtFieldName} fields exist`);
|
|
509
440
|
bSuccess = false;
|
|
510
441
|
}
|
|
511
|
-
(0,
|
|
442
|
+
(0, status_logging_1.logStatus)(` Ensured ${core_1.EntityInfo.CreatedAtFieldName}/${core_1.EntityInfo.UpdatedAtFieldName}/${core_1.EntityInfo.DeletedAtFieldName} fields exist in ${(new Date().getTime() - startTime.getTime()) / 1000} seconds`);
|
|
512
443
|
}
|
|
513
444
|
const step1StartTime = new Date();
|
|
514
445
|
if (!await this.deleteUnneededEntityFields(ds, excludeSchemas)) {
|
|
515
|
-
(0,
|
|
446
|
+
(0, status_logging_1.logError)('Error deleting unneeded entity fields');
|
|
516
447
|
bSuccess = false;
|
|
517
448
|
}
|
|
518
|
-
(0,
|
|
449
|
+
(0, status_logging_1.logStatus)(` Deleted unneeded entity fields in ${(new Date().getTime() - step1StartTime.getTime()) / 1000} seconds`);
|
|
519
450
|
const step2StartTime = new Date();
|
|
520
451
|
if (!await this.updateExistingEntityFieldsFromSchema(ds, excludeSchemas)) {
|
|
521
|
-
(0,
|
|
452
|
+
(0, status_logging_1.logError)('Error updating existing entity fields from schema');
|
|
522
453
|
bSuccess = false;
|
|
523
454
|
}
|
|
524
|
-
(0,
|
|
455
|
+
(0, status_logging_1.logStatus)(` Updated existing entity fields from schema in ${(new Date().getTime() - step2StartTime.getTime()) / 1000} seconds`);
|
|
525
456
|
const step3StartTime = new Date();
|
|
526
457
|
if (!await this.createNewEntityFieldsFromSchema(ds)) { // has its own internal filtering for exclude schema/table so don't pass in
|
|
527
|
-
(0,
|
|
458
|
+
(0, status_logging_1.logError)('Error creating new entity fields from schema');
|
|
528
459
|
bSuccess = false;
|
|
529
460
|
}
|
|
530
|
-
(0,
|
|
461
|
+
(0, status_logging_1.logStatus)(` Created new entity fields from schema in ${(new Date().getTime() - step3StartTime.getTime()) / 1000} seconds`);
|
|
531
462
|
const step4StartTime = new Date();
|
|
532
463
|
if (!await this.setDefaultColumnWidthWhereNeeded(ds, excludeSchemas)) {
|
|
533
|
-
(0,
|
|
464
|
+
(0, status_logging_1.logError)('Error setting default column width where needed');
|
|
534
465
|
bSuccess = false;
|
|
535
466
|
}
|
|
536
|
-
(0,
|
|
467
|
+
(0, status_logging_1.logStatus)(` Set default column width where needed in ${(new Date().getTime() - step4StartTime.getTime()) / 1000} seconds`);
|
|
537
468
|
const step5StartTime = new Date();
|
|
538
469
|
if (!await this.updateEntityFieldDisplayNameWhereNull(ds, excludeSchemas)) {
|
|
539
|
-
(0,
|
|
470
|
+
(0, status_logging_1.logError)('Error updating entity field display name where null');
|
|
540
471
|
bSuccess = false;
|
|
541
472
|
}
|
|
542
|
-
(0,
|
|
473
|
+
(0, status_logging_1.logStatus)(` Updated entity field display name where null in ${(new Date().getTime() - step5StartTime.getTime()) / 1000} seconds`);
|
|
543
474
|
if (!skipEntityFieldValues) {
|
|
544
475
|
const step6StartTime = new Date();
|
|
545
|
-
(0,
|
|
476
|
+
(0, status_logging_1.logStatus)(` Starting to manage entity field values...`);
|
|
546
477
|
if (!await this.manageEntityFieldValues(ds, excludeSchemas)) {
|
|
547
|
-
(0,
|
|
478
|
+
(0, status_logging_1.logError)('Error managing entity field values');
|
|
548
479
|
bSuccess = false;
|
|
549
480
|
}
|
|
550
|
-
(0,
|
|
481
|
+
(0, status_logging_1.logStatus)(` Managed entity field values in ${(new Date().getTime() - step6StartTime.getTime()) / 1000} seconds`);
|
|
551
482
|
}
|
|
552
|
-
(0,
|
|
483
|
+
(0, status_logging_1.logStatus)(` Total time to manage entity fields: ${(new Date().getTime() - startTime.getTime()) / 1000} seconds`);
|
|
553
484
|
return bSuccess;
|
|
554
485
|
}
|
|
555
486
|
/**
|
|
@@ -587,7 +518,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
587
518
|
return overallResult;
|
|
588
519
|
}
|
|
589
520
|
catch (e) {
|
|
590
|
-
(0,
|
|
521
|
+
(0, status_logging_1.logError)(e);
|
|
591
522
|
return false;
|
|
592
523
|
}
|
|
593
524
|
}
|
|
@@ -633,7 +564,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
633
564
|
return overallResult;
|
|
634
565
|
}
|
|
635
566
|
catch (e) {
|
|
636
|
-
(0,
|
|
567
|
+
(0, status_logging_1.logError)(e);
|
|
637
568
|
return false;
|
|
638
569
|
}
|
|
639
570
|
}
|
|
@@ -649,7 +580,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
649
580
|
if (!currentFieldData) {
|
|
650
581
|
// field doesn't exist, let's create it
|
|
651
582
|
const sql = `ALTER TABLE [${entity.SchemaName}].[${entity.BaseTable}] ADD ${fieldName} DATETIMEOFFSET ${allowNull ? 'NULL' : 'NOT NULL DEFAULT GETUTCDATE()'}`;
|
|
652
|
-
await this.
|
|
583
|
+
await this.LogSQLAndExecute(ds, sql, `SQL text to add special date field ${fieldName} to entity ${entity.SchemaName}.${entity.BaseTable}`);
|
|
653
584
|
}
|
|
654
585
|
else {
|
|
655
586
|
// field does exist, let's first check the data type/nullability
|
|
@@ -660,7 +591,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
660
591
|
// modifying the column, and finally adding the default constraint back in.
|
|
661
592
|
await this.dropExistingDefaultConstraint(ds, entity, fieldName);
|
|
662
593
|
const sql = `ALTER TABLE [${entity.SchemaName}].[${entity.BaseTable}] ALTER COLUMN ${fieldName} DATETIMEOFFSET ${allowNull ? 'NULL' : 'NOT NULL'}`;
|
|
663
|
-
await this.
|
|
594
|
+
await this.LogSQLAndExecute(ds, sql, `SQL text to update special date field ${fieldName} in entity ${entity.SchemaName}.${entity.BaseTable}`);
|
|
664
595
|
if (!allowNull)
|
|
665
596
|
await this.createDefaultConstraintForSpecialDateField(ds, entity, fieldName);
|
|
666
597
|
}
|
|
@@ -680,7 +611,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
680
611
|
return true;
|
|
681
612
|
}
|
|
682
613
|
catch (e) {
|
|
683
|
-
(0,
|
|
614
|
+
(0, status_logging_1.logError)(e);
|
|
684
615
|
return false;
|
|
685
616
|
}
|
|
686
617
|
}
|
|
@@ -690,10 +621,10 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
690
621
|
async createDefaultConstraintForSpecialDateField(ds, entity, fieldName) {
|
|
691
622
|
try {
|
|
692
623
|
const sqlAddDefaultConstraint = `ALTER TABLE [${entity.SchemaName}].[${entity.BaseTable}] ADD CONSTRAINT DF_${entity.SchemaName}_${(0, core_1.CodeNameFromString)(entity.BaseTable)}_${fieldName} DEFAULT GETUTCDATE() FOR [${fieldName}]`;
|
|
693
|
-
await this.
|
|
624
|
+
await this.LogSQLAndExecute(ds, sqlAddDefaultConstraint, `SQL text to add default constraint for special date field ${fieldName} in entity ${entity.SchemaName}.${entity.BaseTable}`);
|
|
694
625
|
}
|
|
695
626
|
catch (e) {
|
|
696
|
-
(0,
|
|
627
|
+
(0, status_logging_1.logError)(e);
|
|
697
628
|
}
|
|
698
629
|
}
|
|
699
630
|
/**
|
|
@@ -734,10 +665,10 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
734
665
|
EXEC('ALTER TABLE [${entity.SchemaName}].[${entity.BaseTable}] DROP CONSTRAINT ' + @constraintName);
|
|
735
666
|
END
|
|
736
667
|
`;
|
|
737
|
-
this.
|
|
668
|
+
this.LogSQLAndExecute(ds, sqlDropDefaultConstraint, `SQL text to drop default existing default constraints in entity ${entity.SchemaName}.${entity.BaseTable}`);
|
|
738
669
|
}
|
|
739
670
|
catch (e) {
|
|
740
|
-
(0,
|
|
671
|
+
(0, status_logging_1.logError)(e);
|
|
741
672
|
}
|
|
742
673
|
}
|
|
743
674
|
/**
|
|
@@ -782,8 +713,8 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
782
713
|
try {
|
|
783
714
|
const structuredResult = JSON.parse(resultText);
|
|
784
715
|
if (structuredResult?.entityDescription && structuredResult.entityDescription.length > 0) {
|
|
785
|
-
const
|
|
786
|
-
await this.
|
|
716
|
+
const sSQL = `UPDATE [${(0, config_1.mj_core_schema)()}].Entity SET Description = '${structuredResult.entityDescription}' WHERE Name = '${e}'`;
|
|
717
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update entity description for entity ${e}`);
|
|
787
718
|
}
|
|
788
719
|
else {
|
|
789
720
|
console.warn(' >>> Advanced Generation Error: LLM returned a blank entity description, skipping entity description for entity ' + e);
|
|
@@ -829,13 +760,13 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
829
760
|
const sDisplayName = this.stripTrailingChars(this.convertCamelCaseToHaveSpaces(field.Name), 'ID', true).trim();
|
|
830
761
|
if (sDisplayName.length > 0 && sDisplayName.toLowerCase().trim() !== field.Name.toLowerCase().trim()) {
|
|
831
762
|
const sSQL = `UPDATE [${(0, config_1.mj_core_schema)()}].EntityField SET ${core_1.EntityInfo.UpdatedAtFieldName}=GETUTCDATE(), DisplayName = '${sDisplayName}' WHERE ID = '${field.ID}'`;
|
|
832
|
-
await this.
|
|
763
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update display name for field ${field.Name}`);
|
|
833
764
|
}
|
|
834
765
|
}
|
|
835
766
|
return true;
|
|
836
767
|
}
|
|
837
768
|
catch (e) {
|
|
838
|
-
(0,
|
|
769
|
+
(0, status_logging_1.logError)(e);
|
|
839
770
|
return false;
|
|
840
771
|
}
|
|
841
772
|
}
|
|
@@ -849,11 +780,12 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
849
780
|
*/
|
|
850
781
|
async setDefaultColumnWidthWhereNeeded(ds, excludeSchemas) {
|
|
851
782
|
try {
|
|
852
|
-
|
|
783
|
+
const sSQL = `EXEC ${(0, config_1.mj_core_schema)()}.spSetDefaultColumnWidthWhereNeeded @ExcludedSchemaNames='${excludeSchemas.join(',')}'`;
|
|
784
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to set default column width where needed`);
|
|
853
785
|
return true;
|
|
854
786
|
}
|
|
855
787
|
catch (e) {
|
|
856
|
-
(0,
|
|
788
|
+
(0, status_logging_1.logError)(e);
|
|
857
789
|
return false;
|
|
858
790
|
}
|
|
859
791
|
}
|
|
@@ -1051,7 +983,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1051
983
|
// need to check for null entity id = that is because the above query can return candidate Entity Fields but the entities may not have been created if the entities
|
|
1052
984
|
// that would have been created violate rules - such as not having an ID column, etc.
|
|
1053
985
|
const sSQLInsert = this.getPendingEntityFieldINSERTSQL(n);
|
|
1054
|
-
await this.
|
|
986
|
+
await this.LogSQLAndExecute(ds, sSQLInsert, `SQL text to insert new entity field`);
|
|
1055
987
|
// if we get here, we're okay, otherwise we have an exception, which we want as it blows up transaction
|
|
1056
988
|
}
|
|
1057
989
|
}
|
|
@@ -1059,7 +991,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1059
991
|
return true;
|
|
1060
992
|
}
|
|
1061
993
|
catch (e) {
|
|
1062
|
-
(0,
|
|
994
|
+
(0, status_logging_1.logError)(e);
|
|
1063
995
|
return false;
|
|
1064
996
|
}
|
|
1065
997
|
}
|
|
@@ -1075,41 +1007,44 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1075
1007
|
const sSQL = `EXEC [${(0, config_1.mj_core_schema)()}].spUpdateEntityFieldRelatedEntityNameFieldMap
|
|
1076
1008
|
@EntityFieldID='${entityFieldID}',
|
|
1077
1009
|
@RelatedEntityNameFieldMap='${relatedEntityNameFieldMap}'`;
|
|
1078
|
-
await
|
|
1010
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update entity field related entity name field map for entity field ID ${entityFieldID}`);
|
|
1079
1011
|
return true;
|
|
1080
1012
|
}
|
|
1081
1013
|
catch (e) {
|
|
1082
|
-
(0,
|
|
1014
|
+
(0, status_logging_1.logError)(e);
|
|
1083
1015
|
return false;
|
|
1084
1016
|
}
|
|
1085
1017
|
}
|
|
1086
1018
|
async updateExistingEntitiesFromSchema(ds, excludeSchemas) {
|
|
1087
1019
|
try {
|
|
1088
|
-
|
|
1020
|
+
const sSQL = `EXEC [${(0, config_1.mj_core_schema)()}].spUpdateExistingEntitiesFromSchema @ExcludedSchemaNames='${excludeSchemas.join(',')}'`;
|
|
1021
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update existing entities from schema`);
|
|
1089
1022
|
return true;
|
|
1090
1023
|
}
|
|
1091
1024
|
catch (e) {
|
|
1092
|
-
(0,
|
|
1025
|
+
(0, status_logging_1.logError)(e);
|
|
1093
1026
|
return false;
|
|
1094
1027
|
}
|
|
1095
1028
|
}
|
|
1096
1029
|
async updateExistingEntityFieldsFromSchema(ds, excludeSchemas) {
|
|
1097
1030
|
try {
|
|
1098
|
-
|
|
1031
|
+
const sSQL = `EXEC [${(0, config_1.mj_core_schema)()}].spUpdateExistingEntityFieldsFromSchema @ExcludedSchemaNames='${excludeSchemas.join(',')}'`;
|
|
1032
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update existingg entity fields from schema`);
|
|
1099
1033
|
return true;
|
|
1100
1034
|
}
|
|
1101
1035
|
catch (e) {
|
|
1102
|
-
(0,
|
|
1036
|
+
(0, status_logging_1.logError)(e);
|
|
1103
1037
|
return false;
|
|
1104
1038
|
}
|
|
1105
1039
|
}
|
|
1106
1040
|
async deleteUnneededEntityFields(ds, excludeSchemas) {
|
|
1107
1041
|
try {
|
|
1108
|
-
|
|
1042
|
+
const sSQL = `EXEC [${(0, config_1.mj_core_schema)()}].spDeleteUnneededEntityFields @ExcludedSchemaNames='${excludeSchemas.join(',')}'`;
|
|
1043
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to delete unneeded entity fields`);
|
|
1109
1044
|
return true;
|
|
1110
1045
|
}
|
|
1111
1046
|
catch (e) {
|
|
1112
|
-
(0,
|
|
1047
|
+
(0, status_logging_1.logError)(e);
|
|
1113
1048
|
return false;
|
|
1114
1049
|
}
|
|
1115
1050
|
}
|
|
@@ -1135,14 +1070,14 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1135
1070
|
await this.syncEntityFieldValues(ds, r.EntityFieldID, parsedValues, allEntityFieldValues);
|
|
1136
1071
|
// finally, make sure the ValueListType column within the EntityField table is set to "List" because for check constraints we only allow the values specified in the list.
|
|
1137
1072
|
const sSQL = `UPDATE [${(0, config_1.mj_core_schema)()}].EntityField SET ValueListType='List' WHERE ID='${r.EntityFieldID}'`;
|
|
1138
|
-
await this.
|
|
1073
|
+
await this.LogSQLAndExecute(ds, sSQL, `SQL text to update ValueListType for entity field ID ${r.EntityFieldID}`);
|
|
1139
1074
|
}
|
|
1140
1075
|
}
|
|
1141
1076
|
}
|
|
1142
1077
|
return true;
|
|
1143
1078
|
}
|
|
1144
1079
|
catch (e) {
|
|
1145
|
-
(0,
|
|
1080
|
+
(0, status_logging_1.logError)(e);
|
|
1146
1081
|
return false;
|
|
1147
1082
|
}
|
|
1148
1083
|
}
|
|
@@ -1158,7 +1093,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1158
1093
|
if (!possibleValues.find(v => v === ev.Value)) {
|
|
1159
1094
|
// delete the value from the database
|
|
1160
1095
|
const sSQLDelete = `DELETE FROM [${(0, config_1.mj_core_schema)()}].EntityFieldValue WHERE ID='${ev.ID}'`;
|
|
1161
|
-
await this.
|
|
1096
|
+
await this.LogSQLAndExecute(ds, sSQLDelete, `SQL text to delete entity field value ID ${ev.ID}`);
|
|
1162
1097
|
numRemoved++;
|
|
1163
1098
|
}
|
|
1164
1099
|
}
|
|
@@ -1171,7 +1106,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1171
1106
|
(EntityFieldID, Sequence, Value, Code)
|
|
1172
1107
|
VALUES
|
|
1173
1108
|
('${entityFieldID}', ${1 + possibleValues.indexOf(v)}, '${v}', '${v}')`;
|
|
1174
|
-
await this.
|
|
1109
|
+
await this.LogSQLAndExecute(ds, sSQLInsert, `SQL text to insert entity field values`);
|
|
1175
1110
|
numAdded++;
|
|
1176
1111
|
}
|
|
1177
1112
|
}
|
|
@@ -1182,7 +1117,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1182
1117
|
if (ev && ev.Sequence !== 1 + possibleValues.indexOf(v)) {
|
|
1183
1118
|
// update the sequence to match the order in the possible values list, if it doesn't already match
|
|
1184
1119
|
const sSQLUpdate = `UPDATE [${(0, config_1.mj_core_schema)()}].EntityFieldValue SET Sequence=${1 + possibleValues.indexOf(v)} WHERE ID='${ev.ID}'`;
|
|
1185
|
-
await this.
|
|
1120
|
+
await this.LogSQLAndExecute(ds, sSQLUpdate, `SQL text to update entity field value sequence`);
|
|
1186
1121
|
numUpdated++;
|
|
1187
1122
|
}
|
|
1188
1123
|
}
|
|
@@ -1190,7 +1125,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1190
1125
|
return true;
|
|
1191
1126
|
}
|
|
1192
1127
|
catch (e) {
|
|
1193
|
-
(0,
|
|
1128
|
+
(0, status_logging_1.logError)(e);
|
|
1194
1129
|
return false;
|
|
1195
1130
|
}
|
|
1196
1131
|
}
|
|
@@ -1201,7 +1136,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1201
1136
|
// Note: Assuming fieldName does not contain regex special characters; otherwise, it needs to be escaped as well.
|
|
1202
1137
|
const structureRegex = new RegExp(`^\\(\\[${fieldName}\\]='[^']+'(?: OR \\[${fieldName}\\]='[^']+?')+\\)$`);
|
|
1203
1138
|
if (!structureRegex.test(constraintDefinition)) {
|
|
1204
|
-
(0,
|
|
1139
|
+
(0, status_logging_1.logWarning)(` Can't extract value list from [${entityName}].[${fieldName}]. The check constraint does not match the simple OR condition pattern or field name does not match: ${constraintDefinition}`);
|
|
1205
1140
|
return null;
|
|
1206
1141
|
}
|
|
1207
1142
|
// Regular expression to match the values within the single quotes specifically for the field
|
|
@@ -1359,7 +1294,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1359
1294
|
}
|
|
1360
1295
|
const isNewSchema = await this.isSchemaNew(ds, newEntity.SchemaName);
|
|
1361
1296
|
const sSQLInsert = this.createNewEntityInsertSQL(newEntityName, newEntity, suffix);
|
|
1362
|
-
const newEntityResult = await this.
|
|
1297
|
+
const newEntityResult = await this.LogSQLAndExecute(ds, sSQLInsert, `SQL generated to create new entity ${newEntityName}`);
|
|
1363
1298
|
const newEntityID = newEntityResult && newEntityResult.length > 0 ? newEntityResult[0].ID : null;
|
|
1364
1299
|
if (!newEntityID) {
|
|
1365
1300
|
throw new Error(`Failed to create new entity ${newEntityName} for table ${newEntity.SchemaName}.${newEntity.TableName}`);
|
|
@@ -1389,7 +1324,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1389
1324
|
const sSQLInsertApplicationEntity = `INSERT INTO ${(0, config_1.mj_core_schema)()}.ApplicationEntity
|
|
1390
1325
|
(ApplicationID, EntityID, Sequence) VALUES
|
|
1391
1326
|
('${app.ID}', '${newEntityID}', (SELECT ISNULL(MAX(Sequence),0)+1 FROM ${(0, config_1.mj_core_schema)()}.ApplicationEntity WHERE ApplicationID = '${app.ID}'))`;
|
|
1392
|
-
this.
|
|
1327
|
+
this.LogSQLAndExecute(ds, sSQLInsertApplicationEntity, `SQL generated to add new entity ${newEntityName} to application ${appName}`);
|
|
1393
1328
|
}
|
|
1394
1329
|
else
|
|
1395
1330
|
(0, core_1.LogError)(` >>>> ERROR: Unable to find Application ID for application ${appName} to add new entity ${newEntityName} to it`);
|
|
@@ -1404,7 +1339,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1404
1339
|
const sSQLInsertPermission = `INSERT INTO ${(0, config_1.mj_core_schema)()}.EntityPermission
|
|
1405
1340
|
(EntityID, RoleID, CanRead, CanCreate, CanUpdate, CanDelete) VALUES
|
|
1406
1341
|
('${newEntityID}', '${RoleID}', ${p.CanRead ? 1 : 0}, ${p.CanCreate ? 1 : 0}, ${p.CanUpdate ? 1 : 0}, ${p.CanDelete ? 1 : 0})`;
|
|
1407
|
-
await this.
|
|
1342
|
+
await this.LogSQLAndExecute(ds, sSQLInsertPermission, `SQL generated to add new permission for entity ${newEntityName} for role ${p.RoleName}`);
|
|
1408
1343
|
}
|
|
1409
1344
|
else
|
|
1410
1345
|
(0, core_1.LogError)(` >>>> ERROR: Unable to find Role ID for role ${p.RoleName} to add permissions for new entity ${newEntityName}`);
|
|
@@ -1429,7 +1364,7 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1429
1364
|
}
|
|
1430
1365
|
async createNewApplication(ds, appName) {
|
|
1431
1366
|
const sSQL = "INSERT INTO [" + (0, config_1.mj_core_schema)() + "].Application (Name, Description) VALUES ('" + appName + "', 'Generated for Schema'); SELECT @@IDENTITY AS ID";
|
|
1432
|
-
const result = await this.
|
|
1367
|
+
const result = await this.LogSQLAndExecute(ds, sSQL, `SQL generated to create new application ${appName}`);
|
|
1433
1368
|
return result && result.length > 0 ? result[0].ID : null;
|
|
1434
1369
|
}
|
|
1435
1370
|
async applicationExists(ds, applicationName) {
|
|
@@ -1551,15 +1486,11 @@ let ManageMetadataBase = ManageMetadataBase_1 = class ManageMetadataBase {
|
|
|
1551
1486
|
* Note that in order to append to the log file, ManageMetadataBase.manageMetaDataLogging must be called first.
|
|
1552
1487
|
* @param ds - The DataSource object to use to execute the query.
|
|
1553
1488
|
* @param query - The SQL query to execute.
|
|
1554
|
-
* @param appendToLogFile - If true, the query will be appended to the log file.
|
|
1555
1489
|
* @param description - A description of the query to append to the log file.
|
|
1556
1490
|
* @returns - The result of the query execution.
|
|
1557
1491
|
*/
|
|
1558
|
-
async
|
|
1559
|
-
|
|
1560
|
-
this.appendToFile(query, description);
|
|
1561
|
-
}
|
|
1562
|
-
return ds.query(query);
|
|
1492
|
+
async LogSQLAndExecute(ds, query, description) {
|
|
1493
|
+
sql_logging_1.SQLLogging.LogSQLAndExecute(ds, query, description);
|
|
1563
1494
|
}
|
|
1564
1495
|
};
|
|
1565
1496
|
exports.ManageMetadataBase = ManageMetadataBase;
|