@memberjunction/sql-converter 5.41.0 → 5.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/IncrementalBaker.d.ts +85 -0
- package/dist/IncrementalBaker.d.ts.map +1 -0
- package/dist/IncrementalBaker.js +127 -0
- package/dist/IncrementalBaker.js.map +1 -0
- package/dist/MigrationConverter.d.ts +119 -0
- package/dist/MigrationConverter.d.ts.map +1 -0
- package/dist/MigrationConverter.js +364 -0
- package/dist/MigrationConverter.js.map +1 -0
- package/dist/MigrationSplitter.d.ts +89 -0
- package/dist/MigrationSplitter.d.ts.map +1 -0
- package/dist/MigrationSplitter.js +311 -0
- package/dist/MigrationSplitter.js.map +1 -0
- package/dist/MigrationStatementSplitter.d.ts +39 -0
- package/dist/MigrationStatementSplitter.d.ts.map +1 -0
- package/dist/MigrationStatementSplitter.js +123 -0
- package/dist/MigrationStatementSplitter.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/rules/PostProcessor.d.ts.map +1 -1
- package/dist/rules/PostProcessor.js +11 -2
- package/dist/rules/PostProcessor.js.map +1 -1
- package/dist/rules/SequenceDeduplicator.d.ts +22 -0
- package/dist/rules/SequenceDeduplicator.d.ts.map +1 -1
- package/dist/rules/SequenceDeduplicator.js +2 -0
- package/dist/rules/SequenceDeduplicator.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MigrationSplitter — deterministic decomposition of a SQL Server migration into
|
|
3
|
+
* the regions that drive the "split-and-regenerate" PG conversion strategy.
|
|
4
|
+
*
|
|
5
|
+
* See `plans/pg-migration-architecture/SPLIT_AND_REGENERATE_PROPOSAL.md`.
|
|
6
|
+
*
|
|
7
|
+
* The premise: almost all migration content is emitted by one of two MJ
|
|
8
|
+
* generators — CodeGen (SQL objects: views/sprocs/GRANTs/indexes/extended
|
|
9
|
+
* properties) and mj-sync (metadata seed via `DECLARE @x_<hash>; EXEC spCreate…`).
|
|
10
|
+
* Each generator has a FIXED output grammar, so its output is identified
|
|
11
|
+
* deterministically rather than parsed as arbitrary T-SQL. What remains is a
|
|
12
|
+
* small, regular hand-authored remainder plus a rare hand-written procedural
|
|
13
|
+
* residue that must be human-authored for PG.
|
|
14
|
+
*
|
|
15
|
+
* This module performs NO conversion. It only classifies, so the pipeline can
|
|
16
|
+
* route each region: regenerate (CodeGen objects), re-seed/transpile (mj-sync),
|
|
17
|
+
* transpile (regular DDL), or escalate to a human (hand procedural).
|
|
18
|
+
*/
|
|
19
|
+
/** Marker emitted by CodeGen inside every generated item's header comment block. */
|
|
20
|
+
const GENERATED_BANNER = /This was generated by the MemberJunction CodeGen tool/i;
|
|
21
|
+
/** Explicit run-level delimiter (present in a minority of files but unambiguous when it is). */
|
|
22
|
+
const CODE_GEN_RUN = /^--\s*CODE GEN RUN\b/i;
|
|
23
|
+
/** Opener of a CodeGen item header comment, e.g. `/* Base View SQL for ... */`. */
|
|
24
|
+
const ITEM_OPENER = /^\s*\/\*/;
|
|
25
|
+
/** Hand-written stored routine — distinct from CodeGen sprocs (which live below the boundary). */
|
|
26
|
+
const HAND_PROCEDURAL = /\bCREATE\s+(?:OR\s+ALTER\s+)?(?:PROCEDURE|PROC|FUNCTION|TRIGGER)\b/i;
|
|
27
|
+
/**
|
|
28
|
+
* mj-sync session header (definitive). Emitted once at the top of a logging
|
|
29
|
+
* session; the only reliable way to tell a `*_Metadata_Sync` push apart from a
|
|
30
|
+
* hand-written `Backfill_*` DML migration. Matched on RAW lines (it lives in a
|
|
31
|
+
* `-- Description:` comment that the code scan strips out).
|
|
32
|
+
*/
|
|
33
|
+
const MJSYNC_SESSION_HEADER = /MetadataSync push operation/i;
|
|
34
|
+
/** mj-sync's hashed local-variable signature, e.g. `@Name_da319a9d`. Only mj-sync emits these. */
|
|
35
|
+
const MJSYNC_HASHED_VAR = /@\w+_[0-9a-f]{8}\b/;
|
|
36
|
+
/** Real schema DDL — the genuine transpilation surface. */
|
|
37
|
+
const SCHEMA_DDL = /\b(CREATE\s+TABLE|ALTER\s+TABLE|CREATE\s+(?:UNIQUE\s+)?(?:CLUSTERED\s+|NONCLUSTERED\s+)?INDEX|DROP\s+(?:TABLE|INDEX|CONSTRAINT)|ADD\s+CONSTRAINT)\b/i;
|
|
38
|
+
/** Data DML — transpilable, but in an mj-sync file it is just the metadata seed.
|
|
39
|
+
* No trailing \b: `UPDATE ${flyway:defaultSchema}.T` starts with `$` (non-word),
|
|
40
|
+
* so a trailing word-boundary assertion would silently fail to match. The leading
|
|
41
|
+
* `\b` + required whitespace (`\s+`) already prevents false matches inside words. */
|
|
42
|
+
const DATA_DML = /\b(INSERT\s+INTO|UPDATE\s+|DELETE\s+FROM)/i;
|
|
43
|
+
/** Max lines to walk up from a banner to its `/*` opener (header blocks are ~6-8 lines). */
|
|
44
|
+
const MAX_HEADER_WALKUP = 25;
|
|
45
|
+
/**
|
|
46
|
+
* Split a migration into its hand-authored and CodeGen-generated regions and
|
|
47
|
+
* recommend a routing. Pure function — no I/O.
|
|
48
|
+
*/
|
|
49
|
+
export function splitMigration(sql, fileName = '<inline>') {
|
|
50
|
+
const lines = sql.split('\n');
|
|
51
|
+
const boundary = findCodeGenBoundary(lines);
|
|
52
|
+
const handLines = boundary.line == null ? lines : lines.slice(0, boundary.line - 1);
|
|
53
|
+
const blockLines = boundary.line == null ? [] : lines.slice(boundary.line - 1);
|
|
54
|
+
const handAuthored = handLines.join('\n');
|
|
55
|
+
const codeGenBlock = blockLines.join('\n');
|
|
56
|
+
const handAuthoredRegions = classifyHandRegion(handLines);
|
|
57
|
+
return {
|
|
58
|
+
fileName,
|
|
59
|
+
totalLines: lines.length,
|
|
60
|
+
codeGenBoundaryLine: boundary.line,
|
|
61
|
+
boundaryMethod: boundary.method,
|
|
62
|
+
handAuthored,
|
|
63
|
+
codeGenBlock,
|
|
64
|
+
affectedEntities: extractAffectedEntities(codeGenBlock),
|
|
65
|
+
handAuthoredRegions,
|
|
66
|
+
routing: deriveRouting(handAuthoredRegions),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Locate the first line of the CodeGen block, preferring the explicit delimiter. */
|
|
70
|
+
function findCodeGenBoundary(lines) {
|
|
71
|
+
const runDelimiter = lines.findIndex((l) => CODE_GEN_RUN.test(l));
|
|
72
|
+
if (runDelimiter !== -1) {
|
|
73
|
+
return { line: runDelimiter + 1, method: 'code-gen-run-delimiter' };
|
|
74
|
+
}
|
|
75
|
+
const firstBanner = lines.findIndex((l) => GENERATED_BANNER.test(l));
|
|
76
|
+
if (firstBanner === -1) {
|
|
77
|
+
return { line: null, method: 'no-codegen-block' };
|
|
78
|
+
}
|
|
79
|
+
// Walk up from the banner to the `/*` opener of the item's header block.
|
|
80
|
+
const opener = walkUpToItemOpener(lines, firstBanner);
|
|
81
|
+
return { line: opener + 1, method: 'first-item-banner' };
|
|
82
|
+
}
|
|
83
|
+
/** From a banner line, find the nearest preceding `/*` opener (the item title line). */
|
|
84
|
+
function walkUpToItemOpener(lines, bannerIdx) {
|
|
85
|
+
const floor = Math.max(0, bannerIdx - MAX_HEADER_WALKUP);
|
|
86
|
+
for (let i = bannerIdx; i >= floor; i--) {
|
|
87
|
+
if (ITEM_OPENER.test(lines[i])) {
|
|
88
|
+
return i;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Fallback: no `/*` opener in the window — this item uses a `--` comment header
|
|
92
|
+
// (e.g. `-- Item: vwAIAgentRuns` under a dash rule). Split at the start of the
|
|
93
|
+
// banner's CONTIGUOUS comment/blank run only — backing up a fixed offset can land
|
|
94
|
+
// mid-statement and bisect a preceding INSERT (live hit: AIAgentRun_LastHeartbeatAt,
|
|
95
|
+
// whose registration INSERT lost its tail to the block and failed to parse).
|
|
96
|
+
let i = bannerIdx;
|
|
97
|
+
while (i - 1 >= floor && /^\s*(--.*)?$/.test(lines[i - 1])) {
|
|
98
|
+
i--;
|
|
99
|
+
}
|
|
100
|
+
return i;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Classify the hand-authored region. Scans on a comment/string-stripped copy so
|
|
104
|
+
* keywords inside comments or string literals don't produce false findings, while
|
|
105
|
+
* preserving original line numbers for evidence.
|
|
106
|
+
*/
|
|
107
|
+
function classifyHandRegion(handLines) {
|
|
108
|
+
const findings = [];
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
// The mj-sync session header lives in a comment, so detect it on raw lines
|
|
111
|
+
// before stripping. This is the definitive metadata-sync signal.
|
|
112
|
+
const headerIdx = handLines.findIndex((l) => MJSYNC_SESSION_HEADER.test(l));
|
|
113
|
+
if (headerIdx !== -1) {
|
|
114
|
+
addFindingOnce(findings, seen, { kind: 'metadata-sync', evidence: 'MetadataSync push operation' }, '', headerIdx + 1);
|
|
115
|
+
}
|
|
116
|
+
const code = stripCommentsPreservingLines(handLines);
|
|
117
|
+
for (let i = 0; i < code.length; i++) {
|
|
118
|
+
const line = code[i];
|
|
119
|
+
if (line.trim().length === 0)
|
|
120
|
+
continue;
|
|
121
|
+
addFindingOnce(findings, seen, classifyCodeLine(line), line, i + 1);
|
|
122
|
+
}
|
|
123
|
+
return findings;
|
|
124
|
+
}
|
|
125
|
+
/** Classify a single (comment-stripped) code line into a region kind, if it matches a signature. */
|
|
126
|
+
function classifyCodeLine(line) {
|
|
127
|
+
// Order matters: most-specific first. Procedural and mj-sync take precedence
|
|
128
|
+
// over generic DDL/DML because they imply special handling.
|
|
129
|
+
if (HAND_PROCEDURAL.test(line)) {
|
|
130
|
+
return { kind: 'hand-procedural', evidence: (line.match(HAND_PROCEDURAL) ?? [''])[0].trim() };
|
|
131
|
+
}
|
|
132
|
+
if (MJSYNC_HASHED_VAR.test(line)) {
|
|
133
|
+
return { kind: 'metadata-sync', evidence: (line.match(MJSYNC_HASHED_VAR) ?? [''])[0].trim() };
|
|
134
|
+
}
|
|
135
|
+
if (SCHEMA_DDL.test(line)) {
|
|
136
|
+
return { kind: 'schema-ddl', evidence: (line.match(SCHEMA_DDL) ?? [''])[0].trim() };
|
|
137
|
+
}
|
|
138
|
+
if (DATA_DML.test(line)) {
|
|
139
|
+
return { kind: 'data-dml', evidence: (line.match(DATA_DML) ?? [''])[0].trim() };
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
/** Record a finding only on first occurrence of its kind. */
|
|
144
|
+
function addFindingOnce(findings, seen, classified, _line, lineNo) {
|
|
145
|
+
if (!classified || seen.has(classified.kind))
|
|
146
|
+
return;
|
|
147
|
+
seen.add(classified.kind);
|
|
148
|
+
findings.push({ kind: classified.kind, evidence: classified.evidence, line: lineNo });
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Return a copy of the lines with comment and string-literal content blanked out,
|
|
152
|
+
* keeping the array length (and therefore line numbers) intact. Handles `--` line
|
|
153
|
+
* comments, `/* */` block comments, and `'...'` string literals (doubled-quote escapes).
|
|
154
|
+
*/
|
|
155
|
+
function stripCommentsPreservingLines(lines) {
|
|
156
|
+
const out = [];
|
|
157
|
+
let inBlockComment = false;
|
|
158
|
+
// T-SQL string literals span lines (mj-sync seeds embed whole prompt templates),
|
|
159
|
+
// so the in-string state must persist across lines exactly like block comments —
|
|
160
|
+
// otherwise literal content containing "ALTER TABLE"/"CREATE TABLE" text is
|
|
161
|
+
// scanned as code and misclassifies the file.
|
|
162
|
+
let inString = false;
|
|
163
|
+
for (const raw of lines) {
|
|
164
|
+
let result = '';
|
|
165
|
+
let i = 0;
|
|
166
|
+
while (i < raw.length) {
|
|
167
|
+
const two = raw.slice(i, i + 2);
|
|
168
|
+
if (inBlockComment) {
|
|
169
|
+
if (two === '*/') {
|
|
170
|
+
inBlockComment = false;
|
|
171
|
+
i += 2;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
i += 1;
|
|
175
|
+
}
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (inString) {
|
|
179
|
+
if (raw[i] === "'") {
|
|
180
|
+
if (raw[i + 1] === "'") {
|
|
181
|
+
i += 2;
|
|
182
|
+
continue;
|
|
183
|
+
} // escaped quote
|
|
184
|
+
inString = false;
|
|
185
|
+
}
|
|
186
|
+
i += 1;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (two === '--') {
|
|
190
|
+
break;
|
|
191
|
+
} // rest of line is a comment
|
|
192
|
+
if (two === '/*') {
|
|
193
|
+
inBlockComment = true;
|
|
194
|
+
i += 2;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (raw[i] === "'") {
|
|
198
|
+
inString = true;
|
|
199
|
+
i += 1;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
result += raw[i];
|
|
203
|
+
i += 1;
|
|
204
|
+
}
|
|
205
|
+
out.push(result);
|
|
206
|
+
}
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Derive the file-level routing from the hand-region findings.
|
|
211
|
+
*
|
|
212
|
+
* Order is significant:
|
|
213
|
+
* 1. Any hand-written procedural SQL → human authoring (we never auto-translate it).
|
|
214
|
+
* 2. Real schema DDL present → transpile (this is the genuine Category-B surface).
|
|
215
|
+
* A file with both schema DDL *and* mj-sync metadata is the rare mixed case —
|
|
216
|
+
* still routed to transpile so the DDL is not lost.
|
|
217
|
+
* 3. mj-sync metadata with no schema DDL → re-seed (the INSERT/UPDATE/DELETE in
|
|
218
|
+
* such a file is the metadata seed, reproduced by `mj sync push`, not real DDL).
|
|
219
|
+
* 4. Anything else with data DML to translate → transpile (e.g. a Backfill_*).
|
|
220
|
+
* 5. Nothing translatable → transpile-only with empty output (pure CodeGen file).
|
|
221
|
+
*/
|
|
222
|
+
function deriveRouting(findings) {
|
|
223
|
+
const has = (k) => findings.some((f) => f.kind === k);
|
|
224
|
+
if (has('hand-procedural'))
|
|
225
|
+
return 'needs-hand-authoring';
|
|
226
|
+
if (has('schema-ddl'))
|
|
227
|
+
return 'transpile-only';
|
|
228
|
+
if (has('metadata-sync'))
|
|
229
|
+
return 'transpile-plus-reseed';
|
|
230
|
+
return 'transpile-only';
|
|
231
|
+
}
|
|
232
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
233
|
+
// Affected-entity extraction (INLINE_CODEGEN_BAKING_PLAN.md §5)
|
|
234
|
+
//
|
|
235
|
+
// A CodeGen block names every entity it regenerated objects for, and the inline
|
|
236
|
+
// baker must regenerate exactly that set natively (`E(M)`) — no more (avoid ledger
|
|
237
|
+
// bloat / SS divergence), no less (a missed cascade `spDelete` diverges from SS).
|
|
238
|
+
//
|
|
239
|
+
// Three comment forms carry the entity name; we union them so one format drift
|
|
240
|
+
// can't drop an entity. All three carry the entity DISPLAY name ("MJ: AI Agent
|
|
241
|
+
// Runs") — we deliberately exclude the `Index for Foreign Keys for AIAgentRun`
|
|
242
|
+
// provenance and the `----- CREATE PROCEDURE FOR AIAgentRun` banner, which carry
|
|
243
|
+
// the bare table name.
|
|
244
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
245
|
+
/**
|
|
246
|
+
* Item provenance comment, e.g. `/* spCreate SQL for MJ: AI Agent Runs */` or
|
|
247
|
+
* `/* Base View Permissions for MJ: AI Agent Runs */`. The alternation is the
|
|
248
|
+
* allow-list of kinds whose `for <X>` carries the display name; `Index …` is
|
|
249
|
+
* intentionally absent (its `for <X>` is the table name).
|
|
250
|
+
*/
|
|
251
|
+
const CODEGEN_ITEM_PROVENANCE = /^\s*\/\*\s*(?:Base View|sp(?:Create|Update|Delete))\b[^*]*?\bfor\s+(.+?)\s*\*\//i;
|
|
252
|
+
/** Older base-view/-table header banner: `----- BASE VIEW FOR ENTITY: MJ: AI Agent Runs`. */
|
|
253
|
+
const BASE_OBJECT_BANNER = /^\s*-{3,}\s*BASE\s+(?:VIEW|TABLE)\s+FOR\s+ENTITY:\s*(.+?)\s*$/i;
|
|
254
|
+
/** SQL-Code-Generation header line `-- Entity: MJ: AI Agent Runs` (gated by a nearby `-- Item:`). */
|
|
255
|
+
const ENTITY_HEADER = /^\s*--\s*Entity:\s*(.+?)\s*$/i;
|
|
256
|
+
/** Its `-- Item: <object>` partner — proves the `-- Entity:` heads a generated item. */
|
|
257
|
+
const ITEM_HEADER = /^\s*--\s*Item:\s*\S/i;
|
|
258
|
+
/**
|
|
259
|
+
* Parse the ordered, de-duplicated entity display names whose objects a CodeGen
|
|
260
|
+
* block regenerated (`E(M)`). Pure — no I/O. Case-insensitive de-dup, first-seen
|
|
261
|
+
* order and casing preserved. Returns `[]` for an empty/absent block.
|
|
262
|
+
*/
|
|
263
|
+
export function extractAffectedEntities(codeGenBlock) {
|
|
264
|
+
if (!codeGenBlock)
|
|
265
|
+
return [];
|
|
266
|
+
const lines = codeGenBlock.split('\n');
|
|
267
|
+
const ordered = [];
|
|
268
|
+
const seen = new Set();
|
|
269
|
+
const add = (raw) => {
|
|
270
|
+
const name = raw.trim();
|
|
271
|
+
const key = name.toLowerCase();
|
|
272
|
+
if (name && !seen.has(key)) {
|
|
273
|
+
seen.add(key);
|
|
274
|
+
ordered.push(name);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
for (let i = 0; i < lines.length; i++) {
|
|
278
|
+
const provenance = lines[i].match(CODEGEN_ITEM_PROVENANCE);
|
|
279
|
+
if (provenance) {
|
|
280
|
+
add(provenance[1]);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const banner = lines[i].match(BASE_OBJECT_BANNER);
|
|
284
|
+
if (banner) {
|
|
285
|
+
add(banner[1]);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const entity = lines[i].match(ENTITY_HEADER);
|
|
289
|
+
if (entity && headsGeneratedItem(lines, i)) {
|
|
290
|
+
add(entity[1]);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return ordered;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* True when a `-- Entity:` line heads a generated item — its `-- Item:` partner
|
|
297
|
+
* follows within the same `--`-comment header block. This distinguishes an entity
|
|
298
|
+
* whose objects were emitted from one merely *mentioned* (e.g. an inline
|
|
299
|
+
* registration-INSERT comment, which is not part of a header block).
|
|
300
|
+
*/
|
|
301
|
+
function headsGeneratedItem(lines, entityIdx) {
|
|
302
|
+
for (let j = entityIdx + 1; j < lines.length && j <= entityIdx + 3; j++) {
|
|
303
|
+
if (ITEM_HEADER.test(lines[j]))
|
|
304
|
+
return true;
|
|
305
|
+
const t = lines[j].trim();
|
|
306
|
+
if (t !== '' && !t.startsWith('--'))
|
|
307
|
+
return false; // left the comment header block
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=MigrationSplitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigrationSplitter.js","sourceRoot":"","sources":["../src/MigrationSplitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAkEH,oFAAoF;AACpF,MAAM,gBAAgB,GAAG,wDAAwD,CAAC;AAClF,gGAAgG;AAChG,MAAM,YAAY,GAAG,uBAAuB,CAAC;AAC7C,oFAAoF;AACpF,MAAM,WAAW,GAAG,UAAU,CAAC;AAE/B,kGAAkG;AAClG,MAAM,eAAe,GAAG,qEAAqE,CAAC;AAC9F;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,8BAA8B,CAAC;AAC7D,kGAAkG;AAClG,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAC/C,2DAA2D;AAC3D,MAAM,UAAU,GAAG,sJAAsJ,CAAC;AAC1K;;;qFAGqF;AACrF,MAAM,QAAQ,GAAG,4CAA4C,CAAC;AAE9D,4FAA4F;AAC5F,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,QAAQ,GAAG,UAAU;IAC/D,MAAM,KAAK,GAAG,GAAG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,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,KAAe,EAAE,SAAiB;IAC5D,KAAK,IAAI,CAAC,GAAG,SAAS,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACxE,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QAC5C,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC,CAAC,gCAAgC;IACrF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MigrationStatementSplitter — statement-level (GO-batch) classification.
|
|
3
|
+
*
|
|
4
|
+
* The banner-based `MigrationSplitter` works for *feature* migrations (hand-DDL +
|
|
5
|
+
* CodeGen banner + generated block). It cannot handle **baselines** and other
|
|
6
|
+
* old-style files, which are squashed snapshots with NO banners — tables, views,
|
|
7
|
+
* sprocs, grants, and metadata INSERTs all flattened together, GO-separated.
|
|
8
|
+
*
|
|
9
|
+
* This classifier keys off GO-batch boundaries + the leading statement of each
|
|
10
|
+
* batch (and, for routines, the object NAME), so it separates content uniformly
|
|
11
|
+
* whether or not banners are present:
|
|
12
|
+
*
|
|
13
|
+
* keep/transpile : CREATE/ALTER TABLE · CREATE INDEX/TYPE · CREATE ROLE/SCHEMA
|
|
14
|
+
* · sp_addextendedproperty (→ COMMENT ON)
|
|
15
|
+
* drop+regenerate: CREATE VIEW/PROCEDURE/FUNCTION/TRIGGER whose name matches the
|
|
16
|
+
* CodeGen convention (vw, spCreate, spUpdate, spDelete, fn, …)
|
|
17
|
+
* + GRANT/REVOKE (CodeGen re-emits permissions)
|
|
18
|
+
* drop+reseed : metadata INSERT/UPDATE/DELETE (Entity/EntityField/… regenerated
|
|
19
|
+
* by CodeGen introspection; curated rows reseeded by `mj sync push`)
|
|
20
|
+
* flag : CREATE PROCEDURE/FUNCTION/TRIGGER NOT matching the CodeGen
|
|
21
|
+
* convention → hand-written, needs a human PG version
|
|
22
|
+
* noise : PRINT/SET/USE/GO/IF @@ERROR batch-control
|
|
23
|
+
*/
|
|
24
|
+
export type StatementKind = 'schema-ddl' | 'comment' | 'role-setup' | 'codegen-object' | 'grant' | 'metadata-dml' | 'hand-procedural' | 'noise' | 'unknown';
|
|
25
|
+
export interface StatementBatch {
|
|
26
|
+
kind: StatementKind;
|
|
27
|
+
/** Original SQL of the batch (verbatim, GO stripped). */
|
|
28
|
+
sql: string;
|
|
29
|
+
/** What matched (keyword / object name). */
|
|
30
|
+
evidence: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Split SQL into GO batches and classify each by its leading statement.
|
|
34
|
+
* Pure function — no I/O.
|
|
35
|
+
*/
|
|
36
|
+
export declare function splitByStatement(sql: string): StatementBatch[];
|
|
37
|
+
/** Roll up a classified batch list into per-kind counts (for census/reporting). */
|
|
38
|
+
export declare function summarizeStatements(batches: StatementBatch[]): Record<StatementKind, number>;
|
|
39
|
+
//# sourceMappingURL=MigrationStatementSplitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigrationStatementSplitter.d.ts","sourceRoot":"","sources":["../src/MigrationStatementSplitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,SAAS,GACT,YAAY,GACZ,gBAAgB,GAChB,OAAO,GACP,cAAc,GACd,iBAAiB,GACjB,OAAO,GACP,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,yDAAyD;IACzD,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAeD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,EAAE,CAM9D;AAqED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAO5F"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MigrationStatementSplitter — statement-level (GO-batch) classification.
|
|
3
|
+
*
|
|
4
|
+
* The banner-based `MigrationSplitter` works for *feature* migrations (hand-DDL +
|
|
5
|
+
* CodeGen banner + generated block). It cannot handle **baselines** and other
|
|
6
|
+
* old-style files, which are squashed snapshots with NO banners — tables, views,
|
|
7
|
+
* sprocs, grants, and metadata INSERTs all flattened together, GO-separated.
|
|
8
|
+
*
|
|
9
|
+
* This classifier keys off GO-batch boundaries + the leading statement of each
|
|
10
|
+
* batch (and, for routines, the object NAME), so it separates content uniformly
|
|
11
|
+
* whether or not banners are present:
|
|
12
|
+
*
|
|
13
|
+
* keep/transpile : CREATE/ALTER TABLE · CREATE INDEX/TYPE · CREATE ROLE/SCHEMA
|
|
14
|
+
* · sp_addextendedproperty (→ COMMENT ON)
|
|
15
|
+
* drop+regenerate: CREATE VIEW/PROCEDURE/FUNCTION/TRIGGER whose name matches the
|
|
16
|
+
* CodeGen convention (vw, spCreate, spUpdate, spDelete, fn, …)
|
|
17
|
+
* + GRANT/REVOKE (CodeGen re-emits permissions)
|
|
18
|
+
* drop+reseed : metadata INSERT/UPDATE/DELETE (Entity/EntityField/… regenerated
|
|
19
|
+
* by CodeGen introspection; curated rows reseeded by `mj sync push`)
|
|
20
|
+
* flag : CREATE PROCEDURE/FUNCTION/TRIGGER NOT matching the CodeGen
|
|
21
|
+
* convention → hand-written, needs a human PG version
|
|
22
|
+
* noise : PRINT/SET/USE/GO/IF @@ERROR batch-control
|
|
23
|
+
*/
|
|
24
|
+
const GO_SPLIT = /^[ \t]*GO[ \t]*;?[ \t]*$/im;
|
|
25
|
+
/** CodeGen routine/view/trigger naming conventions — these are regenerated, not translated. */
|
|
26
|
+
const CODEGEN_NAME = /^(spCreate|spUpdate|spDelete|spRecompile|vw|fn|trgUpdate|trgCreate|trgDelete|trg)/i;
|
|
27
|
+
/**
|
|
28
|
+
* Hand-written objects whose names collide with the CodeGen conventions. CodeGen does
|
|
29
|
+
* NOT regenerate these (they only exist in the baselines), so dropping them as
|
|
30
|
+
* codegen-objects would silently lose them on PG. Names are matched case-insensitively.
|
|
31
|
+
* Extend this list when a new custom `vw*`/`fn*` object is hand-authored in a migration.
|
|
32
|
+
*/
|
|
33
|
+
const HAND_WRITTEN_OBJECT_ALLOWLIST = new Set(['vwentitieswithexternalchangetracking']);
|
|
34
|
+
/**
|
|
35
|
+
* Split SQL into GO batches and classify each by its leading statement.
|
|
36
|
+
* Pure function — no I/O.
|
|
37
|
+
*/
|
|
38
|
+
export function splitByStatement(sql) {
|
|
39
|
+
return sql
|
|
40
|
+
.split(GO_SPLIT)
|
|
41
|
+
.map((b) => b.trim())
|
|
42
|
+
.filter((b) => b.length > 0)
|
|
43
|
+
.map(classifyBatch);
|
|
44
|
+
}
|
|
45
|
+
/** Classify one GO batch by its first meaningful statement. */
|
|
46
|
+
function classifyBatch(batch) {
|
|
47
|
+
const code = stripLeadingNoise(batch);
|
|
48
|
+
const head = code.slice(0, 200);
|
|
49
|
+
if (/\bsp_addextendedproperty\b/i.test(batch)) {
|
|
50
|
+
return { kind: 'comment', sql: batch, evidence: 'sp_addextendedproperty' };
|
|
51
|
+
}
|
|
52
|
+
if (/^\s*CREATE\s+TABLE\b/i.test(head))
|
|
53
|
+
return mk('schema-ddl', batch, 'CREATE TABLE');
|
|
54
|
+
if (/^\s*ALTER\s+TABLE\b/i.test(head))
|
|
55
|
+
return mk('schema-ddl', batch, 'ALTER TABLE');
|
|
56
|
+
if (/^\s*CREATE\s+(?:UNIQUE\s+)?(?:CLUSTERED\s+|NONCLUSTERED\s+)?INDEX\b/i.test(head))
|
|
57
|
+
return mk('schema-ddl', batch, 'CREATE INDEX');
|
|
58
|
+
if (/^\s*CREATE\s+TYPE\b/i.test(head))
|
|
59
|
+
return mk('schema-ddl', batch, 'CREATE TYPE');
|
|
60
|
+
if (/^\s*CREATE\s+(?:ROLE|SCHEMA|USER)\b/i.test(head))
|
|
61
|
+
return mk('role-setup', batch, 'CREATE ROLE/SCHEMA');
|
|
62
|
+
const routine = head.match(/^\s*CREATE\s+(?:OR\s+ALTER\s+)?(VIEW|PROCEDURE|PROC|FUNCTION|TRIGGER)\b/i);
|
|
63
|
+
if (routine) {
|
|
64
|
+
const name = extractObjectName(head);
|
|
65
|
+
if (name && HAND_WRITTEN_OBJECT_ALLOWLIST.has(name.toLowerCase())) {
|
|
66
|
+
// Hand-written despite the codegen-style name — keep + transpile.
|
|
67
|
+
return mk('schema-ddl', batch, `${routine[1]} ${name} (hand-written allowlist)`);
|
|
68
|
+
}
|
|
69
|
+
const isGenerated = !!name && CODEGEN_NAME.test(name);
|
|
70
|
+
return isGenerated
|
|
71
|
+
? mk('codegen-object', batch, `${routine[1]} ${name}`)
|
|
72
|
+
: mk('hand-procedural', batch, `${routine[1]} ${name ?? '?'}`);
|
|
73
|
+
}
|
|
74
|
+
if (/^\s*(?:GRANT|REVOKE|DENY)\b/i.test(head))
|
|
75
|
+
return mk('grant', batch, 'GRANT/REVOKE');
|
|
76
|
+
// SQL Server allows `INSERT [table]` without INTO — metadata seeds use that form.
|
|
77
|
+
if (/^\s*(?:INSERT\b|UPDATE\s|DELETE\s+FROM)/i.test(head))
|
|
78
|
+
return mk('metadata-dml', batch, 'INSERT/UPDATE/DELETE');
|
|
79
|
+
if (/^\s*(?:PRINT|SET|USE|IF\s+@@ERROR)\b/i.test(head) || head.length === 0) {
|
|
80
|
+
return mk('noise', batch, 'batch-control');
|
|
81
|
+
}
|
|
82
|
+
// DECLARE-led batches and dynamic SQL carry real statements (seed INSERTs, guarded
|
|
83
|
+
// DDL) — they are NOT noise. Classify as unknown so they flow to the AST transpiler,
|
|
84
|
+
// which either emits them or reports them in `unhandled`. Nothing silent.
|
|
85
|
+
if (/^\s*(?:DECLARE|EXEC(?:UTE)?\s+sp_executesql)\b/i.test(head)) {
|
|
86
|
+
return mk('unknown', batch, head.slice(0, 40).replace(/\s+/g, ' ').trim());
|
|
87
|
+
}
|
|
88
|
+
return mk('unknown', batch, head.slice(0, 40).replace(/\s+/g, ' ').trim());
|
|
89
|
+
}
|
|
90
|
+
/** Strip leading comment/PRINT/SET/IF-@@ERROR lines so the first real keyword is visible. */
|
|
91
|
+
function stripLeadingNoise(batch) {
|
|
92
|
+
const lines = batch.split('\n');
|
|
93
|
+
let i = 0;
|
|
94
|
+
while (i < lines.length) {
|
|
95
|
+
const t = lines[i].trim();
|
|
96
|
+
if (t === '' || t.startsWith('--') || /^PRINT\b/i.test(t) || /^SET\s+(NOEXEC|QUOTED_IDENTIFIER|ANSI_)/i.test(t) || /^IF\s+@@ERROR/i.test(t)) {
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return lines.slice(i).join('\n');
|
|
104
|
+
}
|
|
105
|
+
/** Pull the object name out of a CREATE VIEW/PROC/FUNCTION/TRIGGER header. */
|
|
106
|
+
function extractObjectName(head) {
|
|
107
|
+
const m = head.match(/CREATE\s+(?:OR\s+ALTER\s+)?(?:VIEW|PROCEDURE|PROC|FUNCTION|TRIGGER)\s+(?:\[?[\w${}:]+\]?\s*\.\s*)?\[?(\w+)\]?/i);
|
|
108
|
+
return m?.[1];
|
|
109
|
+
}
|
|
110
|
+
function mk(kind, sql, evidence) {
|
|
111
|
+
return { kind, sql, evidence };
|
|
112
|
+
}
|
|
113
|
+
/** Roll up a classified batch list into per-kind counts (for census/reporting). */
|
|
114
|
+
export function summarizeStatements(batches) {
|
|
115
|
+
const out = {
|
|
116
|
+
'schema-ddl': 0, comment: 0, 'role-setup': 0, 'codegen-object': 0,
|
|
117
|
+
grant: 0, 'metadata-dml': 0, 'hand-procedural': 0, noise: 0, unknown: 0,
|
|
118
|
+
};
|
|
119
|
+
for (const b of batches)
|
|
120
|
+
out[b.kind]++;
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=MigrationStatementSplitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigrationStatementSplitter.js","sourceRoot":"","sources":["../src/MigrationStatementSplitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAqBH,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAE9C,+FAA+F;AAC/F,MAAM,YAAY,GAAG,oFAAoF,CAAC;AAE1G;;;;;GAKG;AACH,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAC,CAAC,sCAAsC,CAAC,CAAC,CAAC;AAExF;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,GAAG;SACP,KAAK,CAAC,QAAQ,CAAC;SACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SAC3B,GAAG,CAAC,aAAa,CAAC,CAAC;AACxB,CAAC;AAED,+DAA+D;AAC/D,SAAS,aAAa,CAAC,KAAa;IAClC,MAAM,IAAI,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEhC,IAAI,6BAA6B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,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AAI,CAAC,EAAE,CAAC;IACvC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { ConversionPipeline } from './ConversionPipeline.js';
|
|
7
7
|
export { SQLFileSplitter } from './SQLFileSplitter.js';
|
|
8
|
+
export { splitMigration, extractAffectedEntities } from './MigrationSplitter.js';
|
|
9
|
+
export type { MigrationSplitResult, MigrationRegionKind, RegionFinding, BoundaryMethod, FileRouting, } from './MigrationSplitter.js';
|
|
10
|
+
export { convertMigration, extractKeptTSQL } from './MigrationConverter.js';
|
|
11
|
+
export { IncrementalBaker, stripVolatileHeaders } from './IncrementalBaker.js';
|
|
12
|
+
export type { BakerWorkingDB, CapturedEntitySQL, IncrementalBakerOptions, BakedMigrationResult, } from './IncrementalBaker.js';
|
|
13
|
+
export type { MigrationConversionResult, ConversionStatus, ConvertMigrationOptions, KeptTSQL, MJTranspileResult, TSQLToPGTranspiler, UnhandledStatement, } from './MigrationConverter.js';
|
|
14
|
+
export { splitByStatement, summarizeStatements } from './MigrationStatementSplitter.js';
|
|
15
|
+
export type { StatementBatch, StatementKind } from './MigrationStatementSplitter.js';
|
|
8
16
|
export { DatabaseAuditRunner } from './DatabaseAuditor.js';
|
|
9
17
|
export { NoOpLLMFallback } from './LLMFallback.js';
|
|
10
18
|
export type { ConversionPipelineConfig, ConversionResult, StatementResult, AuditReport, DatabaseInventory, RowCountMismatch, ILLMFallback, IDatabaseVerifier, IDatabaseAuditor, SQLDialect, } from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,mBA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WAAW,EACX,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,eAAe,EACf,SAAS,EACT,oBAAoB,EACpB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,UAAU,GACX,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAClF,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { ConversionPipeline } from './ConversionPipeline.js';
|
|
7
7
|
export { SQLFileSplitter } from './SQLFileSplitter.js';
|
|
8
|
+
export { splitMigration, extractAffectedEntities } from './MigrationSplitter.js';
|
|
9
|
+
export { convertMigration, extractKeptTSQL } from './MigrationConverter.js';
|
|
10
|
+
export { IncrementalBaker, stripVolatileHeaders } from './IncrementalBaker.js';
|
|
11
|
+
export { splitByStatement, summarizeStatements } from './MigrationStatementSplitter.js';
|
|
8
12
|
export { DatabaseAuditRunner } from './DatabaseAuditor.js';
|
|
9
13
|
export { NoOpLLMFallback } from './LLMFallback.js';
|
|
10
14
|
// Rule-based conversion system
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAcnD,+BAA+B;AAC/B,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,eAAe,EACf,SAAS,EACT,oBAAoB,EACpB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,YAAY,GACb,MAAM,kBAAkB,CAAC;AAc1B,mCAAmC;AACnC,OAAO,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAGlF,mBAAmB;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,kBAAkB,EAAE,M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/PostProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"PostProcessor.d.ts","sourceRoot":"","sources":["../../src/rules/PostProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAyW/C"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* INFORMATION_SCHEMA casing, long index name truncation, backslash line fix, etc.
|
|
7
7
|
*/
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
|
+
import { transformCodeOnly } from './ExpressionHelpers.js';
|
|
9
10
|
/**
|
|
10
11
|
* Final cleanup pass on the complete converted SQL output.
|
|
11
12
|
* Applied after all individual statement conversions are done.
|
|
@@ -157,9 +158,17 @@ export function postProcess(sql) {
|
|
|
157
158
|
// Quote unquoted table names after any schema prefix (PascalCase identifiers)
|
|
158
159
|
// e.g., __mj.OpenApp → __mj."OpenApp" but NOT __mj."OpenApp" (already quoted)
|
|
159
160
|
// Also skip all-lowercase names like __mj.information_schema
|
|
160
|
-
|
|
161
|
+
//
|
|
162
|
+
// transformCodeOnly is REQUIRED here: these regexes match `<word>.<PascalCase>`,
|
|
163
|
+
// which also occurs inside single-quoted string literals that carry TypeScript
|
|
164
|
+
// code (e.g. `GeneratedCode.Code` / `Action.Code` INSERT VALUES contain
|
|
165
|
+
// `this.GranteeType`, `result.Errors`, `params.Params`). Without skipping string
|
|
166
|
+
// literals, those TS member accesses get rewritten to `this."GranteeType"` etc.,
|
|
167
|
+
// producing invalid TypeScript that breaks the build when CodeGen re-emits it.
|
|
168
|
+
// A SQL->SQL converter must treat string-literal content as opaque data.
|
|
169
|
+
sql = transformCodeOnly(sql, (code) => code.replace(/(\b\w+)\.(?!")([A-Z][a-zA-Z_]\w*)/g, '$1."$2"'));
|
|
161
170
|
// Also handle quoted schema: "schema".PascalCase → "schema"."PascalCase"
|
|
162
|
-
sql = sql.replace(/"(\w+)"\.(?!")([A-Z][a-zA-Z_]\w*)/g, '"$1"."$2"');
|
|
171
|
+
sql = transformCodeOnly(sql, (code) => code.replace(/"(\w+)"\.(?!")([A-Z][a-zA-Z_]\w*)/g, '"$1"."$2"'));
|
|
163
172
|
// ISNULL → COALESCE (SQL Server function)
|
|
164
173
|
sql = sql.replace(/\bISNULL\s*\(/gi, 'COALESCE(');
|
|
165
174
|
// Safety net: convert any remaining GETUTCDATE/GETDATE → NOW()
|