@memberjunction/codegen-lib 6.1.0-edge.2 → 6.1.0-edge.4
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/LICENSE +180 -4
- package/README.md +89 -43
- package/dist/Angular/angular-codegen.d.ts +0 -8
- package/dist/Angular/angular-codegen.d.ts.map +1 -1
- package/dist/Angular/angular-codegen.js +32 -22
- package/dist/Angular/angular-codegen.js.map +1 -1
- package/dist/Angular/entity-data-grid-related-entity-component.js +2 -2
- package/dist/Angular/entity-data-grid-related-entity-component.js.map +1 -1
- package/dist/Angular/related-entity-components.d.ts +1 -1
- package/dist/Angular/related-entity-components.js +1 -1
- package/dist/Config/config.d.ts +118 -1
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +202 -8
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/__tests__/exclude-schema-permissions.test.d.ts +2 -0
- package/dist/Database/__tests__/exclude-schema-permissions.test.d.ts.map +1 -0
- package/dist/Database/__tests__/exclude-schema-permissions.test.js +32 -0
- package/dist/Database/__tests__/exclude-schema-permissions.test.js.map +1 -0
- package/dist/Database/codeGenDatabaseProvider.d.ts +178 -2
- package/dist/Database/codeGenDatabaseProvider.d.ts.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.js +175 -10
- package/dist/Database/codeGenDatabaseProvider.js.map +1 -1
- package/dist/Database/heal-schema-params.d.ts +33 -0
- package/dist/Database/heal-schema-params.d.ts.map +1 -0
- package/dist/Database/heal-schema-params.js +51 -0
- package/dist/Database/heal-schema-params.js.map +1 -0
- package/dist/Database/manage-metadata.d.ts +301 -2
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +1242 -96
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/materializationAnalysis.d.ts +241 -0
- package/dist/Database/materializationAnalysis.d.ts.map +1 -0
- package/dist/Database/materializationAnalysis.js +415 -0
- package/dist/Database/materializationAnalysis.js.map +1 -0
- package/dist/Database/materializationBroadRender.d.ts +67 -0
- package/dist/Database/materializationBroadRender.d.ts.map +1 -0
- package/dist/Database/materializationBroadRender.js +104 -0
- package/dist/Database/materializationBroadRender.js.map +1 -0
- package/dist/Database/materializationDrift.d.ts +59 -0
- package/dist/Database/materializationDrift.d.ts.map +1 -0
- package/dist/Database/materializationDrift.js +85 -0
- package/dist/Database/materializationDrift.js.map +1 -0
- package/dist/Database/materializationParamClassifier.d.ts +92 -0
- package/dist/Database/materializationParamClassifier.d.ts.map +1 -0
- package/dist/Database/materializationParamClassifier.js +224 -0
- package/dist/Database/materializationParamClassifier.js.map +1 -0
- package/dist/Database/materializationParamVerifier.d.ts +71 -0
- package/dist/Database/materializationParamVerifier.d.ts.map +1 -0
- package/dist/Database/materializationParamVerifier.js +302 -0
- package/dist/Database/materializationParamVerifier.js.map +1 -0
- package/dist/Database/materializationSqlAst.d.ts +78 -0
- package/dist/Database/materializationSqlAst.d.ts.map +1 -0
- package/dist/Database/materializationSqlAst.js +142 -0
- package/dist/Database/materializationSqlAst.js.map +1 -0
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts +93 -56
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js +399 -247
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLCodeGenProvider.materialization.test.d.ts +2 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLCodeGenProvider.materialization.test.d.ts.map +1 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLCodeGenProvider.materialization.test.js +119 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLCodeGenProvider.materialization.test.js.map +1 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLHierarchyFunctions.test.d.ts +2 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLHierarchyFunctions.test.d.ts.map +1 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLHierarchyFunctions.test.js +155 -0
- package/dist/Database/providers/postgresql/__tests__/PostgreSQLHierarchyFunctions.test.js.map +1 -0
- package/dist/Database/providers/postgresql/__tests__/SoftPrimaryKeyIndex.test.d.ts +2 -0
- package/dist/Database/providers/postgresql/__tests__/SoftPrimaryKeyIndex.test.d.ts.map +1 -0
- package/dist/Database/providers/postgresql/__tests__/SoftPrimaryKeyIndex.test.js +110 -0
- package/dist/Database/providers/postgresql/__tests__/SoftPrimaryKeyIndex.test.js.map +1 -0
- package/dist/Database/providers/postgresql/metadataSupportObjects.js +78 -10
- package/dist/Database/providers/postgresql/metadataSupportObjects.js.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts +72 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js +322 -0
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/sqlserver/__tests__/BaseViewEmissionGoldenMaster.test.d.ts +2 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewEmissionGoldenMaster.test.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewEmissionGoldenMaster.test.js +547 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewEmissionGoldenMaster.test.js.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewRegenDecision.test.d.ts +2 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewRegenDecision.test.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewRegenDecision.test.js +721 -0
- package/dist/Database/providers/sqlserver/__tests__/BaseViewRegenDecision.test.js.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerCodeGenProvider.materialization.test.d.ts +2 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerCodeGenProvider.materialization.test.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerCodeGenProvider.materialization.test.js +78 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerCodeGenProvider.materialization.test.js.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerHierarchyTVF.test.d.ts +2 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerHierarchyTVF.test.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerHierarchyTVF.test.js +155 -0
- package/dist/Database/providers/sqlserver/__tests__/SQLServerHierarchyTVF.test.js.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/SoftPrimaryKeyIndex.test.d.ts +2 -0
- package/dist/Database/providers/sqlserver/__tests__/SoftPrimaryKeyIndex.test.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/SoftPrimaryKeyIndex.test.js +195 -0
- package/dist/Database/providers/sqlserver/__tests__/SoftPrimaryKeyIndex.test.js.map +1 -0
- package/dist/Database/schema-filters.d.ts +23 -0
- package/dist/Database/schema-filters.d.ts.map +1 -0
- package/dist/Database/schema-filters.js +42 -0
- package/dist/Database/schema-filters.js.map +1 -0
- package/dist/Database/schema-scope.d.ts.map +1 -1
- package/dist/Database/schema-scope.js +4 -0
- package/dist/Database/schema-scope.js.map +1 -1
- package/dist/Database/sql_codegen.d.ts +39 -5
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +176 -67
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/EntityNameScanner/EntityNameScanner.d.ts.map +1 -1
- package/dist/EntityNameScanner/EntityNameScanner.js +33 -2
- package/dist/EntityNameScanner/EntityNameScanner.js.map +1 -1
- package/dist/Manifest/GenerateClassRegistrationsManifest.d.ts +8 -4
- package/dist/Manifest/GenerateClassRegistrationsManifest.d.ts.map +1 -1
- package/dist/Manifest/GenerateClassRegistrationsManifest.js +63 -20
- package/dist/Manifest/GenerateClassRegistrationsManifest.js.map +1 -1
- package/dist/Misc/action_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/action_subclasses_codegen.js +4 -4
- package/dist/Misc/action_subclasses_codegen.js.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.d.ts +61 -0
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.js +437 -158
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
- package/dist/Misc/graphql_server_codegen.d.ts +4 -58
- package/dist/Misc/graphql_server_codegen.d.ts.map +1 -1
- package/dist/Misc/graphql_server_codegen.js +22 -236
- package/dist/Misc/graphql_server_codegen.js.map +1 -1
- package/dist/Misc/sql_logging.d.ts +25 -0
- package/dist/Misc/sql_logging.d.ts.map +1 -1
- package/dist/Misc/sql_logging.js +51 -8
- package/dist/Misc/sql_logging.js.map +1 -1
- package/dist/Misc/system_integrity.d.ts.map +1 -1
- package/dist/Misc/system_integrity.js +5 -0
- package/dist/Misc/system_integrity.js.map +1 -1
- package/package.json +30 -30
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { snapshotAuthoredExcludeSchemas } from './heal-schema-params.js';
|
|
1
2
|
/**
|
|
2
3
|
* Schema-scope resolution helpers for CodeGen.
|
|
3
4
|
*
|
|
@@ -58,6 +59,9 @@ export function computeSchemasToExcludeForIncludeList(allSchemas, includeSchemas
|
|
|
58
59
|
* @returns the schema names that were newly appended (empty when the scope is unused or already applied)
|
|
59
60
|
*/
|
|
60
61
|
export function applyIncludeSchemaScope(allSchemas, config) {
|
|
62
|
+
// Capture authored excludes before this run mutates excludeSchemas. Heal EXEC
|
|
63
|
+
// statements must serialize that original list, not the sibling snapshot.
|
|
64
|
+
snapshotAuthoredExcludeSchemas(config.excludeSchemas);
|
|
61
65
|
if (!config.includeSchemas || config.includeSchemas.length === 0) {
|
|
62
66
|
return []; // classic exclude-only behavior, unchanged
|
|
63
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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,OAAO,SAAS,CAAC;AACnB,CAAC;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAoB,EAAE,MAAyB;IACrF,8EAA8E;IAC9E,0EAA0E;IAC1E,8BAA8B,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjE,OAAO,EAAE,CAAC,CAAC,2CAA2C;IACxD,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAC3B,MAAM,CAAC,cAAc,GAAG,EAAE,CAAC;IAC7B,CAAC;IACD,MAAM,SAAS,GAAG,qCAAqC,CAAC,UAAU,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;IAClH,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACzC,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -8,6 +8,14 @@ export declare const SPType: {
|
|
|
8
8
|
readonly Delete: "Delete";
|
|
9
9
|
};
|
|
10
10
|
export type SPType = typeof SPType[keyof typeof SPType];
|
|
11
|
+
/**
|
|
12
|
+
* Entities whose SchemaName is not in excludeSchemas (case-insensitive).
|
|
13
|
+
* This is the CodeGen run's in-scope set: SQL objects and GRANTs are
|
|
14
|
+
* generated and executed only for these. excludeSchemas means "not this run".
|
|
15
|
+
*/
|
|
16
|
+
export declare function entitiesNotInExcludedSchemas<T extends {
|
|
17
|
+
SchemaName: string;
|
|
18
|
+
}>(entities: T[], excludeSchemas: string[]): T[];
|
|
11
19
|
/**
|
|
12
20
|
* This class is responsible for generating database level objects like views, stored procedures, permissions, etc. You can sub-class this class to create your own SQL generation logic or implement support for other
|
|
13
21
|
* databases. The base class implements support for SQL Server. In future versions of MJ, we will break out an abstract base class that has the skeleton of the logic and then the SQL Server version will be a sub-class
|
|
@@ -109,7 +117,7 @@ export declare class SQLCodeGenBase {
|
|
|
109
117
|
*/
|
|
110
118
|
executeEntityInPhases(pool: CodeGenConnection, entity: EntityInfo, willRegenerate: Set<string> | undefined): Promise<PhasedExecutionResult>;
|
|
111
119
|
/**
|
|
112
|
-
* Concatenates the
|
|
120
|
+
* Concatenates the hierarchy TVF SQL for every recursive ParentID-style FK
|
|
113
121
|
* on this entity. Mirrors the inline TVF generation in
|
|
114
122
|
* `generateSingleEntitySQLToSeparateFiles` so the phased executor can run
|
|
115
123
|
* the same DDL ahead of the base view.
|
|
@@ -226,11 +234,30 @@ export declare class SQLCodeGenBase {
|
|
|
226
234
|
* Delegates to the database provider for platform-specific index DDL.
|
|
227
235
|
*/
|
|
228
236
|
generateIndexesForForeignKeys(pool: CodeGenConnection, entity: EntityInfo): string;
|
|
237
|
+
/**
|
|
238
|
+
* Generates the composite index covering the entity's SOFT primary key. Empty for every
|
|
239
|
+
* entity with a real `PRIMARY KEY` constraint, which is nearly all of them.
|
|
240
|
+
*
|
|
241
|
+
* Kept separate from {@link generateIndexesForForeignKeys} and gated by its own setting: a
|
|
242
|
+
* soft-PK index serves MJ's own per-record existence check on the create path, which is a
|
|
243
|
+
* different concern from indexing foreign keys for joins and filters, and an operator's
|
|
244
|
+
* opinion about one is not an opinion about the other.
|
|
245
|
+
*/
|
|
246
|
+
generateIndexForSoftPrimaryKey(entity: EntityInfo): string;
|
|
229
247
|
/**
|
|
230
248
|
* Detects self-referential foreign keys in an entity (e.g., ParentTaskID pointing back to Task table)
|
|
231
249
|
* Returns array of field info objects representing recursive relationships
|
|
232
250
|
*/
|
|
233
251
|
protected detectRecursiveForeignKeys(entity: EntityInfo): EntityFieldInfo[];
|
|
252
|
+
/**
|
|
253
|
+
* Helper to get the canonical hierarchy function definitions and metadata for an entity and recursive FK field.
|
|
254
|
+
*/
|
|
255
|
+
protected getHierarchyFunctionsForField(entity: EntityInfo, field: EntityFieldInfo): Array<{
|
|
256
|
+
functionName: string;
|
|
257
|
+
sql: string;
|
|
258
|
+
description: string;
|
|
259
|
+
fieldName: string;
|
|
260
|
+
}>;
|
|
234
261
|
/**
|
|
235
262
|
* Generates an inline Table Value Function for calculating root ID for a recursive FK field
|
|
236
263
|
* The function takes both the record ID and parent ID for optimization
|
|
@@ -243,13 +270,20 @@ export declare class SQLCodeGenBase {
|
|
|
243
270
|
*/
|
|
244
271
|
protected generateAllRootIDFunctions(entity: EntityInfo, recursiveFKs: EntityFieldInfo[]): string;
|
|
245
272
|
/**
|
|
246
|
-
* Generates the SELECT clause additions for
|
|
247
|
-
*
|
|
273
|
+
* Generates the SELECT clause additions for hierarchy metadata fields from TVFs
|
|
274
|
+
* Projects: Root<Field>, <Field>Depth, <Field>Path, <Field>IsLeaf, <Field>ChildCount
|
|
275
|
+
*/
|
|
276
|
+
protected generateHierarchyFieldSelects(entity: EntityInfo, recursiveFKs: EntityFieldInfo[], classNameFirstChar: string): string;
|
|
277
|
+
/**
|
|
278
|
+
* Generates JOIN clauses to inline Table Value Functions for hierarchy metadata calculation
|
|
279
|
+
*/
|
|
280
|
+
protected generateHierarchyJoins(recursiveFKs: EntityFieldInfo[], classNameFirstChar: string, entity: EntityInfo): string;
|
|
281
|
+
/**
|
|
282
|
+
* Generates the SELECT clause additions for root and hierarchy fields from TVFs
|
|
248
283
|
*/
|
|
249
284
|
protected generateRootFieldSelects(entity: EntityInfo, recursiveFKs: EntityFieldInfo[], classNameFirstChar: string): string;
|
|
250
285
|
/**
|
|
251
|
-
* Generates
|
|
252
|
-
* Each recursive FK gets an OUTER APPLY that calls its corresponding function
|
|
286
|
+
* Generates joins to inline Table Value Functions for hierarchy and root ID calculation
|
|
253
287
|
*/
|
|
254
288
|
protected generateRootIDJoins(recursiveFKs: EntityFieldInfo[], classNameFirstChar: string, entity: EntityInfo): string;
|
|
255
289
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql_codegen.d.ts","sourceRoot":"","sources":["../../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6
6
|
import { CodeGenDatabaseProvider } from './codeGenDatabaseProvider.js';
|
|
7
|
-
import { autoIndexForeignKeys, configInfo, customSqlScripts, mjCoreSchema } from '../Config/config.js';
|
|
7
|
+
import { autoIndexForeignKeys, autoIndexSoftPrimaryKeys, configInfo, customSqlScripts, mjCoreSchema } from '../Config/config.js';
|
|
8
|
+
import { entityInCustomBaseViewRefreshScope, shouldEmitCascadeForRelatedEntity } from './schema-filters.js';
|
|
8
9
|
import { ManageMetadataBase } from './manage-metadata.js';
|
|
9
10
|
import { UserCache } from '@memberjunction/generic-database-provider';
|
|
10
11
|
import { combineFiles, logIf } from '../Misc/util.js';
|
|
@@ -16,6 +17,15 @@ export const SPType = {
|
|
|
16
17
|
Update: 'Update',
|
|
17
18
|
Delete: 'Delete',
|
|
18
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Entities whose SchemaName is not in excludeSchemas (case-insensitive).
|
|
22
|
+
* This is the CodeGen run's in-scope set: SQL objects and GRANTs are
|
|
23
|
+
* generated and executed only for these. excludeSchemas means "not this run".
|
|
24
|
+
*/
|
|
25
|
+
export function entitiesNotInExcludedSchemas(entities, excludeSchemas) {
|
|
26
|
+
const exclude = new Set(excludeSchemas.map((s) => s.toLowerCase()));
|
|
27
|
+
return entities.filter((e) => !exclude.has(e.SchemaName.toLowerCase()));
|
|
28
|
+
}
|
|
19
29
|
/**
|
|
20
30
|
* This class is responsible for generating database level objects like views, stored procedures, permissions, etc. You can sub-class this class to create your own SQL generation logic or implement support for other
|
|
21
31
|
* databases. The base class implements support for SQL Server. In future versions of MJ, we will break out an abstract base class that has the skeleton of the logic and then the SQL Server version will be a sub-class
|
|
@@ -108,9 +118,7 @@ export class SQLCodeGenBase {
|
|
|
108
118
|
// Entities are already sorted by name in PostProcessEntityMetadata (see providerBase.ts)
|
|
109
119
|
const baselineEntities = entities.filter(e => e.IncludeInAPI);
|
|
110
120
|
// OPTIMIZATION: Use a Set for O(1) lookups instead of O(n) array finds to improve performance
|
|
111
|
-
const
|
|
112
|
-
const includedEntities = baselineEntities.filter(e => !excludeSchemasSet.has(e.SchemaName.toLowerCase())); //only include entities that are NOT in the excludeSchemas list
|
|
113
|
-
const excludedEntities = baselineEntities.filter(e => excludeSchemasSet.has(e.SchemaName.toLowerCase())); //only include entities that ARE in the excludeSchemas list in this array
|
|
121
|
+
const includedEntities = entitiesNotInExcludedSchemas(baselineEntities, configInfo.excludeSchemas);
|
|
114
122
|
// Initialize temp batch files for each schema
|
|
115
123
|
// These will be populated as SQL is generated and will be used for actual execution
|
|
116
124
|
const schemas = Array.from(new Set(baselineEntities.map(e => e.SchemaName))).sort();
|
|
@@ -140,17 +148,17 @@ export class SQLCodeGenBase {
|
|
|
140
148
|
.filter(e => e !== undefined);
|
|
141
149
|
// Track per-batch success without short-circuiting. Historically,
|
|
142
150
|
// any single batch failure here returned `false` immediately, which
|
|
143
|
-
// skipped the cascade-regen and
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
151
|
+
// skipped the cascade-regen batch and left those entities with no
|
|
152
|
+
// SQL emitted at all. The post-run CRUD validator (in runCodeGen.ts)
|
|
153
|
+
// is the authoritative ship-gate now, so we want every in-scope
|
|
154
|
+
// batch to attempt its work and surface the complete picture of
|
|
155
|
+
// what's missing — partial generation is strictly more useful than
|
|
156
|
+
// nothing.
|
|
149
157
|
let entityGenSuccess = true;
|
|
150
158
|
// Build a UNION will-regenerate set across every batch we're about
|
|
151
|
-
// to launch (main + cascade-regen
|
|
152
|
-
//
|
|
153
|
-
//
|
|
159
|
+
// to launch (main + cascade-regen). The PG view fallback's
|
|
160
|
+
// restoreDependents path uses this to skip restoring captured
|
|
161
|
+
// dependents that codegen will recreate later in the run.
|
|
154
162
|
// Without the union, batch 1's fallback only sees batch 1's
|
|
155
163
|
// entities — so a dependent like vwAIAgentRuns (which lives in
|
|
156
164
|
// batch 2 cascade-regen) is "missing from willRegenerate", the
|
|
@@ -162,7 +170,6 @@ export class SQLCodeGenBase {
|
|
|
162
170
|
const allBatchEntities = [
|
|
163
171
|
...entitiesWithoutCascadeRegeneration,
|
|
164
172
|
...entitiesForCascadeRegeneration,
|
|
165
|
-
...excludedEntities,
|
|
166
173
|
];
|
|
167
174
|
const globalWillRegenerate = new Set(allBatchEntities
|
|
168
175
|
.filter(e => !!e.BaseView)
|
|
@@ -196,7 +203,7 @@ export class SQLCodeGenBase {
|
|
|
196
203
|
willRegenerate: globalWillRegenerate
|
|
197
204
|
}); // enable sql logging for NEW entities....
|
|
198
205
|
if (!genResult.Success) {
|
|
199
|
-
logError('Main entity SQL generation batch had failures — continuing with cascade-regen
|
|
206
|
+
logError('Main entity SQL generation batch had failures — continuing with cascade-regen; validator will report any missing routines.');
|
|
200
207
|
entityGenSuccess = false;
|
|
201
208
|
}
|
|
202
209
|
// Generate SQL for cascade delete regenerations in dependency order (sequentially)
|
|
@@ -219,23 +226,19 @@ export class SQLCodeGenBase {
|
|
|
219
226
|
}
|
|
220
227
|
genResult.Files.push(...cascadeGenResult.Files);
|
|
221
228
|
}
|
|
222
|
-
// STEP 2(c)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (!genResult2.Success) {
|
|
236
|
-
logError('Excluded-entities permissions batch had failures — continuing; validator will report any missing routines.');
|
|
237
|
-
entityGenSuccess = false;
|
|
238
|
-
}
|
|
229
|
+
// STEP 2(c) used to generate+apply GRANT files for excludeSchemas entities
|
|
230
|
+
// ("we don't want to generate SQL, we do want to generate the permissions").
|
|
231
|
+
// That is wrong once excludeSchemas means "not this CodeGen run":
|
|
232
|
+
//
|
|
233
|
+
// - Open Apps exclude sibling schemas (__mj_BizAppsCommon, …) and __mj.
|
|
234
|
+
// GRANT SELECT ON [__mj_BizAppsCommon].[vwContactMethods] then runs from
|
|
235
|
+
// the orders (or other) repo, pollutes SQL Scripts/generated/<sibling>/,
|
|
236
|
+
// and fails the whole run (exit 1) when that object is missing or lives
|
|
237
|
+
// in a schema the executing login does not resolve.
|
|
238
|
+
// - Core (__mj) permissions already ship in MJ migrations. Refreshing them
|
|
239
|
+
// from an app CodeGen is not this app's job.
|
|
240
|
+
//
|
|
241
|
+
// Permissions are applied in STEP 4 for includedEntities only.
|
|
239
242
|
if (entityGenSuccess) {
|
|
240
243
|
succeedSpinner(`Entity generation completed (${(new Date().getTime() - step2StartTime.getTime()) / 1000}s)`);
|
|
241
244
|
}
|
|
@@ -244,15 +247,15 @@ export class SQLCodeGenBase {
|
|
|
244
247
|
}
|
|
245
248
|
// STEP 2(d) now that we've generated the SQL, let's create a combined file in each schema sub-directory for convenience for a DBA
|
|
246
249
|
startSpinner('Creating combined SQL files...');
|
|
247
|
-
const allEntityFiles = this.createCombinedEntitySQLFiles(directory,
|
|
248
|
-
succeedSpinner(`Created combined SQL files for ${allEntityFiles.length}
|
|
250
|
+
const allEntityFiles = this.createCombinedEntitySQLFiles(directory, includedEntities);
|
|
251
|
+
succeedSpinner(`Created combined SQL files for ${allEntityFiles.length} file(s)`);
|
|
249
252
|
// STEP 2(e) ---- FINALLY, we execute SQL in proper dependency order
|
|
250
253
|
// Use temp batch files (which maintain CodeGen log order) if available, otherwise fall back to combined files
|
|
251
254
|
startSpinner('Executing entity SQL files...');
|
|
252
255
|
const step2eStartTime = new Date();
|
|
253
256
|
let executionSuccess = false;
|
|
254
257
|
if (useProviderPhasedExecution) {
|
|
255
|
-
// Per-entity phased execution already ran during
|
|
258
|
+
// Per-entity phased execution already ran during step 2(b).
|
|
256
259
|
// Skip the bulk file re-execution — replaying the same SQL here
|
|
257
260
|
// would re-trigger 42P16 without the phased recovery wrapper and
|
|
258
261
|
// undo the work the phased executor just did.
|
|
@@ -363,10 +366,13 @@ export class SQLCodeGenBase {
|
|
|
363
366
|
succeedSpinner('No valid entities to regenerate');
|
|
364
367
|
}
|
|
365
368
|
}
|
|
366
|
-
// STEP 4- Apply permissions
|
|
369
|
+
// STEP 4- Apply permissions for THIS run's schemas only. Excluded-schema
|
|
370
|
+
// GRANT files are not generated (see STEP 2(c) note) and must not be
|
|
371
|
+
// executed: a missing sibling object would fail CodeGen with
|
|
372
|
+
// "Cannot find the object 'vw…'" even though this app's work succeeded.
|
|
367
373
|
startSpinner('Applying permissions...');
|
|
368
374
|
const step4StartTime = new Date();
|
|
369
|
-
if (!await this.applyPermissions(pool, directory,
|
|
375
|
+
if (!await this.applyPermissions(pool, directory, includedEntities)) {
|
|
370
376
|
failSpinner('Failed to apply permissions');
|
|
371
377
|
overallSuccess = false;
|
|
372
378
|
}
|
|
@@ -689,7 +695,7 @@ export class SQLCodeGenBase {
|
|
|
689
695
|
});
|
|
690
696
|
}
|
|
691
697
|
/**
|
|
692
|
-
* Concatenates the
|
|
698
|
+
* Concatenates the hierarchy TVF SQL for every recursive ParentID-style FK
|
|
693
699
|
* on this entity. Mirrors the inline TVF generation in
|
|
694
700
|
* `generateSingleEntitySQLToSeparateFiles` so the phased executor can run
|
|
695
701
|
* the same DDL ahead of the base view.
|
|
@@ -700,10 +706,10 @@ export class SQLCodeGenBase {
|
|
|
700
706
|
return '';
|
|
701
707
|
let combined = '';
|
|
702
708
|
for (const field of recursiveFKs) {
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
+ this.
|
|
706
|
-
|
|
709
|
+
const fns = this.getHierarchyFunctionsForField(entity, field);
|
|
710
|
+
for (const fn of fns) {
|
|
711
|
+
combined += fn.sql + '\n' + this._dbProvider.BatchSeparator + '\n';
|
|
712
|
+
}
|
|
707
713
|
}
|
|
708
714
|
return combined;
|
|
709
715
|
}
|
|
@@ -925,7 +931,8 @@ export class SQLCodeGenBase {
|
|
|
925
931
|
return md.Entities.filter(e => modifiedOrNewNames.includes(e.Name) &&
|
|
926
932
|
!e.BaseViewGenerated &&
|
|
927
933
|
e.IncludeInAPI &&
|
|
928
|
-
!e.VirtualEntity
|
|
934
|
+
!e.VirtualEntity &&
|
|
935
|
+
entityInCustomBaseViewRefreshScope(e.SchemaName, configInfo.excludeSchemas ?? [], configInfo.includeSchemas));
|
|
929
936
|
}
|
|
930
937
|
/**
|
|
931
938
|
* Builds a combined SQL string of sp_refreshview statements for the given entities.
|
|
@@ -951,7 +958,14 @@ export class SQLCodeGenBase {
|
|
|
951
958
|
return outer; // fully custom — one view, and it is a standing prerequisite
|
|
952
959
|
}
|
|
953
960
|
const inner = this._dbProvider.generateViewRefreshSQL(e.SchemaName, e.GeneratedViewName);
|
|
954
|
-
|
|
961
|
+
const rebind = this._dbProvider.generateLayeredOuterRebindSQL(e);
|
|
962
|
+
const outerSql = outer.trim().length > 0
|
|
963
|
+
? this.guardOnApplicationOwnedView(e, outer)
|
|
964
|
+
: '';
|
|
965
|
+
const rebindSql = rebind.trim().length > 0
|
|
966
|
+
? this.guardOnApplicationOwnedView(e, rebind.trim())
|
|
967
|
+
: '';
|
|
968
|
+
return [inner, outerSql, rebindSql].filter((s) => s && s.trim().length > 0).join('\n');
|
|
955
969
|
})
|
|
956
970
|
.join('\n');
|
|
957
971
|
}
|
|
@@ -981,9 +995,21 @@ export class SQLCodeGenBase {
|
|
|
981
995
|
let baseViewChanged = false;
|
|
982
996
|
// Indexes for Fkeys for the table (skip for virtual entities — views can't have indexes)
|
|
983
997
|
if (!options.onlyPermissions && !options.entity.VirtualEntity) {
|
|
984
|
-
const
|
|
998
|
+
const forceIndexes = !!(configInfo.forceRegeneration?.enabled && configInfo.forceRegeneration?.indexes);
|
|
999
|
+
const shouldGenerateIndexes = autoIndexForeignKeys() || forceIndexes;
|
|
985
1000
|
const indexSQL = shouldGenerateIndexes ? this.generateIndexesForForeignKeys(options.pool, options.entity) : ''; // generate indexes if auto-indexing is on OR force regeneration is enabled
|
|
986
|
-
|
|
1001
|
+
// The soft-PK index rides in the same generated file (and therefore the same
|
|
1002
|
+
// migration log), but on its own setting — see generateIndexForSoftPrimaryKey.
|
|
1003
|
+
// Appended rather than prepended so the file's existing content stays
|
|
1004
|
+
// byte-identical for every entity that has no soft PK, which is nearly all of
|
|
1005
|
+
// them: writeFileIfChanged compares content, and reordering would rewrite the
|
|
1006
|
+
// whole tree for no functional gain.
|
|
1007
|
+
const softPKSQL = (autoIndexSoftPrimaryKeys() || forceIndexes)
|
|
1008
|
+
? this.generateIndexForSoftPrimaryKey(options.entity)
|
|
1009
|
+
: '';
|
|
1010
|
+
const s = this.generateSingleEntitySQLFileHeader(options.entity, 'Index for Foreign Keys')
|
|
1011
|
+
+ indexSQL
|
|
1012
|
+
+ (softPKSQL ? (indexSQL ? '\n\n' : '') + softPKSQL : '');
|
|
987
1013
|
if (options.writeFiles) {
|
|
988
1014
|
const filePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('index', options.entity.SchemaName, options.entity.BaseTable, false, true));
|
|
989
1015
|
this.writeFileIfChanged(filePath, s);
|
|
@@ -1002,7 +1028,7 @@ export class SQLCodeGenBase {
|
|
|
1002
1028
|
if (!options.onlyPermissions &&
|
|
1003
1029
|
(options.entity.BaseViewGenerated || options.entity.HasLayeredBaseView) &&
|
|
1004
1030
|
!options.entity.VirtualEntity) {
|
|
1005
|
-
// ROOT ID FUNCTIONS (TVFs) + BASE VIEW
|
|
1031
|
+
// HIERARCHY & ROOT ID FUNCTIONS (TVFs) + BASE VIEW
|
|
1006
1032
|
// TVFs must be created BEFORE the view that references them.
|
|
1007
1033
|
// We defer TVF logging until after baseViewChanged is computed so that
|
|
1008
1034
|
// TVFs are force-logged to the TempBatchFile whenever the view changes.
|
|
@@ -1012,13 +1038,13 @@ export class SQLCodeGenBase {
|
|
|
1012
1038
|
const tvfEntries = [];
|
|
1013
1039
|
if (recursiveFKs.length > 0) {
|
|
1014
1040
|
for (const field of recursiveFKs) {
|
|
1015
|
-
const
|
|
1016
|
-
const
|
|
1017
|
-
this.
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1041
|
+
const fns = this.getHierarchyFunctionsForField(options.entity, field);
|
|
1042
|
+
for (const fn of fns) {
|
|
1043
|
+
const tvfFilePath = path.join(options.directory, this.SQLUtilityObject.getDBObjectFileName('function', options.entity.SchemaName, fn.functionName, false, true));
|
|
1044
|
+
tvfEntries.push({ sql: fn.sql, filePath: tvfFilePath, fieldName: fn.fieldName, description: fn.description });
|
|
1045
|
+
// Add function SQL to output BEFORE the view
|
|
1046
|
+
sRet += fn.sql + '\n' + this._dbProvider.BatchSeparator + '\n';
|
|
1047
|
+
}
|
|
1022
1048
|
}
|
|
1023
1049
|
}
|
|
1024
1050
|
// Generate the base view (which may reference the TVFs created above)
|
|
@@ -1032,7 +1058,7 @@ export class SQLCodeGenBase {
|
|
|
1032
1058
|
if (options.writeFiles) {
|
|
1033
1059
|
for (const tvf of tvfEntries) {
|
|
1034
1060
|
this.writeFileIfChanged(tvf.filePath, tvf.sql);
|
|
1035
|
-
this.logSQLForNewOrModifiedEntity(options.entity, tvf.sql,
|
|
1061
|
+
this.logSQLForNewOrModifiedEntity(options.entity, tvf.sql, tvf.description, options.enableSQLLoggingForNewOrModifiedEntities, baseViewChanged);
|
|
1036
1062
|
files.push(tvf.filePath);
|
|
1037
1063
|
}
|
|
1038
1064
|
}
|
|
@@ -1324,13 +1350,73 @@ export class SQLCodeGenBase {
|
|
|
1324
1350
|
const indexStatements = this._dbProvider.generateForeignKeyIndexes(entity);
|
|
1325
1351
|
return indexStatements.join('\n\n');
|
|
1326
1352
|
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Generates the composite index covering the entity's SOFT primary key. Empty for every
|
|
1355
|
+
* entity with a real `PRIMARY KEY` constraint, which is nearly all of them.
|
|
1356
|
+
*
|
|
1357
|
+
* Kept separate from {@link generateIndexesForForeignKeys} and gated by its own setting: a
|
|
1358
|
+
* soft-PK index serves MJ's own per-record existence check on the create path, which is a
|
|
1359
|
+
* different concern from indexing foreign keys for joins and filters, and an operator's
|
|
1360
|
+
* opinion about one is not an opinion about the other.
|
|
1361
|
+
*/
|
|
1362
|
+
generateIndexForSoftPrimaryKey(entity) {
|
|
1363
|
+
const indexStatements = this._dbProvider.generateSoftPrimaryKeyIndex(entity);
|
|
1364
|
+
return indexStatements.join('\n\n');
|
|
1365
|
+
}
|
|
1327
1366
|
/**
|
|
1328
1367
|
* Detects self-referential foreign keys in an entity (e.g., ParentTaskID pointing back to Task table)
|
|
1329
1368
|
* Returns array of field info objects representing recursive relationships
|
|
1330
1369
|
*/
|
|
1331
1370
|
detectRecursiveForeignKeys(entity) {
|
|
1332
|
-
|
|
1333
|
-
UUIDsEqual(field.RelatedEntityID, entity.ID)
|
|
1371
|
+
const hierarchyFKs = entity.Fields.filter(field => field.RelatedEntityID != null &&
|
|
1372
|
+
UUIDsEqual(field.RelatedEntityID, entity.ID) &&
|
|
1373
|
+
!field.IsVirtual &&
|
|
1374
|
+
field.IsHierarchy === true);
|
|
1375
|
+
if (hierarchyFKs.length === 0) {
|
|
1376
|
+
return [];
|
|
1377
|
+
}
|
|
1378
|
+
if (entity.PrimaryKeys.length !== 1) {
|
|
1379
|
+
logWarning(`[Hierarchy] Entity '${entity.Name}' has ${hierarchyFKs.length} hierarchy foreign key(s) ` +
|
|
1380
|
+
`(${hierarchyFKs.map(f => f.Name).join(', ')}), but has ${entity.PrimaryKeys.length} primary key fields. ` +
|
|
1381
|
+
`MemberJunction hierarchy TVF generation and traversal require a single-column primary key. Skipping hierarchy generation for this entity.`);
|
|
1382
|
+
return [];
|
|
1383
|
+
}
|
|
1384
|
+
return hierarchyFKs;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Helper to get the canonical hierarchy function definitions and metadata for an entity and recursive FK field.
|
|
1388
|
+
*/
|
|
1389
|
+
getHierarchyFunctionsForField(entity, field) {
|
|
1390
|
+
const metaFnName = this._dbProvider.getHierarchyMetaFunctionName(entity, field);
|
|
1391
|
+
const descFnName = this._dbProvider.getDescendantsFunctionName(entity, field);
|
|
1392
|
+
const ancFnName = this._dbProvider.getAncestorsFunctionName(entity, field);
|
|
1393
|
+
const rootFnName = this._dbProvider.getRootIDFunctionName(entity, field);
|
|
1394
|
+
return [
|
|
1395
|
+
{
|
|
1396
|
+
functionName: metaFnName,
|
|
1397
|
+
sql: this.generateSingleEntitySQLFileHeader(entity, metaFnName) + this._dbProvider.generateHierarchyMetaFunction(entity, field),
|
|
1398
|
+
description: `Hierarchy Metadata Function SQL for ${entity.Name}.${field.Name}`,
|
|
1399
|
+
fieldName: field.Name
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
functionName: descFnName,
|
|
1403
|
+
sql: this.generateSingleEntitySQLFileHeader(entity, descFnName) + this._dbProvider.generateDescendantsFunction(entity, field),
|
|
1404
|
+
description: `Descendants Traversal Function SQL for ${entity.Name}.${field.Name}`,
|
|
1405
|
+
fieldName: field.Name
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
functionName: ancFnName,
|
|
1409
|
+
sql: this.generateSingleEntitySQLFileHeader(entity, ancFnName) + this._dbProvider.generateAncestorsFunction(entity, field),
|
|
1410
|
+
description: `Ancestors Traversal Function SQL for ${entity.Name}.${field.Name}`,
|
|
1411
|
+
fieldName: field.Name
|
|
1412
|
+
},
|
|
1413
|
+
{
|
|
1414
|
+
functionName: rootFnName,
|
|
1415
|
+
sql: this.generateSingleEntitySQLFileHeader(entity, rootFnName) + this._dbProvider.generateRootIDFunction(entity, field),
|
|
1416
|
+
description: `Root ID Function SQL for ${entity.Name}.${field.Name}`,
|
|
1417
|
+
fieldName: field.Name
|
|
1418
|
+
}
|
|
1419
|
+
];
|
|
1334
1420
|
}
|
|
1335
1421
|
/**
|
|
1336
1422
|
* Generates an inline Table Value Function for calculating root ID for a recursive FK field
|
|
@@ -1353,37 +1439,48 @@ export class SQLCodeGenBase {
|
|
|
1353
1439
|
.join('\n');
|
|
1354
1440
|
}
|
|
1355
1441
|
/**
|
|
1356
|
-
* Generates the SELECT clause additions for
|
|
1357
|
-
*
|
|
1442
|
+
* Generates the SELECT clause additions for hierarchy metadata fields from TVFs
|
|
1443
|
+
* Projects: Root<Field>, <Field>Depth, <Field>Path, <Field>IsLeaf, <Field>ChildCount
|
|
1358
1444
|
*/
|
|
1359
|
-
|
|
1445
|
+
generateHierarchyFieldSelects(entity, recursiveFKs, classNameFirstChar) {
|
|
1360
1446
|
if (recursiveFKs.length === 0)
|
|
1361
1447
|
return '';
|
|
1362
1448
|
let sOutput = '';
|
|
1363
1449
|
for (let i = 0; i < recursiveFKs.length; i++) {
|
|
1364
1450
|
const field = recursiveFKs[i];
|
|
1365
|
-
const alias = `
|
|
1366
|
-
sOutput += `,\n ${this._dbProvider.
|
|
1451
|
+
const alias = `hier_${field.Name}`;
|
|
1452
|
+
sOutput += `,\n ${this._dbProvider.generateHierarchyFieldSelect(entity, field, alias)}`;
|
|
1367
1453
|
}
|
|
1368
1454
|
return sOutput;
|
|
1369
1455
|
}
|
|
1370
1456
|
/**
|
|
1371
|
-
* Generates
|
|
1372
|
-
* Each recursive FK gets an OUTER APPLY that calls its corresponding function
|
|
1457
|
+
* Generates JOIN clauses to inline Table Value Functions for hierarchy metadata calculation
|
|
1373
1458
|
*/
|
|
1374
|
-
|
|
1459
|
+
generateHierarchyJoins(recursiveFKs, classNameFirstChar, entity) {
|
|
1375
1460
|
if (recursiveFKs.length === 0)
|
|
1376
1461
|
return '';
|
|
1377
1462
|
let sOutput = '';
|
|
1378
1463
|
for (let i = 0; i < recursiveFKs.length; i++) {
|
|
1379
1464
|
const field = recursiveFKs[i];
|
|
1380
|
-
const alias = `
|
|
1465
|
+
const alias = `hier_${field.Name}`;
|
|
1381
1466
|
if (sOutput.length > 0)
|
|
1382
1467
|
sOutput += '\n';
|
|
1383
|
-
sOutput += this._dbProvider.
|
|
1468
|
+
sOutput += this._dbProvider.generateHierarchyFieldJoin(entity, field, alias);
|
|
1384
1469
|
}
|
|
1385
1470
|
return '\n' + sOutput;
|
|
1386
1471
|
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Generates the SELECT clause additions for root and hierarchy fields from TVFs
|
|
1474
|
+
*/
|
|
1475
|
+
generateRootFieldSelects(entity, recursiveFKs, classNameFirstChar) {
|
|
1476
|
+
return this.generateHierarchyFieldSelects(entity, recursiveFKs, classNameFirstChar);
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Generates joins to inline Table Value Functions for hierarchy and root ID calculation
|
|
1480
|
+
*/
|
|
1481
|
+
generateRootIDJoins(recursiveFKs, classNameFirstChar, entity) {
|
|
1482
|
+
return this.generateHierarchyJoins(recursiveFKs, classNameFirstChar, entity);
|
|
1483
|
+
}
|
|
1387
1484
|
/**
|
|
1388
1485
|
* @deprecated Use generateRootIDJoins instead - kept for backward compatibility during migration
|
|
1389
1486
|
* Generates LEFT OUTER JOINs to the recursive CTEs
|
|
@@ -1539,6 +1636,12 @@ export class SQLCodeGenBase {
|
|
|
1539
1636
|
const refreshSQL = this._dbProvider.generateViewRefreshSQL(entity.SchemaName, entity.BaseView);
|
|
1540
1637
|
sOutput += this.guardOnApplicationOwnedView(entity, refreshSQL) + separator;
|
|
1541
1638
|
}
|
|
1639
|
+
if (entity.HasLayeredBaseView && !entity.VirtualEntity) {
|
|
1640
|
+
const rebindSQL = this._dbProvider.generateLayeredOuterRebindSQL(entity);
|
|
1641
|
+
if (rebindSQL.trim().length > 0) {
|
|
1642
|
+
sOutput += this.guardOnApplicationOwnedView(entity, rebindSQL.trim()) + separator;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1542
1645
|
return sOutput + permissionsHeader + this.guardOnApplicationOwnedView(entity, permissionsBody) + separator;
|
|
1543
1646
|
}
|
|
1544
1647
|
/**
|
|
@@ -1891,6 +1994,9 @@ export class SQLCodeGenBase {
|
|
|
1891
1994
|
const md = new Metadata(); // global-provider-ok: codegen runs offline against a single provider
|
|
1892
1995
|
// Find all fields in other entities that are foreign keys to this entity
|
|
1893
1996
|
for (const e of md.Entities) {
|
|
1997
|
+
if (!shouldEmitCascadeForRelatedEntity(entity.SchemaName, e.SchemaName, configInfo.allowCrossSchemaCascadeDeletes === true)) {
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
1894
2000
|
for (const ef of e.Fields) {
|
|
1895
2001
|
if (UUIDsEqual(ef.RelatedEntityID, entity.ID) && ef.IsVirtual === false) {
|
|
1896
2002
|
const cascadeSql = await this.generateSingleCascadeOperation(entity, e, ef, pool);
|
|
@@ -2001,6 +2107,9 @@ export class SQLCodeGenBase {
|
|
|
2001
2107
|
const md = new Metadata(); // global-provider-ok: codegen runs offline against a single provider
|
|
2002
2108
|
// Find all fields in other entities that are foreign keys to this entity
|
|
2003
2109
|
for (const e of md.Entities) {
|
|
2110
|
+
if (!shouldEmitCascadeForRelatedEntity(entity.SchemaName, e.SchemaName, configInfo.allowCrossSchemaCascadeDeletes === true)) {
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2004
2113
|
for (const ef of e.Fields) {
|
|
2005
2114
|
if (UUIDsEqual(ef.RelatedEntityID, entity.ID) && ef.IsVirtual === false) {
|
|
2006
2115
|
// Skip self-referential foreign keys (e.g., ParentID pointing to same entity)
|