@pgpmjs/slice 0.13.4 → 0.13.6
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/closure.js +3 -5
- package/esm/closure.js +3 -5
- package/esm/object-graph.js +66 -12
- package/esm/partition.js +3 -5
- package/esm/refs.js +11 -7
- package/object-graph.d.ts +18 -6
- package/object-graph.js +66 -12
- package/package.json +4 -4
- package/partition.js +3 -5
- package/refs.d.ts +9 -7
- package/refs.js +10 -6
package/closure.js
CHANGED
|
@@ -4,10 +4,8 @@ exports.buildAstEdges = buildAstEdges;
|
|
|
4
4
|
exports.expandClosures = expandClosures;
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const object_graph_1 = require("./object-graph");
|
|
7
8
|
const refs_1 = require("./refs");
|
|
8
|
-
function objectKey(schema, name) {
|
|
9
|
-
return `${schema ?? ''}\u0000${name}`;
|
|
10
|
-
}
|
|
11
9
|
function refLabel(schema, name) {
|
|
12
10
|
return schema ? `${schema}.${name}` : name;
|
|
13
11
|
}
|
|
@@ -33,7 +31,7 @@ function buildAstEdges(graph, moduleDir) {
|
|
|
33
31
|
if (!f)
|
|
34
32
|
continue;
|
|
35
33
|
for (const c of f.creates) {
|
|
36
|
-
const key =
|
|
34
|
+
const key = (0, object_graph_1.objectKey)(c);
|
|
37
35
|
if (!producerByObject.has(key))
|
|
38
36
|
producerByObject.set(key, change.name);
|
|
39
37
|
}
|
|
@@ -45,7 +43,7 @@ function buildAstEdges(graph, moduleDir) {
|
|
|
45
43
|
if (f.dynamicSql)
|
|
46
44
|
dynamicSqlChanges.push(changeName);
|
|
47
45
|
for (const r of f.references) {
|
|
48
|
-
const producer = producerByObject.get(
|
|
46
|
+
const producer = producerByObject.get((0, object_graph_1.objectKey)(r));
|
|
49
47
|
if (!producer) {
|
|
50
48
|
unresolvedReferences.push({ change: changeName, ref: refLabel(r.schema, r.name) });
|
|
51
49
|
continue;
|
package/esm/closure.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import { objectKey } from './object-graph';
|
|
3
4
|
import { extractSqlFacts } from './refs';
|
|
4
|
-
function objectKey(schema, name) {
|
|
5
|
-
return `${schema ?? ''}\u0000${name}`;
|
|
6
|
-
}
|
|
7
5
|
function refLabel(schema, name) {
|
|
8
6
|
return schema ? `${schema}.${name}` : name;
|
|
9
7
|
}
|
|
@@ -29,7 +27,7 @@ export function buildAstEdges(graph, moduleDir) {
|
|
|
29
27
|
if (!f)
|
|
30
28
|
continue;
|
|
31
29
|
for (const c of f.creates) {
|
|
32
|
-
const key = objectKey(c
|
|
30
|
+
const key = objectKey(c);
|
|
33
31
|
if (!producerByObject.has(key))
|
|
34
32
|
producerByObject.set(key, change.name);
|
|
35
33
|
}
|
|
@@ -41,7 +39,7 @@ export function buildAstEdges(graph, moduleDir) {
|
|
|
41
39
|
if (f.dynamicSql)
|
|
42
40
|
dynamicSqlChanges.push(changeName);
|
|
43
41
|
for (const r of f.references) {
|
|
44
|
-
const producer = producerByObject.get(objectKey(r
|
|
42
|
+
const producer = producerByObject.get(objectKey(r));
|
|
45
43
|
if (!producer) {
|
|
46
44
|
unresolvedReferences.push({ change: changeName, ref: refLabel(r.schema, r.name) });
|
|
47
45
|
continue;
|
package/esm/object-graph.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified SQL object graph — the semantic IR over parsed programs.
|
|
3
|
+
*
|
|
4
|
+
* Nodes are database objects (keyed by qualified name) with the statements
|
|
5
|
+
* that create them; edges are the references statements make to objects,
|
|
6
|
+
* typed with `@pgsql/transform`'s edge taxonomy (`hard | fk | late`).
|
|
7
|
+
* Programs are named (typically one per pgpm change), so ownership queries
|
|
8
|
+
* answer change-level questions directly:
|
|
9
|
+
*
|
|
10
|
+
* - which objects live in a schema set (subsystem selection)
|
|
11
|
+
* - which surviving statements still reach into a dropped object set
|
|
12
|
+
* (cascade safety — every in-edge must originate from a statement that is
|
|
13
|
+
* itself dropped, or be rebound)
|
|
14
|
+
* - which programs create nothing outside a dropped set (whole-change
|
|
15
|
+
* pruning by ownership, not survivor counting)
|
|
16
|
+
*
|
|
17
|
+
* Each program's intra-program edges come straight from
|
|
18
|
+
* `buildStatementGraph`; references with no in-program producer (external
|
|
19
|
+
* dependencies, which the statement graph deliberately omits) are added with
|
|
20
|
+
* the same kind classification, so the object graph is a superset projection
|
|
21
|
+
* of the statement graph over the same facts.
|
|
22
|
+
*
|
|
23
|
+
* Pure and I/O-free; built from `SqlProgram`s parsed once elsewhere.
|
|
24
|
+
*/
|
|
25
|
+
import { buildStatementGraph } from '@pgpmjs/transform';
|
|
1
26
|
export function objectKey(ref) {
|
|
2
27
|
return `${ref.schema ?? ''}\u0000${ref.name}`;
|
|
3
28
|
}
|
|
@@ -17,17 +42,25 @@ export function buildObjectGraph(programs) {
|
|
|
17
42
|
const edges = [];
|
|
18
43
|
const incoming = new Map();
|
|
19
44
|
const addEdge = (edge) => {
|
|
20
|
-
edges.push(edge);
|
|
21
45
|
const list = incoming.get(edge.to);
|
|
22
|
-
if (list)
|
|
46
|
+
if (list) {
|
|
47
|
+
if (list.some(e => e.kind === edge.kind &&
|
|
48
|
+
e.from.program === edge.from.program &&
|
|
49
|
+
e.from.statement === edge.from.statement))
|
|
50
|
+
return;
|
|
23
51
|
list.push(edge);
|
|
24
|
-
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
25
54
|
incoming.set(edge.to, [edge]);
|
|
55
|
+
}
|
|
56
|
+
edges.push(edge);
|
|
26
57
|
};
|
|
27
58
|
for (const [name, program] of programMap) {
|
|
28
|
-
program.statements.
|
|
59
|
+
const facts = program.statements.map(s => s.facts);
|
|
60
|
+
const statementGraph = buildStatementGraph(facts);
|
|
61
|
+
facts.forEach((stmt, i) => {
|
|
29
62
|
const id = { program: name, statement: i };
|
|
30
|
-
for (const c of stmt.
|
|
63
|
+
for (const c of stmt.creates) {
|
|
31
64
|
const key = objectKey(c);
|
|
32
65
|
const node = objects.get(key);
|
|
33
66
|
if (node)
|
|
@@ -35,14 +68,35 @@ export function buildObjectGraph(programs) {
|
|
|
35
68
|
else
|
|
36
69
|
objects.set(key, { ref: { schema: c.schema, name: c.name }, createdBy: [id] });
|
|
37
70
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
71
|
+
});
|
|
72
|
+
// Intra-program edges, exactly as the statement graph typed them.
|
|
73
|
+
for (const e of statementGraph.edges) {
|
|
74
|
+
addEdge({ from: { program: name, statement: e.from }, to: objectKey(e.via), kind: e.kind });
|
|
75
|
+
}
|
|
76
|
+
// References with no in-program producer are external dependencies: the
|
|
77
|
+
// statement graph induces no edge for them, but the object graph keeps
|
|
78
|
+
// them (that is what contract/cascade queries measure). Same kind
|
|
79
|
+
// classification: fk beats late beats hard.
|
|
80
|
+
facts.forEach((stmt, i) => {
|
|
81
|
+
const id = { program: name, statement: i };
|
|
82
|
+
const bodyOnly = new Set(stmt.bodyReferences.map(objectKey));
|
|
83
|
+
const fkKeys = new Set(stmt.fkTargets.map(objectKey));
|
|
84
|
+
const seen = new Set();
|
|
85
|
+
for (const r of stmt.references) {
|
|
86
|
+
const key = objectKey(r);
|
|
87
|
+
seen.add(key);
|
|
88
|
+
if (statementGraph.producers.has(`${r.schema ?? ''}.${r.name}`))
|
|
89
|
+
continue;
|
|
90
|
+
const kind = fkKeys.has(key) ? 'fk' : bodyOnly.has(key) ? 'late' : 'hard';
|
|
91
|
+
addEdge({ from: id, to: key, kind });
|
|
43
92
|
}
|
|
44
|
-
for (const t of stmt.
|
|
45
|
-
|
|
93
|
+
for (const t of stmt.fkTargets) {
|
|
94
|
+
const key = objectKey(t);
|
|
95
|
+
if (seen.has(key))
|
|
96
|
+
continue;
|
|
97
|
+
if (statementGraph.producers.has(`${t.schema ?? ''}.${t.name}`))
|
|
98
|
+
continue;
|
|
99
|
+
addEdge({ from: id, to: key, kind: 'fk' });
|
|
46
100
|
}
|
|
47
101
|
});
|
|
48
102
|
}
|
package/esm/partition.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { parsePlanFile } from '@pgpmjs/ast/files/plan/parser';
|
|
4
4
|
import { buildAstEdges } from './closure';
|
|
5
|
+
import { objectKey } from './object-graph';
|
|
5
6
|
import { extractSqlFacts } from './refs';
|
|
6
7
|
import { buildDependencyGraph } from './slice';
|
|
7
8
|
/** The dependency edges of a change: declared plan `requires` + AST-discovered. */
|
|
@@ -86,9 +87,6 @@ export function partitionChanges(input) {
|
|
|
86
87
|
}
|
|
87
88
|
return { perTenant, shared, sharedDependencies, warnings };
|
|
88
89
|
}
|
|
89
|
-
function objectKey(schema, name) {
|
|
90
|
-
return `${schema ?? ''}\u0000${name}`;
|
|
91
|
-
}
|
|
92
90
|
/**
|
|
93
91
|
* On-disk entry point: parse a module's plan + deploy SQL, resolve the given
|
|
94
92
|
* per-tenant seed *objects* to the changes that create them, and partition the
|
|
@@ -113,7 +111,7 @@ export function partitionModule(options) {
|
|
|
113
111
|
continue;
|
|
114
112
|
const facts = extractSqlFacts(readFileSync(deployPath, 'utf-8'));
|
|
115
113
|
for (const c of facts.creates) {
|
|
116
|
-
const key = objectKey(c
|
|
114
|
+
const key = objectKey(c);
|
|
117
115
|
if (!producerByObject.has(key))
|
|
118
116
|
producerByObject.set(key, change.name);
|
|
119
117
|
}
|
|
@@ -121,7 +119,7 @@ export function partitionModule(options) {
|
|
|
121
119
|
const seedChanges = [];
|
|
122
120
|
const unresolvedSeeds = [];
|
|
123
121
|
for (const obj of options.seedObjects) {
|
|
124
|
-
const producer = producerByObject.get(objectKey(obj
|
|
122
|
+
const producer = producerByObject.get(objectKey(obj));
|
|
125
123
|
if (!producer) {
|
|
126
124
|
unresolvedSeeds.push({
|
|
127
125
|
kind: 'unknown-seed',
|
package/esm/refs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { classifyStatements } from '@pgpmjs/transform';
|
|
1
|
+
import { buildStatementGraph, classifyStatements } from '@pgpmjs/transform';
|
|
2
2
|
/**
|
|
3
3
|
* The parser runs on a WASM build of the real PostgreSQL parser; callers must
|
|
4
4
|
* `await loadModule()` once before any synchronous extraction/slicing call.
|
|
@@ -14,23 +14,27 @@ function pushUnique(list, r) {
|
|
|
14
14
|
* including references reached inside PL/pgSQL function bodies (which are
|
|
15
15
|
* opaque strings in `CREATE FUNCTION` and invisible to a plain SQL parse).
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
* the
|
|
19
|
-
*
|
|
17
|
+
* A thin change-level adapter over `@pgsql/transform`: `classifyStatements`
|
|
18
|
+
* produces the per-statement facts and `buildStatementGraph`'s producer index
|
|
19
|
+
* decides which references are internal — a reference with an in-script
|
|
20
|
+
* producer is satisfied by the change itself, so only external references
|
|
21
|
+
* (the statement graph's non-edges) surface as change-level dependencies.
|
|
20
22
|
*/
|
|
21
23
|
export function extractSqlFacts(sql) {
|
|
24
|
+
const statements = classifyStatements(sql);
|
|
25
|
+
const graph = buildStatementGraph(statements);
|
|
22
26
|
const facts = { creates: [], references: [], dynamicSql: false };
|
|
23
|
-
for (const stmt of
|
|
27
|
+
for (const stmt of statements) {
|
|
24
28
|
for (const c of stmt.creates) {
|
|
25
29
|
pushUnique(facts.creates, { schema: c.schema, name: c.name });
|
|
26
30
|
}
|
|
27
31
|
for (const r of stmt.references) {
|
|
32
|
+
if (graph.producers.has(`${r.schema ?? ''}.${r.name}`))
|
|
33
|
+
continue;
|
|
28
34
|
pushUnique(facts.references, { schema: r.schema, name: r.name });
|
|
29
35
|
}
|
|
30
36
|
if (stmt.dynamicSql)
|
|
31
37
|
facts.dynamicSql = true;
|
|
32
38
|
}
|
|
33
|
-
// A change does not depend on objects it creates itself.
|
|
34
|
-
facts.references = facts.references.filter(r => !facts.creates.some(c => c.schema === r.schema && c.name === r.name));
|
|
35
39
|
return facts;
|
|
36
40
|
}
|
package/object-graph.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Unified SQL object graph — the semantic IR over parsed programs.
|
|
3
3
|
*
|
|
4
4
|
* Nodes are database objects (keyed by qualified name) with the statements
|
|
5
|
-
* that create them; edges are the references statements make to objects
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* that create them; edges are the references statements make to objects,
|
|
6
|
+
* typed with `@pgsql/transform`'s edge taxonomy (`hard | fk | late`).
|
|
7
|
+
* Programs are named (typically one per pgpm change), so ownership queries
|
|
8
|
+
* answer change-level questions directly:
|
|
9
9
|
*
|
|
10
10
|
* - which objects live in a schema set (subsystem selection)
|
|
11
11
|
* - which surviving statements still reach into a dropped object set
|
|
@@ -14,16 +14,28 @@
|
|
|
14
14
|
* - which programs create nothing outside a dropped set (whole-change
|
|
15
15
|
* pruning by ownership, not survivor counting)
|
|
16
16
|
*
|
|
17
|
+
* Each program's intra-program edges come straight from
|
|
18
|
+
* `buildStatementGraph`; references with no in-program producer (external
|
|
19
|
+
* dependencies, which the statement graph deliberately omits) are added with
|
|
20
|
+
* the same kind classification, so the object graph is a superset projection
|
|
21
|
+
* of the statement graph over the same facts.
|
|
22
|
+
*
|
|
17
23
|
* Pure and I/O-free; built from `SqlProgram`s parsed once elsewhere.
|
|
18
24
|
*/
|
|
19
|
-
import
|
|
25
|
+
import { EdgeKind, SqlProgram } from '@pgpmjs/transform';
|
|
20
26
|
import { SqlObjectRef } from './refs';
|
|
21
27
|
/** Identifies one statement inside one named program. */
|
|
22
28
|
export interface StatementId {
|
|
23
29
|
program: string;
|
|
24
30
|
statement: number;
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
/**
|
|
33
|
+
* How an edge constrains ordering — `@pgsql/transform`'s taxonomy:
|
|
34
|
+
* `hard` (must exist at CREATE time), `fk` (a hard edge from a foreign-key
|
|
35
|
+
* target), `late` (reached only inside a PL/pgSQL body, resolved at call
|
|
36
|
+
* time).
|
|
37
|
+
*/
|
|
38
|
+
export type ObjectEdgeKind = EdgeKind;
|
|
27
39
|
/** One reference from a statement to an object. */
|
|
28
40
|
export interface ObjectEdge {
|
|
29
41
|
from: StatementId;
|
package/object-graph.js
CHANGED
|
@@ -6,6 +6,31 @@ exports.buildObjectGraph = buildObjectGraph;
|
|
|
6
6
|
exports.objectsInSchemas = objectsInSchemas;
|
|
7
7
|
exports.danglingEdges = danglingEdges;
|
|
8
8
|
exports.prunablePrograms = prunablePrograms;
|
|
9
|
+
/**
|
|
10
|
+
* Unified SQL object graph — the semantic IR over parsed programs.
|
|
11
|
+
*
|
|
12
|
+
* Nodes are database objects (keyed by qualified name) with the statements
|
|
13
|
+
* that create them; edges are the references statements make to objects,
|
|
14
|
+
* typed with `@pgsql/transform`'s edge taxonomy (`hard | fk | late`).
|
|
15
|
+
* Programs are named (typically one per pgpm change), so ownership queries
|
|
16
|
+
* answer change-level questions directly:
|
|
17
|
+
*
|
|
18
|
+
* - which objects live in a schema set (subsystem selection)
|
|
19
|
+
* - which surviving statements still reach into a dropped object set
|
|
20
|
+
* (cascade safety — every in-edge must originate from a statement that is
|
|
21
|
+
* itself dropped, or be rebound)
|
|
22
|
+
* - which programs create nothing outside a dropped set (whole-change
|
|
23
|
+
* pruning by ownership, not survivor counting)
|
|
24
|
+
*
|
|
25
|
+
* Each program's intra-program edges come straight from
|
|
26
|
+
* `buildStatementGraph`; references with no in-program producer (external
|
|
27
|
+
* dependencies, which the statement graph deliberately omits) are added with
|
|
28
|
+
* the same kind classification, so the object graph is a superset projection
|
|
29
|
+
* of the statement graph over the same facts.
|
|
30
|
+
*
|
|
31
|
+
* Pure and I/O-free; built from `SqlProgram`s parsed once elsewhere.
|
|
32
|
+
*/
|
|
33
|
+
const transform_1 = require("@pgpmjs/transform");
|
|
9
34
|
function objectKey(ref) {
|
|
10
35
|
return `${ref.schema ?? ''}\u0000${ref.name}`;
|
|
11
36
|
}
|
|
@@ -25,17 +50,25 @@ function buildObjectGraph(programs) {
|
|
|
25
50
|
const edges = [];
|
|
26
51
|
const incoming = new Map();
|
|
27
52
|
const addEdge = (edge) => {
|
|
28
|
-
edges.push(edge);
|
|
29
53
|
const list = incoming.get(edge.to);
|
|
30
|
-
if (list)
|
|
54
|
+
if (list) {
|
|
55
|
+
if (list.some(e => e.kind === edge.kind &&
|
|
56
|
+
e.from.program === edge.from.program &&
|
|
57
|
+
e.from.statement === edge.from.statement))
|
|
58
|
+
return;
|
|
31
59
|
list.push(edge);
|
|
32
|
-
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
33
62
|
incoming.set(edge.to, [edge]);
|
|
63
|
+
}
|
|
64
|
+
edges.push(edge);
|
|
34
65
|
};
|
|
35
66
|
for (const [name, program] of programMap) {
|
|
36
|
-
program.statements.
|
|
67
|
+
const facts = program.statements.map(s => s.facts);
|
|
68
|
+
const statementGraph = (0, transform_1.buildStatementGraph)(facts);
|
|
69
|
+
facts.forEach((stmt, i) => {
|
|
37
70
|
const id = { program: name, statement: i };
|
|
38
|
-
for (const c of stmt.
|
|
71
|
+
for (const c of stmt.creates) {
|
|
39
72
|
const key = objectKey(c);
|
|
40
73
|
const node = objects.get(key);
|
|
41
74
|
if (node)
|
|
@@ -43,14 +76,35 @@ function buildObjectGraph(programs) {
|
|
|
43
76
|
else
|
|
44
77
|
objects.set(key, { ref: { schema: c.schema, name: c.name }, createdBy: [id] });
|
|
45
78
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
79
|
+
});
|
|
80
|
+
// Intra-program edges, exactly as the statement graph typed them.
|
|
81
|
+
for (const e of statementGraph.edges) {
|
|
82
|
+
addEdge({ from: { program: name, statement: e.from }, to: objectKey(e.via), kind: e.kind });
|
|
83
|
+
}
|
|
84
|
+
// References with no in-program producer are external dependencies: the
|
|
85
|
+
// statement graph induces no edge for them, but the object graph keeps
|
|
86
|
+
// them (that is what contract/cascade queries measure). Same kind
|
|
87
|
+
// classification: fk beats late beats hard.
|
|
88
|
+
facts.forEach((stmt, i) => {
|
|
89
|
+
const id = { program: name, statement: i };
|
|
90
|
+
const bodyOnly = new Set(stmt.bodyReferences.map(objectKey));
|
|
91
|
+
const fkKeys = new Set(stmt.fkTargets.map(objectKey));
|
|
92
|
+
const seen = new Set();
|
|
93
|
+
for (const r of stmt.references) {
|
|
94
|
+
const key = objectKey(r);
|
|
95
|
+
seen.add(key);
|
|
96
|
+
if (statementGraph.producers.has(`${r.schema ?? ''}.${r.name}`))
|
|
97
|
+
continue;
|
|
98
|
+
const kind = fkKeys.has(key) ? 'fk' : bodyOnly.has(key) ? 'late' : 'hard';
|
|
99
|
+
addEdge({ from: id, to: key, kind });
|
|
51
100
|
}
|
|
52
|
-
for (const t of stmt.
|
|
53
|
-
|
|
101
|
+
for (const t of stmt.fkTargets) {
|
|
102
|
+
const key = objectKey(t);
|
|
103
|
+
if (seen.has(key))
|
|
104
|
+
continue;
|
|
105
|
+
if (statementGraph.producers.has(`${t.schema ?? ''}.${t.name}`))
|
|
106
|
+
continue;
|
|
107
|
+
addEdge({ from: id, to: key, kind: 'fk' });
|
|
54
108
|
}
|
|
55
109
|
});
|
|
56
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpmjs/slice",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.6",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PGPM plan slicing — split a monolithic pgpm plan into packages with pattern strategies and opt-in AST-based dependency closure",
|
|
6
6
|
"main": "index.js",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@pgpmjs/ast": "^0.10.2",
|
|
46
|
-
"@pgpmjs/transform": "^0.
|
|
46
|
+
"@pgpmjs/transform": "^0.17.0",
|
|
47
47
|
"minimatch": "^10.2.5",
|
|
48
|
-
"plpgsql-parser": "^18.2.
|
|
48
|
+
"plpgsql-parser": "^18.2.3"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "45cd961cf956d2d28e4d09b20db4204982c33593"
|
|
51
51
|
}
|
package/partition.js
CHANGED
|
@@ -6,6 +6,7 @@ const fs_1 = require("fs");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const parser_1 = require("@pgpmjs/ast/files/plan/parser");
|
|
8
8
|
const closure_1 = require("./closure");
|
|
9
|
+
const object_graph_1 = require("./object-graph");
|
|
9
10
|
const refs_1 = require("./refs");
|
|
10
11
|
const slice_1 = require("./slice");
|
|
11
12
|
/** The dependency edges of a change: declared plan `requires` + AST-discovered. */
|
|
@@ -90,9 +91,6 @@ function partitionChanges(input) {
|
|
|
90
91
|
}
|
|
91
92
|
return { perTenant, shared, sharedDependencies, warnings };
|
|
92
93
|
}
|
|
93
|
-
function objectKey(schema, name) {
|
|
94
|
-
return `${schema ?? ''}\u0000${name}`;
|
|
95
|
-
}
|
|
96
94
|
/**
|
|
97
95
|
* On-disk entry point: parse a module's plan + deploy SQL, resolve the given
|
|
98
96
|
* per-tenant seed *objects* to the changes that create them, and partition the
|
|
@@ -117,7 +115,7 @@ function partitionModule(options) {
|
|
|
117
115
|
continue;
|
|
118
116
|
const facts = (0, refs_1.extractSqlFacts)((0, fs_1.readFileSync)(deployPath, 'utf-8'));
|
|
119
117
|
for (const c of facts.creates) {
|
|
120
|
-
const key =
|
|
118
|
+
const key = (0, object_graph_1.objectKey)(c);
|
|
121
119
|
if (!producerByObject.has(key))
|
|
122
120
|
producerByObject.set(key, change.name);
|
|
123
121
|
}
|
|
@@ -125,7 +123,7 @@ function partitionModule(options) {
|
|
|
125
123
|
const seedChanges = [];
|
|
126
124
|
const unresolvedSeeds = [];
|
|
127
125
|
for (const obj of options.seedObjects) {
|
|
128
|
-
const producer = producerByObject.get(
|
|
126
|
+
const producer = producerByObject.get((0, object_graph_1.objectKey)(obj));
|
|
129
127
|
if (!producer) {
|
|
130
128
|
unresolvedSeeds.push({
|
|
131
129
|
kind: 'unknown-seed',
|
package/refs.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QualifiedName } from '@pgpmjs/transform';
|
|
1
2
|
/**
|
|
2
3
|
* The parser runs on a WASM build of the real PostgreSQL parser; callers must
|
|
3
4
|
* `await loadModule()` once before any synchronous extraction/slicing call.
|
|
@@ -5,11 +6,10 @@
|
|
|
5
6
|
export { loadModule } from 'plpgsql-parser';
|
|
6
7
|
/**
|
|
7
8
|
* A (possibly schema-qualified) database object name extracted from SQL.
|
|
9
|
+
* Alias of `@pgsql/transform`'s `QualifiedName` — one name type across the
|
|
10
|
+
* facts substrate and the slice layer.
|
|
8
11
|
*/
|
|
9
|
-
export
|
|
10
|
-
schema: string | null;
|
|
11
|
-
name: string;
|
|
12
|
-
}
|
|
12
|
+
export type SqlObjectRef = QualifiedName;
|
|
13
13
|
/**
|
|
14
14
|
* AST-derived facts about a change's deploy SQL, used to discover
|
|
15
15
|
* dependencies that are not declared in plan `requires` headers.
|
|
@@ -36,8 +36,10 @@ export interface ChangeSqlFacts {
|
|
|
36
36
|
* including references reached inside PL/pgSQL function bodies (which are
|
|
37
37
|
* opaque strings in `CREATE FUNCTION` and invisible to a plain SQL parse).
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
* the
|
|
41
|
-
*
|
|
39
|
+
* A thin change-level adapter over `@pgsql/transform`: `classifyStatements`
|
|
40
|
+
* produces the per-statement facts and `buildStatementGraph`'s producer index
|
|
41
|
+
* decides which references are internal — a reference with an in-script
|
|
42
|
+
* producer is satisfied by the change itself, so only external references
|
|
43
|
+
* (the statement graph's non-edges) surface as change-level dependencies.
|
|
42
44
|
*/
|
|
43
45
|
export declare function extractSqlFacts(sql: string): ChangeSqlFacts;
|
package/refs.js
CHANGED
|
@@ -19,23 +19,27 @@ function pushUnique(list, r) {
|
|
|
19
19
|
* including references reached inside PL/pgSQL function bodies (which are
|
|
20
20
|
* opaque strings in `CREATE FUNCTION` and invisible to a plain SQL parse).
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
* the
|
|
24
|
-
*
|
|
22
|
+
* A thin change-level adapter over `@pgsql/transform`: `classifyStatements`
|
|
23
|
+
* produces the per-statement facts and `buildStatementGraph`'s producer index
|
|
24
|
+
* decides which references are internal — a reference with an in-script
|
|
25
|
+
* producer is satisfied by the change itself, so only external references
|
|
26
|
+
* (the statement graph's non-edges) surface as change-level dependencies.
|
|
25
27
|
*/
|
|
26
28
|
function extractSqlFacts(sql) {
|
|
29
|
+
const statements = (0, transform_1.classifyStatements)(sql);
|
|
30
|
+
const graph = (0, transform_1.buildStatementGraph)(statements);
|
|
27
31
|
const facts = { creates: [], references: [], dynamicSql: false };
|
|
28
|
-
for (const stmt of
|
|
32
|
+
for (const stmt of statements) {
|
|
29
33
|
for (const c of stmt.creates) {
|
|
30
34
|
pushUnique(facts.creates, { schema: c.schema, name: c.name });
|
|
31
35
|
}
|
|
32
36
|
for (const r of stmt.references) {
|
|
37
|
+
if (graph.producers.has(`${r.schema ?? ''}.${r.name}`))
|
|
38
|
+
continue;
|
|
33
39
|
pushUnique(facts.references, { schema: r.schema, name: r.name });
|
|
34
40
|
}
|
|
35
41
|
if (stmt.dynamicSql)
|
|
36
42
|
facts.dynamicSql = true;
|
|
37
43
|
}
|
|
38
|
-
// A change does not depend on objects it creates itself.
|
|
39
|
-
facts.references = facts.references.filter(r => !facts.creates.some(c => c.schema === r.schema && c.name === r.name));
|
|
40
44
|
return facts;
|
|
41
45
|
}
|