@memberjunction/codegen-lib 6.2.0-edge.5 → 6.2.0-edge.7
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/README.md +1 -0
- package/dist/Angular/angular-codegen.d.ts +12 -1
- package/dist/Angular/angular-codegen.d.ts.map +1 -1
- package/dist/Angular/angular-codegen.js +36 -1
- package/dist/Angular/angular-codegen.js.map +1 -1
- package/dist/Config/config.d.ts +301 -0
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +188 -84
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.d.ts +101 -4
- package/dist/Database/codeGenDatabaseProvider.d.ts.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.js +170 -4
- package/dist/Database/codeGenDatabaseProvider.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +379 -24
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +1021 -237
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/materializationAnalysis.d.ts +18 -4
- package/dist/Database/materializationAnalysis.d.ts.map +1 -1
- package/dist/Database/materializationAnalysis.js +113 -99
- package/dist/Database/materializationAnalysis.js.map +1 -1
- package/dist/Database/materializationBroadRender.d.ts +7 -3
- package/dist/Database/materializationBroadRender.d.ts.map +1 -1
- package/dist/Database/materializationBroadRender.js +89 -56
- package/dist/Database/materializationBroadRender.js.map +1 -1
- package/dist/Database/materializationParamClassifier.d.ts +1 -1
- package/dist/Database/materializationParamClassifier.js +2 -2
- package/dist/Database/materializationParamVerifier.d.ts +1 -1
- package/dist/Database/materializationParamVerifier.d.ts.map +1 -1
- package/dist/Database/materializationParamVerifier.js +127 -221
- package/dist/Database/materializationParamVerifier.js.map +1 -1
- package/dist/Database/materializationSqlAst.d.ts +107 -79
- package/dist/Database/materializationSqlAst.d.ts.map +1 -1
- package/dist/Database/materializationSqlAst.js +307 -134
- package/dist/Database/materializationSqlAst.js.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts +25 -5
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js +135 -26
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.js +9 -5
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.js.map +1 -1
- package/dist/Database/providers/postgresql/metadataSupportObjects.js +289 -90
- package/dist/Database/providers/postgresql/metadataSupportObjects.js.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts +48 -12
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js +146 -54
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.js +66 -0
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.js.map +1 -1
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.d.ts +47 -0
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.js +167 -0
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.js.map +1 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.d.ts +31 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.js +116 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.js.map +1 -0
- package/dist/Database/queryRebindPass.d.ts +37 -0
- package/dist/Database/queryRebindPass.d.ts.map +1 -0
- package/dist/Database/queryRebindPass.js +110 -0
- package/dist/Database/queryRebindPass.js.map +1 -0
- package/dist/Database/schema-scope.d.ts +12 -0
- package/dist/Database/schema-scope.d.ts.map +1 -1
- package/dist/Database/schema-scope.js +15 -0
- package/dist/Database/schema-scope.js.map +1 -1
- package/dist/Database/sql.d.ts +13 -0
- package/dist/Database/sql.d.ts.map +1 -1
- package/dist/Database/sql.js +39 -8
- package/dist/Database/sql.js.map +1 -1
- package/dist/Database/sql_codegen.d.ts +212 -6
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +765 -63
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Misc/advanced_generation.d.ts +129 -5
- package/dist/Misc/advanced_generation.d.ts.map +1 -1
- package/dist/Misc/advanced_generation.js +212 -8
- package/dist/Misc/advanced_generation.js.map +1 -1
- package/dist/Misc/display-name-heuristics.d.ts +57 -0
- package/dist/Misc/display-name-heuristics.d.ts.map +1 -0
- package/dist/Misc/display-name-heuristics.js +97 -0
- package/dist/Misc/display-name-heuristics.js.map +1 -0
- package/dist/Misc/entity_subclasses_codegen.d.ts +31 -3
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.js +79 -17
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
- package/dist/Misc/remote_operations_codegen.d.ts.map +1 -1
- package/dist/Misc/remote_operations_codegen.js +21 -4
- package/dist/Misc/remote_operations_codegen.js.map +1 -1
- package/dist/Misc/sql_logging.d.ts +12 -0
- package/dist/Misc/sql_logging.d.ts.map +1 -1
- package/dist/Misc/sql_logging.js +21 -8
- package/dist/Misc/sql_logging.js.map +1 -1
- package/dist/Misc/system_integrity.d.ts +48 -0
- package/dist/Misc/system_integrity.d.ts.map +1 -1
- package/dist/Misc/system_integrity.js +151 -75
- package/dist/Misc/system_integrity.js.map +1 -1
- package/dist/Misc/validator-text.d.ts +17 -0
- package/dist/Misc/validator-text.d.ts.map +1 -1
- package/dist/Misc/validator-text.js +59 -0
- package/dist/Misc/validator-text.js.map +1 -1
- package/dist/runCodeGen.d.ts +37 -3
- package/dist/runCodeGen.d.ts.map +1 -1
- package/dist/runCodeGen.js +161 -51
- package/dist/runCodeGen.js.map +1 -1
- package/package.json +29 -29
|
@@ -40,7 +40,9 @@ function section(header) {
|
|
|
40
40
|
describe('spUpdateExistingEntitiesFromSchema — planner statistics for its own working tables', () => {
|
|
41
41
|
const body = section('-- 4. spUpdateExistingEntitiesFromSchema');
|
|
42
42
|
it('materialises vwSQLTablesAndEntities into an ANALYZEd temp table', () => {
|
|
43
|
-
|
|
43
|
+
// Created once per session and refilled (see the temp-table lifecycle note in the DDL).
|
|
44
|
+
expect(body).toContain('CREATE TEMP TABLE IF NOT EXISTS _ues_tables AS SELECT * FROM __mj."vwSQLTablesAndEntities" WITH NO DATA');
|
|
45
|
+
expect(body).toContain('INSERT INTO _ues_tables SELECT * FROM __mj."vwSQLTablesAndEntities";');
|
|
44
46
|
expect(body).toContain('ANALYZE _ues_tables;');
|
|
45
47
|
});
|
|
46
48
|
it('no longer joins the introspection view directly', () => {
|
|
@@ -51,9 +53,10 @@ describe('spUpdateExistingEntitiesFromSchema — planner statistics for its own
|
|
|
51
53
|
expect(body).toContain('ANALYZE _ues_filtered;');
|
|
52
54
|
expect(body.indexOf('ANALYZE _ues_filtered;')).toBeLessThan(body.indexOf('UPDATE __mj."Entity" tgt SET'));
|
|
53
55
|
});
|
|
54
|
-
it('
|
|
56
|
+
it('empties every temp table it uses, and never drops one (a dropped table strands the cached plan)', () => {
|
|
55
57
|
for (const t of ['_ues_filtered', '_ues_tables', '_ues_included']) {
|
|
56
|
-
expect(body).toContain(`
|
|
58
|
+
expect(body).toContain(`TRUNCATE ${t};`);
|
|
59
|
+
expect(body).not.toContain(`DROP TABLE IF EXISTS ${t};`);
|
|
57
60
|
}
|
|
58
61
|
});
|
|
59
62
|
});
|
|
@@ -65,14 +68,15 @@ describe('spDeleteUnneededEntityFields — the base-view exclusion interlock', (
|
|
|
65
68
|
expect(body).toContain('DROP FUNCTION IF EXISTS __mj."spDeleteUnneededEntityFields"(TEXT, TEXT, TEXT, TEXT);');
|
|
66
69
|
});
|
|
67
70
|
it('splits the list case-insensitively and trims each entry', () => {
|
|
68
|
-
expect(body).toContain('
|
|
71
|
+
expect(body).toContain('INSERT INTO _del_protected (field_name)');
|
|
72
|
+
expect(body).toContain('SELECT LOWER(TRIM(s))');
|
|
69
73
|
expect(body).toContain("unnest(string_to_array(COALESCE(p_ProtectedFieldNames, ''), ','))");
|
|
70
74
|
});
|
|
71
75
|
it('excludes protected names from the candidate set, so they can never reach the DELETE', () => {
|
|
72
76
|
expect(body).toContain('NOT IN (SELECT pr.field_name FROM _del_protected pr)');
|
|
73
77
|
// The filter belongs on the CANDIDATE build (_del_ef), not on the delete — anything that
|
|
74
78
|
// reaches _del_deleted is also returned to the caller as "deleted".
|
|
75
|
-
const candidateBuild = body.slice(body.indexOf('
|
|
79
|
+
const candidateBuild = body.slice(body.indexOf('INSERT INTO _del_ef ('), body.indexOf('ANALYZE _del_ef;'));
|
|
76
80
|
expect(candidateBuild).toContain('_del_protected');
|
|
77
81
|
});
|
|
78
82
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetadataSupportObjectsDDL.test.js","sourceRoot":"","sources":["../../../../../src/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAE3E,MAAM,GAAG,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC;AAEnD,mGAAmG;AACnG,SAAS,OAAO,CAAC,MAAc;IAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,KAAK,EAAE,sBAAsB,MAAM,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAClE,0DAA0D;IAC1D,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,wFAAwF,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1I,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,QAAQ,CAAC,oFAAoF,EAAE,GAAG,EAAE;IAChG,MAAM,IAAI,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;IAEjE,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACvE,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"MetadataSupportObjectsDDL.test.js","sourceRoot":"","sources":["../../../../../src/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAE3E,MAAM,GAAG,GAAG,8BAA8B,CAAC,MAAM,CAAC,CAAC;AAEnD,mGAAmG;AACnG,SAAS,OAAO,CAAC,MAAc;IAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,CAAC,KAAK,EAAE,sBAAsB,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AG,CAAC,SAAS,CAAC,kDAAkD,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,gCAAgC,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -29,8 +29,9 @@ export function buildMetadataSupportObjectsSQL(mjCoreSchema) {
|
|
|
29
29
|
}
|
|
30
30
|
const METADATA_SUPPORT_OBJECTS_DDL = String.raw `
|
|
31
31
|
-- ----------------------------------------------------------------------------
|
|
32
|
-
-- 0. Drop the view first — it depends on fnMapPGDefaultToMJ
|
|
33
|
-
-- the helper DROPs below would otherwise fail with a
|
|
32
|
+
-- 0. Drop the view first — it depends on fnMapPGDefaultToMJ and fnSafePGGetExpr,
|
|
33
|
+
-- so on re-apply the helper DROPs below would otherwise fail with a
|
|
34
|
+
-- dependency error.
|
|
34
35
|
-- ----------------------------------------------------------------------------
|
|
35
36
|
DROP VIEW IF EXISTS __mj."vwSQLColumnsAndEntityFields";
|
|
36
37
|
|
|
@@ -38,6 +39,48 @@ DROP VIEW IF EXISTS __mj."vwSQLColumnsAndEntityFields";
|
|
|
38
39
|
-- 1. Default-value helpers
|
|
39
40
|
-- ----------------------------------------------------------------------------
|
|
40
41
|
|
|
42
|
+
-- Crash-safe wrapper around pg_get_expr(). pg_get_expr() does not just read a
|
|
43
|
+
-- catalog row: it OPENS the relation named by adrelid so it can resolve column
|
|
44
|
+
-- references while rendering the expression. CodeGen races its OWN object
|
|
45
|
+
-- regeneration — a relation can be dropped between the catalog scan that
|
|
46
|
+
-- produced the row and the moment the expression is rendered — and the open
|
|
47
|
+
-- then fails with "could not open relation with OID <n>", which aborts the
|
|
48
|
+
-- whole statement and kills the entire CodeGen run. Of the four catalog views
|
|
49
|
+
-- this file's routines consume, only vwSQLColumnsAndEntityFields calls
|
|
50
|
+
-- pg_get_expr (the FK/PK/unique-key views do not), and col_description() cannot
|
|
51
|
+
-- raise this error because it only reads pg_description — so these two call
|
|
52
|
+
-- sites are the only place a mid-run DROP can abort the introspection.
|
|
53
|
+
--
|
|
54
|
+
-- STRICT IS LOAD-BEARING, DO NOT REMOVE IT. A STRICT function returns NULL for
|
|
55
|
+
-- a NULL argument WITHOUT ENTERING THE BODY. ad.adbin is NULL for every column
|
|
56
|
+
-- that has no default — the overwhelming majority — so those rows never reach
|
|
57
|
+
-- the EXCEPTION block and therefore never open a subtransaction. A non-STRICT
|
|
58
|
+
-- wrapper would open one subtransaction PER COLUMN (PL/pgSQL enters a
|
|
59
|
+
-- subtransaction whenever it executes a block with an EXCEPTION clause), which
|
|
60
|
+
-- is not an acceptable cost on the hot path of a procedure that is already
|
|
61
|
+
-- O(N^2) in schema size. The guard must also never blank out a legitimate
|
|
62
|
+
-- default: on success it returns pg_get_expr's own result unchanged, so a
|
|
63
|
+
-- healthy schema renders exactly the same DefaultValue set as before.
|
|
64
|
+
--
|
|
65
|
+
-- WHEN OTHERS is deliberately broad: the underlying failure is an elog() inside
|
|
66
|
+
-- relation_open, which carries the generic internal-error SQLSTATE (XX000), so a
|
|
67
|
+
-- narrower handler would buy nothing. PL/pgSQL's OTHERS still does not trap
|
|
68
|
+
-- query_canceled or assert_failure, so statement_timeout and cancellation
|
|
69
|
+
-- continue to propagate normally.
|
|
70
|
+
DROP FUNCTION IF EXISTS __mj."fnSafePGGetExpr"(pg_node_tree, oid);
|
|
71
|
+
CREATE OR REPLACE FUNCTION __mj."fnSafePGGetExpr"(p_expr pg_node_tree, p_relid oid)
|
|
72
|
+
RETURNS TEXT
|
|
73
|
+
LANGUAGE plpgsql STABLE STRICT AS $$
|
|
74
|
+
BEGIN
|
|
75
|
+
RETURN pg_get_expr(p_expr, p_relid);
|
|
76
|
+
EXCEPTION WHEN OTHERS THEN
|
|
77
|
+
-- The relation vanished mid-render (or is otherwise unreadable right now).
|
|
78
|
+
-- A missing default is recoverable — the next CodeGen run re-reads it — but
|
|
79
|
+
-- an aborted statement is not.
|
|
80
|
+
RETURN NULL;
|
|
81
|
+
END;
|
|
82
|
+
$$;
|
|
83
|
+
|
|
41
84
|
-- Normalizer used ONLY for change detection. Collapses formatting variance
|
|
42
85
|
-- (paren wrapping, N-prefix, ::casts, current-timestamp function family, uuid
|
|
43
86
|
-- generator family, numeric trailing zeros) so cosmetic differences never
|
|
@@ -177,8 +220,11 @@ SELECT
|
|
|
177
220
|
CASE WHEN COALESCE(bt_a.attgenerated, '') <> '' THEN 1 ELSE 0 END AS "IsComputed",
|
|
178
221
|
src_cls.oid AS object_id,
|
|
179
222
|
NULL::text AS "DefaultConstraintName",
|
|
180
|
-
|
|
181
|
-
|
|
223
|
+
-- both expression renders go through fnSafePGGetExpr (see section 1): a relation
|
|
224
|
+
-- dropped by CodeGen's own concurrent regeneration must yield NULL for that one
|
|
225
|
+
-- column, not abort the statement and with it the run.
|
|
226
|
+
__mj."fnMapPGDefaultToMJ"(__mj."fnSafePGGetExpr"(ad.adbin, ad.adrelid)) AS "DefaultValue",
|
|
227
|
+
CASE WHEN COALESCE(bt_a.attgenerated, '') <> '' THEN __mj."fnSafePGGetExpr"(ad.adbin, ad.adrelid) ELSE NULL END AS "ComputedColumnDefinition",
|
|
182
228
|
COALESCE(col_description(src_cls.oid, a.attnum::integer), col_description(bt_cls.oid, bt_a.attnum::integer)) AS "Description",
|
|
183
229
|
col_description(src_cls.oid, a.attnum::integer) AS "ViewColumnDescription",
|
|
184
230
|
CASE WHEN bt_a.attnum IS NOT NULL THEN col_description(bt_cls.oid, bt_a.attnum::integer) ELSE NULL END AS "TableColumnDescription"
|
|
@@ -244,22 +290,46 @@ BEGIN
|
|
|
244
290
|
-- needs no ANALYZE privileges on pg_catalog.
|
|
245
291
|
SET LOCAL enable_nestloop = off;
|
|
246
292
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
293
|
+
-- ==========================================================================
|
|
294
|
+
-- TEMP-TABLE LIFECYCLE: CREATE-ONCE + TRUNCATE. DO NOT REINTRODUCE
|
|
295
|
+
-- "DROP TABLE IF EXISTS x; CREATE TEMP TABLE x AS ...".
|
|
296
|
+
--
|
|
297
|
+
-- PL/pgSQL plan-caches every static SQL statement in this body for the life
|
|
298
|
+
-- of the SESSION, and those cached plans reference each temp table by its
|
|
299
|
+
-- relation OID. Dropping a temp table at the end of a call and re-creating it
|
|
300
|
+
-- on the next call through the SAME pooled connection hands the next call a
|
|
301
|
+
-- cached plan pointing at the OID of a relation that no longer exists, and the
|
|
302
|
+
-- routine dies with "could not open relation with OID <n>". It is intermittent
|
|
303
|
+
-- precisely because it depends on whether the pool hands back a connection
|
|
304
|
+
-- this routine has already run on.
|
|
305
|
+
--
|
|
306
|
+
-- Creating each table ONCE per session and TRUNCATE-ing it around each use
|
|
307
|
+
-- keeps the OID stable forever, so no cached plan can ever go stale, while
|
|
308
|
+
-- TRUNCATE still hands the storage back between calls. Crucially it leaves
|
|
309
|
+
-- every downstream statement (the reconciliation join, both UPDATEs, the
|
|
310
|
+
-- RETURN QUERY) textually unchanged, and — the reason dynamic SQL was
|
|
311
|
+
-- rejected — it PRESERVES THE ANALYZE CALLS below, which are load-bearing for
|
|
312
|
+
-- the planner in a routine that is already O(N^2) in schema size.
|
|
313
|
+
-- ==========================================================================
|
|
314
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_excluded (schema_name TEXT);
|
|
315
|
+
TRUNCATE _uef_excluded;
|
|
316
|
+
INSERT INTO _uef_excluded (schema_name)
|
|
317
|
+
SELECT TRIM(s)
|
|
250
318
|
FROM unnest(string_to_array(COALESCE(p_ExcludedSchemaNames, ''), ',')) AS s
|
|
251
319
|
WHERE TRIM(s) <> '';
|
|
252
320
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
321
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_included (schema_name TEXT);
|
|
322
|
+
TRUNCATE _uef_included;
|
|
323
|
+
INSERT INTO _uef_included (schema_name)
|
|
324
|
+
SELECT TRIM(s)
|
|
256
325
|
FROM unnest(string_to_array(COALESCE(p_IncludedSchemaNames, ''), ',')) AS s
|
|
257
326
|
WHERE TRIM(s) <> '';
|
|
258
327
|
v_has_include := EXISTS (SELECT 1 FROM _uef_included);
|
|
259
328
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
329
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_scope (entity_id UUID);
|
|
330
|
+
TRUNCATE _uef_scope;
|
|
331
|
+
INSERT INTO _uef_scope (entity_id)
|
|
332
|
+
SELECT DISTINCT TRIM(v)::uuid
|
|
263
333
|
FROM unnest(string_to_array(COALESCE(p_EntityIDs, ''), ',')) AS v
|
|
264
334
|
WHERE TRIM(v) ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$';
|
|
265
335
|
v_is_scoped := EXISTS (SELECT 1 FROM _uef_scope);
|
|
@@ -275,24 +345,95 @@ BEGIN
|
|
|
275
345
|
-- codegen adds objects mid-run. Materializing each view exactly once + ANALYZE
|
|
276
346
|
-- gives the planner real cardinalities so the reconciliation join hash-joins
|
|
277
347
|
-- instead of nested-looping.
|
|
278
|
-
|
|
279
|
-
|
|
348
|
+
-- Shape comes from the view itself via WITH NO DATA (which plans the query for
|
|
349
|
+
-- its column types but never runs it), so these four stay in lockstep with the
|
|
350
|
+
-- views automatically. The ANALYZE after each load is the whole point of
|
|
351
|
+
-- materializing and must survive any future rework of this block.
|
|
352
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_cols AS SELECT * FROM __mj."vwSQLColumnsAndEntityFields" WITH NO DATA;
|
|
353
|
+
TRUNCATE _uef_cols;
|
|
354
|
+
INSERT INTO _uef_cols SELECT * FROM __mj."vwSQLColumnsAndEntityFields";
|
|
280
355
|
ANALYZE _uef_cols;
|
|
281
356
|
|
|
282
|
-
|
|
283
|
-
|
|
357
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_fk AS SELECT * FROM __mj."vwForeignKeys" WITH NO DATA;
|
|
358
|
+
TRUNCATE _uef_fk;
|
|
359
|
+
INSERT INTO _uef_fk SELECT * FROM __mj."vwForeignKeys";
|
|
284
360
|
ANALYZE _uef_fk;
|
|
285
361
|
|
|
286
|
-
|
|
287
|
-
|
|
362
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_pk AS SELECT * FROM __mj."vwTablePrimaryKeys" WITH NO DATA;
|
|
363
|
+
TRUNCATE _uef_pk;
|
|
364
|
+
INSERT INTO _uef_pk SELECT * FROM __mj."vwTablePrimaryKeys";
|
|
288
365
|
ANALYZE _uef_pk;
|
|
289
366
|
|
|
290
|
-
|
|
291
|
-
|
|
367
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_uk AS SELECT * FROM __mj."vwTableUniqueKeys" WITH NO DATA;
|
|
368
|
+
TRUNCATE _uef_uk;
|
|
369
|
+
INSERT INTO _uef_uk SELECT * FROM __mj."vwTableUniqueKeys";
|
|
292
370
|
ANALYZE _uef_uk;
|
|
293
371
|
|
|
294
|
-
|
|
295
|
-
|
|
372
|
+
-- Orphan-tolerant renumber (#4050): an EntityField row whose column is no longer in the base
|
|
373
|
+
-- view never joins _uef_cols below, so it is never renumbered and keeps its old Sequence. When
|
|
374
|
+
-- that slot is inside the live column range, the live field that must move onto it collides on
|
|
375
|
+
-- UQ_EntityField_EntityID_Sequence and the whole metadata pass fails. Park such orphans above
|
|
376
|
+
-- the entity's current maximum first; the prune step deletes them later. Orphans already above
|
|
377
|
+
-- the live range are left alone, so repeated runs do not keep moving them.
|
|
378
|
+
UPDATE __mj."EntityField" tgt SET
|
|
379
|
+
"Sequence" = mx.max_sequence + o.rn
|
|
380
|
+
FROM (
|
|
381
|
+
SELECT ef."ID" AS field_id, ef."EntityID" AS entity_id,
|
|
382
|
+
ROW_NUMBER() OVER (PARTITION BY ef."EntityID" ORDER BY ef."Sequence", ef."Name") AS rn
|
|
383
|
+
FROM __mj."EntityField" ef
|
|
384
|
+
INNER JOIN __mj."Entity" e ON e."ID" = ef."EntityID"
|
|
385
|
+
INNER JOIN (SELECT c."EntityID", MAX(c."Sequence") AS live_max FROM _uef_cols c GROUP BY c."EntityID") lm
|
|
386
|
+
ON lm."EntityID" = ef."EntityID"
|
|
387
|
+
LEFT JOIN _uef_excluded ex ON e."SchemaName"::text = ex.schema_name
|
|
388
|
+
WHERE e."VirtualEntity" = FALSE
|
|
389
|
+
AND ex.schema_name IS NULL
|
|
390
|
+
AND (NOT v_has_include OR e."SchemaName"::text IN (SELECT i.schema_name FROM _uef_included i))
|
|
391
|
+
AND (NOT v_is_scoped OR e."ID" IN (SELECT s.entity_id FROM _uef_scope s))
|
|
392
|
+
AND ef."Sequence" <= lm.live_max
|
|
393
|
+
AND NOT EXISTS (
|
|
394
|
+
SELECT 1 FROM _uef_cols c
|
|
395
|
+
WHERE c."EntityID" = ef."EntityID" AND c."FieldName"::text = ef."Name"::text
|
|
396
|
+
)
|
|
397
|
+
) o
|
|
398
|
+
INNER JOIN (SELECT f."EntityID", MAX(f."Sequence") AS max_sequence FROM __mj."EntityField" f GROUP BY f."EntityID") mx
|
|
399
|
+
ON mx."EntityID" = o.entity_id
|
|
400
|
+
WHERE tgt."ID" = o.field_id;
|
|
401
|
+
|
|
402
|
+
-- _uef_filtered is the one temp table whose shape cannot be derived from a
|
|
403
|
+
-- view, so it is declared explicitly rather than duplicating the ~110-line
|
|
404
|
+
-- projection below purely to get its column types. The column list here is
|
|
405
|
+
-- POSITIONAL against that projection: if you add, remove or reorder a column
|
|
406
|
+
-- in the SELECT, change this DDL to match. A mismatch fails the INSERT loudly
|
|
407
|
+
-- (wrong column count, or no assignment cast), it does not silently mis-map.
|
|
408
|
+
CREATE TEMP TABLE IF NOT EXISTS _uef_filtered (
|
|
409
|
+
entity_id UUID,
|
|
410
|
+
entity_name TEXT,
|
|
411
|
+
entity_field_id UUID,
|
|
412
|
+
entity_field_name TEXT,
|
|
413
|
+
auto_update_description BOOLEAN,
|
|
414
|
+
existing_description TEXT,
|
|
415
|
+
sql_description TEXT,
|
|
416
|
+
new_type TEXT,
|
|
417
|
+
new_length INTEGER,
|
|
418
|
+
new_precision INTEGER,
|
|
419
|
+
new_scale INTEGER,
|
|
420
|
+
new_allows_null BOOLEAN,
|
|
421
|
+
new_default_value TEXT,
|
|
422
|
+
new_auto_increment BOOLEAN,
|
|
423
|
+
new_is_virtual BOOLEAN,
|
|
424
|
+
new_is_computed BOOLEAN,
|
|
425
|
+
new_sequence INTEGER,
|
|
426
|
+
related_entity_id UUID,
|
|
427
|
+
related_entity_field_name TEXT,
|
|
428
|
+
new_is_primary_key BOOLEAN,
|
|
429
|
+
new_is_unique BOOLEAN,
|
|
430
|
+
is_isa_inherited BOOLEAN,
|
|
431
|
+
is_material_change BOOLEAN,
|
|
432
|
+
change_reasons TEXT,
|
|
433
|
+
is_sequence_change BOOLEAN
|
|
434
|
+
);
|
|
435
|
+
TRUNCATE _uef_filtered;
|
|
436
|
+
INSERT INTO _uef_filtered
|
|
296
437
|
SELECT * FROM (
|
|
297
438
|
SELECT
|
|
298
439
|
e."ID" AS entity_id,
|
|
@@ -319,6 +460,11 @@ BEGIN
|
|
|
319
460
|
fk."referenced_column"::text AS related_entity_field_name,
|
|
320
461
|
(pk."ColumnName" IS NOT NULL) AS new_is_primary_key,
|
|
321
462
|
(pk."ColumnName" IS NOT NULL OR uk."ColumnName" IS NOT NULL) AS new_is_unique,
|
|
463
|
+
-- IS-A inherited row (#4569): a virtual, updatable field on a child entity, copied from its
|
|
464
|
+
-- parent by manageParentEntityFields. The column lives in the parent's table, so the FK lookup
|
|
465
|
+
-- above (keyed on the child's table) finds nothing; its RelatedEntity* values come from the
|
|
466
|
+
-- parent field and must not be overwritten with NULL here.
|
|
467
|
+
(e."ParentID" IS NOT NULL AND ef."IsVirtual" AND ef."AllowUpdateAPI") AS is_isa_inherited,
|
|
322
468
|
-- is_material_change = a change that actually affects the generated view/sproc SQL. This is the
|
|
323
469
|
-- SINGLE definition of "material" — the row filter (outer WHERE) and the modified-entity RETURN
|
|
324
470
|
-- both derive from it, so there is no duplicated predicate to keep in sync. A pure Sequence
|
|
@@ -338,8 +484,10 @@ BEGIN
|
|
|
338
484
|
OR __mj."fnNormalizeDefaultValue"(ef."DefaultValue") IS DISTINCT FROM __mj."fnNormalizeDefaultValue"(sq."DefaultValue")
|
|
339
485
|
OR ef."AutoIncrement" <> (sq."AutoIncrement" <> 0)
|
|
340
486
|
OR ef."IsVirtual" <> (sq."IsVirtual" <> 0)
|
|
341
|
-
-- Soft-FK guard: preserve soft FKs and respect AutoUpdateRelatedEntityInfo
|
|
342
|
-
|
|
487
|
+
-- Soft-FK guard: preserve soft FKs and respect AutoUpdateRelatedEntityInfo; IS-A inherited
|
|
488
|
+
-- rows keep the relationship copied from the parent field
|
|
489
|
+
OR (ef."AutoUpdateRelatedEntityInfo" AND NOT ef."IsSoftForeignKey"
|
|
490
|
+
AND NOT (e."ParentID" IS NOT NULL AND ef."IsVirtual" AND ef."AllowUpdateAPI") AND (
|
|
343
491
|
COALESCE(ef."RelatedEntityID", '00000000-0000-0000-0000-000000000000'::uuid) <>
|
|
344
492
|
COALESCE(re."ID", '00000000-0000-0000-0000-000000000000'::uuid)
|
|
345
493
|
OR COALESCE(TRIM(ef."RelatedEntityFieldName"), '') <> COALESCE(TRIM(fk."referenced_column"::text), '')
|
|
@@ -363,8 +511,10 @@ BEGIN
|
|
|
363
511
|
CASE WHEN ef."AutoIncrement" <> (sq."AutoIncrement" <> 0) THEN 'AutoIncrement' END,
|
|
364
512
|
CASE WHEN ef."IsVirtual" <> (sq."IsVirtual" <> 0) THEN 'IsVirtual' END,
|
|
365
513
|
CASE WHEN ef."IsComputed" <> (sq."IsComputed" <> 0) THEN 'IsComputed' END,
|
|
366
|
-
CASE WHEN
|
|
367
|
-
|
|
514
|
+
CASE WHEN NOT (e."ParentID" IS NOT NULL AND ef."IsVirtual" AND ef."AllowUpdateAPI")
|
|
515
|
+
AND COALESCE(ef."RelatedEntityID", '00000000-0000-0000-0000-000000000000'::uuid) <> COALESCE(re."ID", '00000000-0000-0000-0000-000000000000'::uuid) THEN 'RelatedEntityID' END,
|
|
516
|
+
CASE WHEN NOT (e."ParentID" IS NOT NULL AND ef."IsVirtual" AND ef."AllowUpdateAPI")
|
|
517
|
+
AND COALESCE(TRIM(ef."RelatedEntityFieldName"), '') <> COALESCE(TRIM(fk."referenced_column"::text), '') THEN 'RelatedEntityFieldName' END,
|
|
368
518
|
CASE WHEN (NOT ef."IsSoftPrimaryKey" AND ef."IsPrimaryKey" <> (pk."ColumnName" IS NOT NULL)) THEN 'IsPrimaryKey' END,
|
|
369
519
|
CASE WHEN (NOT ef."IsSoftPrimaryKey" AND ef."IsUnique" <> (pk."ColumnName" IS NOT NULL OR uk."ColumnName" IS NOT NULL)) THEN 'IsUnique' END,
|
|
370
520
|
CASE WHEN (ef."AllowUpdateAPI" = TRUE AND sq."IsVirtual" <> 0 AND ef."IsVirtual" = FALSE) THEN 'AllowUpdateAPI' END,
|
|
@@ -422,8 +572,8 @@ BEGIN
|
|
|
422
572
|
"IsVirtual" = fr.new_is_virtual,
|
|
423
573
|
"IsComputed" = fr.new_is_computed,
|
|
424
574
|
"Sequence" = fr.new_sequence,
|
|
425
|
-
"RelatedEntityID" = CASE WHEN tgt."AutoUpdateRelatedEntityInfo" AND NOT tgt."IsSoftForeignKey" THEN fr.related_entity_id ELSE tgt."RelatedEntityID" END,
|
|
426
|
-
"RelatedEntityFieldName" = CASE WHEN tgt."AutoUpdateRelatedEntityInfo" AND NOT tgt."IsSoftForeignKey" THEN fr.related_entity_field_name ELSE tgt."RelatedEntityFieldName" END,
|
|
575
|
+
"RelatedEntityID" = CASE WHEN tgt."AutoUpdateRelatedEntityInfo" AND NOT tgt."IsSoftForeignKey" AND NOT fr.is_isa_inherited THEN fr.related_entity_id ELSE tgt."RelatedEntityID" END,
|
|
576
|
+
"RelatedEntityFieldName" = CASE WHEN tgt."AutoUpdateRelatedEntityInfo" AND NOT tgt."IsSoftForeignKey" AND NOT fr.is_isa_inherited THEN fr.related_entity_field_name ELSE tgt."RelatedEntityFieldName" END,
|
|
427
577
|
-- U2 — soft-PK guard: never let the physical-schema sync wipe a soft PK's flags
|
|
428
578
|
"IsPrimaryKey" = CASE WHEN tgt."IsSoftPrimaryKey" THEN tgt."IsPrimaryKey" ELSE fr.new_is_primary_key END,
|
|
429
579
|
"IsUnique" = CASE WHEN tgt."IsSoftPrimaryKey" THEN tgt."IsUnique" ELSE fr.new_is_unique END,
|
|
@@ -449,10 +599,19 @@ BEGIN
|
|
|
449
599
|
-- byte-identical view+sproc regeneration.
|
|
450
600
|
WHERE fr.is_material_change;
|
|
451
601
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
DROP
|
|
455
|
-
|
|
602
|
+
-- Hand the storage back but KEEP the relations (and therefore their OIDs) so
|
|
603
|
+
-- the plans cached above stay valid for the next call on this connection.
|
|
604
|
+
-- These are deliberately TRUNCATE and not DROP — see the lifecycle note above.
|
|
605
|
+
-- The four materialized view snapshots are included: on a large schema they
|
|
606
|
+
-- are the bulk of this routine's temp footprint.
|
|
607
|
+
TRUNCATE _uef_filtered;
|
|
608
|
+
TRUNCATE _uef_cols;
|
|
609
|
+
TRUNCATE _uef_fk;
|
|
610
|
+
TRUNCATE _uef_pk;
|
|
611
|
+
TRUNCATE _uef_uk;
|
|
612
|
+
TRUNCATE _uef_scope;
|
|
613
|
+
TRUNCATE _uef_excluded;
|
|
614
|
+
TRUNCATE _uef_included;
|
|
456
615
|
END;
|
|
457
616
|
$func$;
|
|
458
617
|
|
|
@@ -478,9 +637,17 @@ LANGUAGE plpgsql AS $func$
|
|
|
478
637
|
DECLARE
|
|
479
638
|
v_has_include BOOLEAN := FALSE;
|
|
480
639
|
BEGIN
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
640
|
+
-- TEMP-TABLE LIFECYCLE: CREATE-ONCE + TRUNCATE, exactly as in
|
|
641
|
+
-- spUpdateExistingEntityFieldsFromSchema (see the full note there). Never
|
|
642
|
+
-- "DROP TABLE IF EXISTS x; CREATE TEMP TABLE x AS ...": on a reused pooled
|
|
643
|
+
-- connection PL/pgSQL's session-lifetime plan cache still holds the dropped
|
|
644
|
+
-- relation's OID and the call aborts with "could not open relation with OID
|
|
645
|
+
-- <n>". Creating each table once per session keeps its OID stable, and keeps
|
|
646
|
+
-- the ANALYZE calls below, which the planner needs on a large schema.
|
|
647
|
+
CREATE TEMP TABLE IF NOT EXISTS _ues_included (schema_name TEXT);
|
|
648
|
+
TRUNCATE _ues_included;
|
|
649
|
+
INSERT INTO _ues_included (schema_name)
|
|
650
|
+
SELECT TRIM(s)
|
|
484
651
|
FROM unnest(string_to_array(COALESCE(p_IncludedSchemaNames, ''), ',')) AS s
|
|
485
652
|
WHERE TRIM(s) <> '';
|
|
486
653
|
v_has_include := EXISTS (SELECT 1 FROM _ues_included);
|
|
@@ -492,19 +659,28 @@ BEGIN
|
|
|
492
659
|
-- spUpdateExistingEntityFieldsFromSchema and spDeleteUnneededEntityFields (materialise the
|
|
493
660
|
-- introspection view exactly once, then ANALYZE so the reconciliation join hash-joins);
|
|
494
661
|
-- this proc was the one that kept joining the view directly.
|
|
495
|
-
|
|
496
|
-
|
|
662
|
+
CREATE TEMP TABLE IF NOT EXISTS _ues_tables AS SELECT * FROM __mj."vwSQLTablesAndEntities" WITH NO DATA;
|
|
663
|
+
TRUNCATE _ues_tables;
|
|
664
|
+
INSERT INTO _ues_tables SELECT * FROM __mj."vwSQLTablesAndEntities";
|
|
497
665
|
ANALYZE _ues_tables;
|
|
498
666
|
|
|
499
|
-
|
|
500
|
-
|
|
667
|
+
CREATE TEMP TABLE IF NOT EXISTS _ues_filtered (
|
|
668
|
+
entity_id UUID,
|
|
669
|
+
entity_name TEXT,
|
|
670
|
+
current_description TEXT,
|
|
671
|
+
new_description TEXT,
|
|
672
|
+
entity_description TEXT,
|
|
673
|
+
schema_name TEXT
|
|
674
|
+
);
|
|
675
|
+
TRUNCATE _ues_filtered;
|
|
676
|
+
INSERT INTO _ues_filtered (entity_id, entity_name, current_description, new_description, entity_description, schema_name)
|
|
501
677
|
SELECT
|
|
502
|
-
e."ID"
|
|
503
|
-
e."Name"
|
|
504
|
-
e."Description"
|
|
505
|
-
CASE WHEN e."AutoUpdateDescription" THEN sq."EntityDescription" ELSE e."Description" END
|
|
506
|
-
sq."EntityDescription"
|
|
507
|
-
sq."SchemaName"::text
|
|
678
|
+
e."ID",
|
|
679
|
+
e."Name",
|
|
680
|
+
e."Description",
|
|
681
|
+
CASE WHEN e."AutoUpdateDescription" THEN sq."EntityDescription" ELSE e."Description" END,
|
|
682
|
+
sq."EntityDescription",
|
|
683
|
+
sq."SchemaName"::text
|
|
508
684
|
FROM __mj."Entity" e
|
|
509
685
|
INNER JOIN _ues_tables sq ON e."ID" = sq."EntityID"
|
|
510
686
|
LEFT JOIN unnest(string_to_array(COALESCE(p_ExcludedSchemaNames, ''), ',')) AS ex(v)
|
|
@@ -530,9 +706,11 @@ BEGIN
|
|
|
530
706
|
fr.new_description::text, fr.entity_description::text, fr.schema_name
|
|
531
707
|
FROM _ues_filtered fr;
|
|
532
708
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
709
|
+
-- Hand the storage back but KEEP the relations (and their OIDs) so the plans
|
|
710
|
+
-- cached above stay valid for the next call on this connection.
|
|
711
|
+
TRUNCATE _ues_filtered;
|
|
712
|
+
TRUNCATE _ues_tables;
|
|
713
|
+
TRUNCATE _ues_included;
|
|
536
714
|
END;
|
|
537
715
|
$func$;
|
|
538
716
|
|
|
@@ -580,16 +758,22 @@ BEGIN
|
|
|
580
758
|
-- managed PostgreSQL).
|
|
581
759
|
SET LOCAL enable_nestloop = off;
|
|
582
760
|
|
|
583
|
-
DROP
|
|
584
|
-
|
|
585
|
-
|
|
761
|
+
-- Create-once + TRUNCATE, never DROP + CREATE on a fixed name: see the
|
|
762
|
+
-- temp-table lifecycle note in spUpdateExistingEntityFieldsFromSchema. This
|
|
763
|
+
-- routine is exposed to exactly the same stale-cached-plan abort, and it too
|
|
764
|
+
-- has ANALYZE calls below that any rewrite must preserve.
|
|
765
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_scope (entity_id UUID);
|
|
766
|
+
TRUNCATE _del_scope;
|
|
767
|
+
INSERT INTO _del_scope (entity_id)
|
|
768
|
+
SELECT DISTINCT TRIM(v)::uuid
|
|
586
769
|
FROM unnest(string_to_array(COALESCE(p_EntityIDs, ''), ',')) AS v
|
|
587
770
|
WHERE TRIM(v) ~* '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$';
|
|
588
771
|
v_is_scoped := EXISTS (SELECT 1 FROM _del_scope);
|
|
589
772
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
773
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_included (schema_name TEXT);
|
|
774
|
+
TRUNCATE _del_included;
|
|
775
|
+
INSERT INTO _del_included (schema_name)
|
|
776
|
+
SELECT TRIM(s)
|
|
593
777
|
FROM unnest(string_to_array(COALESCE(p_IncludedSchemaNames, ''), ',')) AS s
|
|
594
778
|
WHERE TRIM(s) <> '';
|
|
595
779
|
v_has_include := EXISTS (SELECT 1 FROM _del_included);
|
|
@@ -615,14 +799,15 @@ BEGIN
|
|
|
615
799
|
--
|
|
616
800
|
-- It is a NAME list, not an id list, because the caller's exclusions are declared by name and
|
|
617
801
|
-- apply across entities. Matched case-insensitively for the same reason.
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
802
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_protected (field_name TEXT);
|
|
803
|
+
TRUNCATE _del_protected;
|
|
804
|
+
INSERT INTO _del_protected (field_name)
|
|
805
|
+
SELECT LOWER(TRIM(s))
|
|
621
806
|
FROM unnest(string_to_array(COALESCE(p_ProtectedFieldNames, ''), ',')) AS s
|
|
622
807
|
WHERE TRIM(s) <> '';
|
|
623
808
|
|
|
624
|
-
|
|
625
|
-
|
|
809
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_ext_entities (entity_id UUID);
|
|
810
|
+
TRUNCATE _del_ext_entities;
|
|
626
811
|
IF EXISTS (
|
|
627
812
|
SELECT 1 FROM information_schema.columns
|
|
628
813
|
WHERE table_schema = '__mj' AND table_name = 'vwEntities' AND column_name = 'ExternalDataSourceID'
|
|
@@ -632,9 +817,10 @@ BEGIN
|
|
|
632
817
|
END IF;
|
|
633
818
|
|
|
634
819
|
-- metadata-side fields for in-scope, non-virtual entities
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
820
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_ef (field_id UUID, entity_id UUID, entity_name TEXT, field_name TEXT);
|
|
821
|
+
TRUNCATE _del_ef;
|
|
822
|
+
INSERT INTO _del_ef (field_id, entity_id, entity_name, field_name)
|
|
823
|
+
SELECT ef."ID", ef."EntityID", ef."Entity"::text, ef."Name"::text
|
|
638
824
|
FROM __mj."vwEntityFields" ef
|
|
639
825
|
INNER JOIN __mj."vwEntities" e ON ef."EntityID" = e."ID"
|
|
640
826
|
LEFT JOIN unnest(string_to_array(COALESCE(p_ExcludedSchemaNames, ''), ',')) AS ex(v)
|
|
@@ -650,9 +836,10 @@ BEGIN
|
|
|
650
836
|
ANALYZE _del_ef;
|
|
651
837
|
|
|
652
838
|
-- actual columns present in the database
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
839
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_actual (entity_id UUID, field_name TEXT);
|
|
840
|
+
TRUNCATE _del_actual;
|
|
841
|
+
INSERT INTO _del_actual (entity_id, field_name)
|
|
842
|
+
SELECT sq."EntityID", sq."FieldName"::text
|
|
656
843
|
FROM __mj."vwSQLColumnsAndEntityFields" sq
|
|
657
844
|
WHERE (NOT v_is_scoped OR sq."EntityID" IN (SELECT s.entity_id FROM _del_scope s));
|
|
658
845
|
-- [Large Schema Series] _del_actual is a single materialization of the heavy
|
|
@@ -661,8 +848,9 @@ BEGIN
|
|
|
661
848
|
ANALYZE _del_actual;
|
|
662
849
|
|
|
663
850
|
-- orphans: metadata field with no matching DB column
|
|
664
|
-
|
|
665
|
-
|
|
851
|
+
CREATE TEMP TABLE IF NOT EXISTS _del_deleted (field_id UUID, entity_id UUID, entity_name TEXT, field_name TEXT);
|
|
852
|
+
TRUNCATE _del_deleted;
|
|
853
|
+
INSERT INTO _del_deleted (field_id, entity_id, entity_name, field_name)
|
|
666
854
|
SELECT ef.field_id, ef.entity_id, ef.entity_name, ef.field_name
|
|
667
855
|
FROM _del_ef ef
|
|
668
856
|
LEFT JOIN _del_actual actual
|
|
@@ -678,16 +866,18 @@ BEGIN
|
|
|
678
866
|
DELETE FROM __mj."EntityField" delf
|
|
679
867
|
WHERE delf."ID" IN (SELECT d.field_id FROM _del_deleted d);
|
|
680
868
|
|
|
681
|
-
DROP TABLE IF EXISTS _del_protected;
|
|
682
|
-
|
|
683
869
|
RETURN QUERY
|
|
684
870
|
SELECT d.field_id, d.entity_id, d.entity_name, d.field_name FROM _del_deleted d;
|
|
685
871
|
|
|
686
|
-
DROP
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
872
|
+
-- TRUNCATE, never DROP: frees the storage while keeping each relation's OID
|
|
873
|
+
-- stable so the plans cached above survive the next call on this connection.
|
|
874
|
+
TRUNCATE _del_deleted;
|
|
875
|
+
TRUNCATE _del_actual;
|
|
876
|
+
TRUNCATE _del_ef;
|
|
877
|
+
TRUNCATE _del_ext_entities;
|
|
878
|
+
TRUNCATE _del_protected;
|
|
879
|
+
TRUNCATE _del_scope;
|
|
880
|
+
TRUNCATE _del_included;
|
|
691
881
|
END;
|
|
692
882
|
$func$;
|
|
693
883
|
|
|
@@ -743,15 +933,19 @@ LANGUAGE plpgsql AS $func$
|
|
|
743
933
|
DECLARE
|
|
744
934
|
v_has_include BOOLEAN := FALSE;
|
|
745
935
|
BEGIN
|
|
746
|
-
DROP
|
|
747
|
-
|
|
748
|
-
|
|
936
|
+
-- Create-once + TRUNCATE, never DROP + CREATE on a fixed name: see the
|
|
937
|
+
-- temp-table lifecycle note in spUpdateExistingEntityFieldsFromSchema.
|
|
938
|
+
CREATE TEMP TABLE IF NOT EXISTS _usi_excluded (schema_name TEXT);
|
|
939
|
+
TRUNCATE _usi_excluded;
|
|
940
|
+
INSERT INTO _usi_excluded (schema_name)
|
|
941
|
+
SELECT TRIM(s)
|
|
749
942
|
FROM unnest(string_to_array(COALESCE(p_ExcludedSchemaNames, ''), ',')) AS s
|
|
750
943
|
WHERE TRIM(s) <> '';
|
|
751
944
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
945
|
+
CREATE TEMP TABLE IF NOT EXISTS _usi_included (schema_name TEXT);
|
|
946
|
+
TRUNCATE _usi_included;
|
|
947
|
+
INSERT INTO _usi_included (schema_name)
|
|
948
|
+
SELECT TRIM(s)
|
|
755
949
|
FROM unnest(string_to_array(COALESCE(p_IncludedSchemaNames, ''), ',')) AS s
|
|
756
950
|
WHERE TRIM(s) <> '';
|
|
757
951
|
v_has_include := EXISTS (SELECT 1 FROM _usi_included);
|
|
@@ -799,8 +993,9 @@ BEGIN
|
|
|
799
993
|
WHERE ss."SchemaName" NOT IN (SELECT x.schema_name FROM _usi_excluded x)
|
|
800
994
|
AND (NOT v_has_include OR ss."SchemaName" IN (SELECT i.schema_name FROM _usi_included i));
|
|
801
995
|
|
|
802
|
-
DROP
|
|
803
|
-
|
|
996
|
+
-- TRUNCATE, never DROP — the relation OIDs must stay stable for the cached plans.
|
|
997
|
+
TRUNCATE _usi_excluded;
|
|
998
|
+
TRUNCATE _usi_included;
|
|
804
999
|
END;
|
|
805
1000
|
$func$;
|
|
806
1001
|
|
|
@@ -942,15 +1137,19 @@ DECLARE
|
|
|
942
1137
|
v_has_include BOOLEAN := FALSE;
|
|
943
1138
|
v_row RECORD;
|
|
944
1139
|
BEGIN
|
|
945
|
-
DROP
|
|
946
|
-
|
|
947
|
-
|
|
1140
|
+
-- Create-once + TRUNCATE, never DROP + CREATE on a fixed name: see the
|
|
1141
|
+
-- temp-table lifecycle note in spUpdateExistingEntityFieldsFromSchema.
|
|
1142
|
+
CREATE TEMP TABLE IF NOT EXISTS _rav_included (schema_name TEXT);
|
|
1143
|
+
TRUNCATE _rav_included;
|
|
1144
|
+
INSERT INTO _rav_included (schema_name)
|
|
1145
|
+
SELECT TRIM(s)
|
|
948
1146
|
FROM unnest(string_to_array(COALESCE(p_IncludedSchemaNames, ''), ',')) AS s
|
|
949
1147
|
WHERE TRIM(s) <> '';
|
|
950
1148
|
v_has_include := EXISTS (SELECT 1 FROM _rav_included);
|
|
951
1149
|
|
|
952
|
-
|
|
953
|
-
|
|
1150
|
+
CREATE TEMP TABLE IF NOT EXISTS _rav_drift (schema_name TEXT, view_name TEXT, entity_name TEXT, missing_columns TEXT);
|
|
1151
|
+
TRUNCATE _rav_drift;
|
|
1152
|
+
INSERT INTO _rav_drift (schema_name, view_name, entity_name, missing_columns)
|
|
954
1153
|
WITH scoped AS (
|
|
955
1154
|
SELECT
|
|
956
1155
|
e."ID" AS entity_id,
|
|
@@ -1001,8 +1200,8 @@ BEGIN
|
|
|
1001
1200
|
FROM _rav_drift d
|
|
1002
1201
|
ORDER BY d.schema_name, d.view_name;
|
|
1003
1202
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1203
|
+
TRUNCATE _rav_drift;
|
|
1204
|
+
TRUNCATE _rav_included;
|
|
1006
1205
|
END;
|
|
1007
1206
|
$rav$;
|
|
1008
1207
|
`;
|