@memberjunction/codegen-lib 5.2.0 → 5.3.1
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/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +11 -6
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +12 -4
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +230 -153
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/sql_codegen.d.ts +24 -1
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +107 -24
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.d.ts +6 -0
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.js +20 -7
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
- package/package.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql_codegen.d.ts","sourceRoot":"","sources":["../../src/Database/sql_codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAkC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAK7G,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,GAAG,MAAM,OAAO,CAAC;AAYxB,eAAO,MAAM,MAAM;;;;CAIP,CAAC;AAEb,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC;AAGxD;;;;GAIG;AACH,qBAAa,cAAc;IACvB,SAAS,CAAC,iBAAiB,EAAE,cAAc,CAAkF;IAC7H,IAAW,gBAAgB,IAAI,cAAc,CAE5C;IAED;;OAEG;IACH,SAAS,CAAC,sCAAsC,EAAE,MAAM,EAAE,CAAM;IAEhE;;OAEG;IACH,SAAS,CAAC,sCAAsC,EAAE,OAAO,CAAS;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EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;IAoDhB;;;;;;;;OAQG;IACH,SAAS,CAAC,2BAA2B,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE;CA8EzG"}
|
|
@@ -414,10 +414,85 @@ export class SQLCodeGenBase {
|
|
|
414
414
|
return { Success: false, Files: [] };
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
-
|
|
417
|
+
/**
|
|
418
|
+
* Writes a generated SQL file to disk only if the content has changed from the existing file.
|
|
419
|
+
* Returns true if the file was written (content changed or file is new), false if unchanged.
|
|
420
|
+
* This avoids false timestamp updates and unnecessary I/O.
|
|
421
|
+
*/
|
|
422
|
+
writeFileIfChanged(filePath, newContent) {
|
|
423
|
+
if (fs.existsSync(filePath)) {
|
|
424
|
+
const existing = fs.readFileSync(filePath, 'utf-8');
|
|
425
|
+
if (existing === newContent) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
fs.writeFileSync(filePath, newContent);
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Fetches the current base view definition from SQL Server and compares it against newly generated SQL.
|
|
434
|
+
* If the view body has changed (e.g., a virtual field was added to a joined table), the entity is
|
|
435
|
+
* logged and executed. Unlike adding to modifiedEntityList (which would cause all SPs,
|
|
436
|
+
* permissions, indexes, etc. to be logged too), this only logs the base view SQL itself.
|
|
437
|
+
*
|
|
438
|
+
* Comparison extracts the SELECT body from both the DB definition (CREATE VIEW ... AS <body>)
|
|
439
|
+
* and the generated SQL, normalizing whitespace for a fair comparison.
|
|
440
|
+
* @returns true if the base view changed, false otherwise
|
|
441
|
+
*/
|
|
442
|
+
async checkBaseViewChangedInDB(pool, entity, generatedViewSQL) {
|
|
443
|
+
// Skip if entity is already tracked as new or modified — those are handled by existing logic
|
|
444
|
+
if (ManageMetadataBase.newEntityList.includes(entity.Name) ||
|
|
445
|
+
ManageMetadataBase.modifiedEntityList.includes(entity.Name)) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
const viewName = entity.BaseView ? entity.BaseView : `vw${entity.CodeName}`;
|
|
450
|
+
const result = await pool.request().query(`SELECT OBJECT_DEFINITION(OBJECT_ID('[${entity.SchemaName}].[${viewName}]')) AS ViewDefinition`);
|
|
451
|
+
const dbDefinition = result.recordset?.[0]?.ViewDefinition;
|
|
452
|
+
if (!dbDefinition) {
|
|
453
|
+
// View doesn't exist in DB yet — it's new, will be handled by existing new entity logic
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
// Extract the SELECT body from both: everything after "AS\n" up to the trailing GO/permissions
|
|
457
|
+
const generatedBody = this.extractViewSelectBody(generatedViewSQL);
|
|
458
|
+
const dbBody = this.extractViewSelectBody(dbDefinition);
|
|
459
|
+
if (generatedBody !== dbBody) {
|
|
460
|
+
logStatus(` Base view changed for ${entity.Name} — logging view SQL`);
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
catch (e) {
|
|
466
|
+
// Non-fatal — if we can't compare, the existing logic still runs
|
|
467
|
+
logIf(configInfo.verboseOutput, `Could not compare base view for ${entity.Name}: ${e}`);
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Extracts the SELECT body from a CREATE VIEW statement, normalizing whitespace for comparison.
|
|
473
|
+
* Handles both DB-stored definitions (CREATE VIEW ... AS SELECT ...) and generated SQL
|
|
474
|
+
* (which includes DROP VIEW, comment headers, GO, and permissions after the view body).
|
|
475
|
+
*/
|
|
476
|
+
extractViewSelectBody(viewSQL) {
|
|
477
|
+
// Find the AS keyword that precedes the SELECT — match "AS" on its own line or followed by whitespace+SELECT
|
|
478
|
+
const asMatch = viewSQL.match(/\bAS\s*\r?\n\s*SELECT\b/i);
|
|
479
|
+
if (!asMatch || asMatch.index === undefined) {
|
|
480
|
+
return viewSQL.trim(); // fallback: compare the whole thing
|
|
481
|
+
}
|
|
482
|
+
// Start from the SELECT keyword
|
|
483
|
+
let body = viewSQL.substring(asMatch.index + asMatch[0].indexOf('SELECT'));
|
|
484
|
+
// Trim trailing GO and anything after it (permissions, etc.)
|
|
485
|
+
const goMatch = body.match(/\r?\nGO\b/i);
|
|
486
|
+
if (goMatch && goMatch.index !== undefined) {
|
|
487
|
+
body = body.substring(0, goMatch.index);
|
|
488
|
+
}
|
|
489
|
+
// Normalize whitespace for fair comparison: collapse runs of whitespace to single space
|
|
490
|
+
return body.replace(/\s+/g, ' ').trim();
|
|
491
|
+
}
|
|
492
|
+
logSQLForNewOrModifiedEntity(entity, sql, description, logSql = false, forceLog = false) {
|
|
418
493
|
// Check if we should log this SQL
|
|
419
|
-
let shouldLog =
|
|
420
|
-
if (logSql) {
|
|
494
|
+
let shouldLog = forceLog;
|
|
495
|
+
if (!shouldLog && logSql) {
|
|
421
496
|
// Check if entity is in new or modified lists
|
|
422
497
|
const isNewOrModified = !!ManageMetadataBase.newEntityList.find(e => e === entity.Name) ||
|
|
423
498
|
!!ManageMetadataBase.modifiedEntityList.find(e => e === entity.Name);
|
|
@@ -453,7 +528,7 @@ export class SQLCodeGenBase {
|
|
|
453
528
|
shouldLog = true;
|
|
454
529
|
}
|
|
455
530
|
else if (isForceRegeneration) {
|
|
456
|
-
// For force regeneration, the specific type flags (spCreate, baseViews, etc.)
|
|
531
|
+
// For force regeneration, the specific type flags (spCreate, baseViews, etc.)
|
|
457
532
|
// already filtered this - now we just need to check entity filtering
|
|
458
533
|
if (this.filterEntitiesQualifiedForRegeneration) {
|
|
459
534
|
// Only log if entity is in the qualified list
|
|
@@ -483,6 +558,10 @@ export class SQLCodeGenBase {
|
|
|
483
558
|
fs.mkdirSync(schemaDirectory, { recursive: true }); // create the directory if it doesn't exist
|
|
484
559
|
let sRet = '';
|
|
485
560
|
let permissionsSQL = '';
|
|
561
|
+
// Tracks whether the base view SQL differs from what's in the database.
|
|
562
|
+
// When true, we force-log the view, its permissions, and all SPs (which compile the view in)
|
|
563
|
+
// so the migration log script can fully update target databases.
|
|
564
|
+
let baseViewChanged = false;
|
|
486
565
|
// Indexes for Fkeys for the table (skip for virtual entities — views can't have indexes)
|
|
487
566
|
if (!options.onlyPermissions && !options.entity.VirtualEntity) {
|
|
488
567
|
const shouldGenerateIndexes = autoIndexForeignKeys() || (configInfo.forceRegeneration?.enabled && configInfo.forceRegeneration?.indexes);
|
|
@@ -490,8 +569,8 @@ export class SQLCodeGenBase {
|
|
|
490
569
|
const s = this.generateSingleEntitySQLFileHeader(options.entity, 'Index for Foreign Keys') + indexSQL;
|
|
491
570
|
if (options.writeFiles) {
|
|
492
571
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('index', options.entity.SchemaName, options.entity.BaseTable, false, true));
|
|
572
|
+
this.writeFileIfChanged(filePath, s);
|
|
493
573
|
this.logSQLForNewOrModifiedEntity(options.entity, s, 'Index for Foreign Keys for ' + options.entity.BaseTable, options.enableSQLLoggingForNewOrModifiedEntities);
|
|
494
|
-
fs.writeFileSync(filePath, s);
|
|
495
574
|
files.push(filePath);
|
|
496
575
|
}
|
|
497
576
|
sRet += s + '\nGO\n';
|
|
@@ -513,8 +592,8 @@ export class SQLCodeGenBase {
|
|
|
513
592
|
this.generateRootIDFunction(options.entity, field);
|
|
514
593
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('function', options.entity.SchemaName, functionName, false, true));
|
|
515
594
|
if (options.writeFiles) {
|
|
595
|
+
this.writeFileIfChanged(filePath, s);
|
|
516
596
|
this.logSQLForNewOrModifiedEntity(options.entity, s, `Root ID Function SQL for ${options.entity.Name}.${field.Name}`, options.enableSQLLoggingForNewOrModifiedEntities);
|
|
517
|
-
fs.writeFileSync(filePath, s);
|
|
518
597
|
files.push(filePath);
|
|
519
598
|
}
|
|
520
599
|
// Add function SQL to output BEFORE the view
|
|
@@ -523,10 +602,14 @@ export class SQLCodeGenBase {
|
|
|
523
602
|
}
|
|
524
603
|
// Generate the base view (which may reference the TVFs created above)
|
|
525
604
|
const s = this.generateSingleEntitySQLFileHeader(options.entity, options.entity.BaseView) + await this.generateBaseView(options.pool, options.entity);
|
|
605
|
+
// Compare generated view SQL against what's currently in the database.
|
|
606
|
+
// If the SELECT body differs, force-log just this base view via the forceLog flag
|
|
607
|
+
// so logging stays centralized in logSQLForNewOrModifiedEntity.
|
|
608
|
+
baseViewChanged = await this.checkBaseViewChangedInDB(options.pool, options.entity, s);
|
|
526
609
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('view', options.entity.SchemaName, options.entity.BaseView, false, true));
|
|
527
610
|
if (options.writeFiles) {
|
|
528
|
-
this.
|
|
529
|
-
|
|
611
|
+
this.writeFileIfChanged(filePath, s);
|
|
612
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `Base View SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
530
613
|
files.push(filePath);
|
|
531
614
|
}
|
|
532
615
|
sRet += s + '\nGO\n';
|
|
@@ -537,8 +620,8 @@ export class SQLCodeGenBase {
|
|
|
537
620
|
permissionsSQL += s + '\nGO\n';
|
|
538
621
|
if (options.writeFiles) {
|
|
539
622
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('view', options.entity.SchemaName, options.entity.BaseView, true, true));
|
|
540
|
-
|
|
541
|
-
this.logSQLForNewOrModifiedEntity(options.entity, s, `Base View Permissions SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities);
|
|
623
|
+
this.writeFileIfChanged(filePath, s);
|
|
624
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `Base View Permissions SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
542
625
|
files.push(filePath);
|
|
543
626
|
}
|
|
544
627
|
// now, append the permissions to the return string IF we did NOT generate the base view - because if we generated the base view, that
|
|
@@ -555,8 +638,8 @@ export class SQLCodeGenBase {
|
|
|
555
638
|
const s = this.generateSingleEntitySQLFileHeader(options.entity, spName) + this.generateSPCreate(options.entity);
|
|
556
639
|
if (options.writeFiles) {
|
|
557
640
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('sp', options.entity.SchemaName, spName, false, true));
|
|
558
|
-
this.
|
|
559
|
-
|
|
641
|
+
this.writeFileIfChanged(filePath, s);
|
|
642
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `spCreate SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
560
643
|
files.push(filePath);
|
|
561
644
|
}
|
|
562
645
|
sRet += s + '\nGO\n';
|
|
@@ -566,8 +649,8 @@ export class SQLCodeGenBase {
|
|
|
566
649
|
permissionsSQL += s + '\nGO\n';
|
|
567
650
|
if (options.writeFiles) {
|
|
568
651
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('sp', options.entity.SchemaName, spName, true, true));
|
|
569
|
-
this.
|
|
570
|
-
|
|
652
|
+
this.writeFileIfChanged(filePath, s);
|
|
653
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `spCreate Permissions for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
571
654
|
files.push(filePath);
|
|
572
655
|
}
|
|
573
656
|
// now, append the permissions to the return string IF we did NOT generate the proc - because if we generated the proc, that
|
|
@@ -585,8 +668,8 @@ export class SQLCodeGenBase {
|
|
|
585
668
|
const s = this.generateSingleEntitySQLFileHeader(options.entity, spName) + this.generateSPUpdate(options.entity);
|
|
586
669
|
if (options.writeFiles) {
|
|
587
670
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('sp', options.entity.SchemaName, spName, false, true));
|
|
588
|
-
|
|
589
|
-
this.logSQLForNewOrModifiedEntity(options.entity, s, `spUpdate SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities);
|
|
671
|
+
this.writeFileIfChanged(filePath, s);
|
|
672
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `spUpdate SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
590
673
|
files.push(filePath);
|
|
591
674
|
}
|
|
592
675
|
sRet += s + '\nGO\n';
|
|
@@ -596,8 +679,8 @@ export class SQLCodeGenBase {
|
|
|
596
679
|
permissionsSQL += s + '\nGO\n';
|
|
597
680
|
if (options.writeFiles) {
|
|
598
681
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('sp', options.entity.SchemaName, spName, true, true));
|
|
599
|
-
this.
|
|
600
|
-
|
|
682
|
+
this.writeFileIfChanged(filePath, s);
|
|
683
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `spUpdate Permissions for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
601
684
|
files.push(filePath);
|
|
602
685
|
}
|
|
603
686
|
// now, append the permissions to the return string IF we did NOT generate the proc - because if we generated the proc, that
|
|
@@ -621,8 +704,8 @@ export class SQLCodeGenBase {
|
|
|
621
704
|
const s = this.generateSingleEntitySQLFileHeader(options.entity, spName) + await this.generateSPDelete(options.entity, options.pool);
|
|
622
705
|
if (options.writeFiles) {
|
|
623
706
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('sp', options.entity.SchemaName, spName, false, true));
|
|
624
|
-
this.
|
|
625
|
-
|
|
707
|
+
this.writeFileIfChanged(filePath, s);
|
|
708
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `spDelete SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
626
709
|
files.push(filePath);
|
|
627
710
|
}
|
|
628
711
|
sRet += s + '\nGO\n';
|
|
@@ -632,8 +715,8 @@ export class SQLCodeGenBase {
|
|
|
632
715
|
permissionsSQL += s + '\nGO\n';
|
|
633
716
|
if (options.writeFiles) {
|
|
634
717
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('sp', options.entity.SchemaName, spName, true, true));
|
|
635
|
-
this.
|
|
636
|
-
|
|
718
|
+
this.writeFileIfChanged(filePath, s);
|
|
719
|
+
this.logSQLForNewOrModifiedEntity(options.entity, s, `spDelete Permissions for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
637
720
|
files.push(filePath);
|
|
638
721
|
}
|
|
639
722
|
// now, append the permissions to the return string IF we did NOT generate the proc - because if we generated the proc, that
|
|
@@ -649,8 +732,8 @@ export class SQLCodeGenBase {
|
|
|
649
732
|
// only write the actual sql out if we're not only generating permissions
|
|
650
733
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('full_text_search_function', options.entity.SchemaName, options.entity.BaseTable, false, true));
|
|
651
734
|
if (options.writeFiles) {
|
|
735
|
+
this.writeFileIfChanged(filePath, ft.sql);
|
|
652
736
|
this.logSQLForNewOrModifiedEntity(options.entity, ft.sql, `Full Text Search SQL for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities);
|
|
653
|
-
fs.writeFileSync(filePath, ft.sql);
|
|
654
737
|
files.push(filePath);
|
|
655
738
|
}
|
|
656
739
|
sRet += ft.sql + '\nGO\n';
|
|
@@ -660,8 +743,8 @@ export class SQLCodeGenBase {
|
|
|
660
743
|
permissionsSQL += sP + '\nGO\n';
|
|
661
744
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('full_text_search_function', options.entity.SchemaName, options.entity.BaseTable, true, true));
|
|
662
745
|
if (options.writeFiles) {
|
|
746
|
+
this.writeFileIfChanged(filePath, sP);
|
|
663
747
|
this.logSQLForNewOrModifiedEntity(options.entity, sP, `Full Text Search Permissions for ${options.entity.Name}`, options.enableSQLLoggingForNewOrModifiedEntities);
|
|
664
|
-
fs.writeFileSync(filePath, sP);
|
|
665
748
|
files.push(filePath);
|
|
666
749
|
}
|
|
667
750
|
// now, append the permissions to the return string IF we did NOT generate the function - because if we generated the function, that
|