@memberjunction/sql-converter 0.0.1 → 5.5.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/README.md +754 -28
- package/dist/ConversionPipeline.d.ts +31 -0
- package/dist/ConversionPipeline.d.ts.map +1 -0
- package/dist/ConversionPipeline.js +231 -0
- package/dist/ConversionPipeline.js.map +1 -0
- package/dist/DatabaseAuditor.d.ts +22 -0
- package/dist/DatabaseAuditor.d.ts.map +1 -0
- package/dist/DatabaseAuditor.js +115 -0
- package/dist/DatabaseAuditor.js.map +1 -0
- package/dist/LLMFallback.d.ts +13 -0
- package/dist/LLMFallback.d.ts.map +1 -0
- package/dist/LLMFallback.js +11 -0
- package/dist/LLMFallback.js.map +1 -0
- package/dist/SQLFileSplitter.d.ts +48 -0
- package/dist/SQLFileSplitter.d.ts.map +1 -0
- package/dist/SQLFileSplitter.js +212 -0
- package/dist/SQLFileSplitter.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/AlterTableRule.d.ts +23 -0
- package/dist/rules/AlterTableRule.d.ts.map +1 -0
- package/dist/rules/AlterTableRule.js +133 -0
- package/dist/rules/AlterTableRule.js.map +1 -0
- package/dist/rules/BatchConverter.d.ts +37 -0
- package/dist/rules/BatchConverter.d.ts.map +1 -0
- package/dist/rules/BatchConverter.js +561 -0
- package/dist/rules/BatchConverter.js.map +1 -0
- package/dist/rules/CatalogViewRule.d.ts +25 -0
- package/dist/rules/CatalogViewRule.d.ts.map +1 -0
- package/dist/rules/CatalogViewRule.js +294 -0
- package/dist/rules/CatalogViewRule.js.map +1 -0
- package/dist/rules/ConditionalDDLRule.d.ts +50 -0
- package/dist/rules/ConditionalDDLRule.d.ts.map +1 -0
- package/dist/rules/ConditionalDDLRule.js +234 -0
- package/dist/rules/ConditionalDDLRule.js.map +1 -0
- package/dist/rules/CreateIndexRule.d.ts +11 -0
- package/dist/rules/CreateIndexRule.d.ts.map +1 -0
- package/dist/rules/CreateIndexRule.js +66 -0
- package/dist/rules/CreateIndexRule.js.map +1 -0
- package/dist/rules/CreateTableRule.d.ts +42 -0
- package/dist/rules/CreateTableRule.d.ts.map +1 -0
- package/dist/rules/CreateTableRule.js +355 -0
- package/dist/rules/CreateTableRule.js.map +1 -0
- package/dist/rules/DialectHeaderBuilder.d.ts +39 -0
- package/dist/rules/DialectHeaderBuilder.d.ts.map +1 -0
- package/dist/rules/DialectHeaderBuilder.js +66 -0
- package/dist/rules/DialectHeaderBuilder.js.map +1 -0
- package/dist/rules/ExecBlockRule.d.ts +89 -0
- package/dist/rules/ExecBlockRule.d.ts.map +1 -0
- package/dist/rules/ExecBlockRule.js +491 -0
- package/dist/rules/ExecBlockRule.js.map +1 -0
- package/dist/rules/ExpressionHelpers.d.ts +71 -0
- package/dist/rules/ExpressionHelpers.d.ts.map +1 -0
- package/dist/rules/ExpressionHelpers.js +686 -0
- package/dist/rules/ExpressionHelpers.js.map +1 -0
- package/dist/rules/ExtendedPropertyRule.d.ts +16 -0
- package/dist/rules/ExtendedPropertyRule.d.ts.map +1 -0
- package/dist/rules/ExtendedPropertyRule.js +89 -0
- package/dist/rules/ExtendedPropertyRule.js.map +1 -0
- package/dist/rules/FunctionRule.d.ts +20 -0
- package/dist/rules/FunctionRule.d.ts.map +1 -0
- package/dist/rules/FunctionRule.js +374 -0
- package/dist/rules/FunctionRule.js.map +1 -0
- package/dist/rules/GrantRule.d.ts +11 -0
- package/dist/rules/GrantRule.d.ts.map +1 -0
- package/dist/rules/GrantRule.js +60 -0
- package/dist/rules/GrantRule.js.map +1 -0
- package/dist/rules/InsertRule.d.ts +18 -0
- package/dist/rules/InsertRule.d.ts.map +1 -0
- package/dist/rules/InsertRule.js +183 -0
- package/dist/rules/InsertRule.js.map +1 -0
- package/dist/rules/PostProcessor.d.ts +13 -0
- package/dist/rules/PostProcessor.d.ts.map +1 -0
- package/dist/rules/PostProcessor.js +252 -0
- package/dist/rules/PostProcessor.js.map +1 -0
- package/dist/rules/ProcedureToFunctionRule.d.ts +31 -0
- package/dist/rules/ProcedureToFunctionRule.d.ts.map +1 -0
- package/dist/rules/ProcedureToFunctionRule.js +805 -0
- package/dist/rules/ProcedureToFunctionRule.js.map +1 -0
- package/dist/rules/RuleRegistry.d.ts +48 -0
- package/dist/rules/RuleRegistry.d.ts.map +1 -0
- package/dist/rules/RuleRegistry.js +70 -0
- package/dist/rules/RuleRegistry.js.map +1 -0
- package/dist/rules/StatementClassifier.d.ts +11 -0
- package/dist/rules/StatementClassifier.d.ts.map +1 -0
- package/dist/rules/StatementClassifier.js +224 -0
- package/dist/rules/StatementClassifier.js.map +1 -0
- package/dist/rules/SubSplitter.d.ts +18 -0
- package/dist/rules/SubSplitter.d.ts.map +1 -0
- package/dist/rules/SubSplitter.js +211 -0
- package/dist/rules/SubSplitter.js.map +1 -0
- package/dist/rules/TSQLToPostgresRules.d.ts +22 -0
- package/dist/rules/TSQLToPostgresRules.d.ts.map +1 -0
- package/dist/rules/TSQLToPostgresRules.js +59 -0
- package/dist/rules/TSQLToPostgresRules.js.map +1 -0
- package/dist/rules/TriggerRule.d.ts +22 -0
- package/dist/rules/TriggerRule.d.ts.map +1 -0
- package/dist/rules/TriggerRule.js +197 -0
- package/dist/rules/TriggerRule.js.map +1 -0
- package/dist/rules/TypeResolver.d.ts +35 -0
- package/dist/rules/TypeResolver.d.ts.map +1 -0
- package/dist/rules/TypeResolver.js +112 -0
- package/dist/rules/TypeResolver.js.map +1 -0
- package/dist/rules/ViewRule.d.ts +28 -0
- package/dist/rules/ViewRule.d.ts.map +1 -0
- package/dist/rules/ViewRule.js +299 -0
- package/dist/rules/ViewRule.js.map +1 -0
- package/dist/rules/index.d.ts +29 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +33 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/types.d.ts +123 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +57 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/types.d.ts +146 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +28 -7
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ConversionPipelineConfig, ConversionResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Orchestrates SQL file conversion from one dialect to another.
|
|
4
|
+
*
|
|
5
|
+
* Pipeline steps:
|
|
6
|
+
* 1. Read source SQL (from file or string)
|
|
7
|
+
* 2. Split into individual statements
|
|
8
|
+
* 3. Transpile each statement via sqlglot
|
|
9
|
+
* 4. Optionally verify against target database
|
|
10
|
+
* 5. Optionally use LLM fallback for failed statements
|
|
11
|
+
* 6. Write output and generate statistics
|
|
12
|
+
*/
|
|
13
|
+
export declare class ConversionPipeline {
|
|
14
|
+
private client;
|
|
15
|
+
private readonly splitter;
|
|
16
|
+
/**
|
|
17
|
+
* Run the conversion pipeline.
|
|
18
|
+
* Manages the sqlglot client lifecycle internally.
|
|
19
|
+
*/
|
|
20
|
+
Run(config: ConversionPipelineConfig): Promise<ConversionResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Process a single statement through the conversion pipeline.
|
|
23
|
+
*/
|
|
24
|
+
private processStatement;
|
|
25
|
+
/**
|
|
26
|
+
* Attempt LLM-based fix for a failed conversion.
|
|
27
|
+
*/
|
|
28
|
+
private tryLLMFallback;
|
|
29
|
+
private buildResult;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ConversionPipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversionPipeline.d.ts","sourceRoot":"","sources":["../src/ConversionPipeline.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,wBAAwB,EACxB,gBAAgB,EAIjB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;GAUG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAElD;;;OAGG;IACG,GAAG,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAiFtE;;OAEG;YACW,gBAAgB;IAkG9B;;OAEG;YACW,cAAc;IAuE5B,OAAO,CAAC,WAAW;CA0BpB"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { SqlGlotClient } from '@memberjunction/sqlglot-ts';
|
|
3
|
+
import { SQLFileSplitter } from './SQLFileSplitter.js';
|
|
4
|
+
import { NoOpLLMFallback } from './LLMFallback.js';
|
|
5
|
+
/**
|
|
6
|
+
* Orchestrates SQL file conversion from one dialect to another.
|
|
7
|
+
*
|
|
8
|
+
* Pipeline steps:
|
|
9
|
+
* 1. Read source SQL (from file or string)
|
|
10
|
+
* 2. Split into individual statements
|
|
11
|
+
* 3. Transpile each statement via sqlglot
|
|
12
|
+
* 4. Optionally verify against target database
|
|
13
|
+
* 5. Optionally use LLM fallback for failed statements
|
|
14
|
+
* 6. Write output and generate statistics
|
|
15
|
+
*/
|
|
16
|
+
export class ConversionPipeline {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.client = null;
|
|
19
|
+
this.splitter = new SQLFileSplitter();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Run the conversion pipeline.
|
|
23
|
+
* Manages the sqlglot client lifecycle internally.
|
|
24
|
+
*/
|
|
25
|
+
async Run(config) {
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
const log = config.onProgress ?? (() => { });
|
|
28
|
+
// Read source SQL
|
|
29
|
+
log('Reading source SQL...');
|
|
30
|
+
const sourceSQL = config.sourceIsFile
|
|
31
|
+
? readFileSync(config.source, 'utf-8')
|
|
32
|
+
: config.source;
|
|
33
|
+
// Split into statements
|
|
34
|
+
log('Splitting into statements...');
|
|
35
|
+
const statements = this.splitter.Split(sourceSQL, config.sourceDialect);
|
|
36
|
+
log(`Found ${statements.length} statements`);
|
|
37
|
+
if (statements.length === 0) {
|
|
38
|
+
return this.buildResult([], '', config, startTime);
|
|
39
|
+
}
|
|
40
|
+
// Start sqlglot client
|
|
41
|
+
log('Starting sqlglot transpiler...');
|
|
42
|
+
this.client = new SqlGlotClient();
|
|
43
|
+
await this.client.start();
|
|
44
|
+
const llmFallback = config.llmFallbackHandler ?? new NoOpLLMFallback();
|
|
45
|
+
const verifier = config.verifier;
|
|
46
|
+
try {
|
|
47
|
+
const results = [];
|
|
48
|
+
for (let i = 0; i < statements.length; i++) {
|
|
49
|
+
const stmt = statements[i];
|
|
50
|
+
log(`[${i + 1}/${statements.length}] Converting...`);
|
|
51
|
+
const result = await this.processStatement(i, stmt, config, llmFallback, verifier, log);
|
|
52
|
+
results.push(result);
|
|
53
|
+
if (!result.success && config.stopOnError) {
|
|
54
|
+
log(`Stopping on error at statement ${i + 1}: ${result.error}`);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Build output SQL
|
|
59
|
+
const outputParts = [];
|
|
60
|
+
for (const r of results) {
|
|
61
|
+
if (r.success) {
|
|
62
|
+
outputParts.push(r.convertedSQL);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
outputParts.push(`-- CONVERSION FAILED (statement ${r.index + 1}): ${r.error ?? 'unknown error'}\n-- Original: ${r.originalSQL.slice(0, 200).replace(/\n/g, '\n-- ')}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const outputSQL = outputParts.join(';\n\n') + (outputParts.length > 0 ? ';' : '');
|
|
69
|
+
// Write output file
|
|
70
|
+
if (config.outputFile) {
|
|
71
|
+
log(`Writing output to ${config.outputFile}...`);
|
|
72
|
+
writeFileSync(config.outputFile, outputSQL, 'utf-8');
|
|
73
|
+
}
|
|
74
|
+
return this.buildResult(results, outputSQL, config, startTime);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
// Always clean up
|
|
78
|
+
if (this.client) {
|
|
79
|
+
await this.client.stop();
|
|
80
|
+
this.client = null;
|
|
81
|
+
}
|
|
82
|
+
if (verifier) {
|
|
83
|
+
await verifier.Close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Process a single statement through the conversion pipeline.
|
|
89
|
+
*/
|
|
90
|
+
async processStatement(index, originalSQL, config, llmFallback, verifier, log) {
|
|
91
|
+
// Step 1: Try sqlglot transpilation
|
|
92
|
+
let transpileResult;
|
|
93
|
+
try {
|
|
94
|
+
transpileResult = await this.client.transpile(originalSQL, {
|
|
95
|
+
fromDialect: config.sourceDialect,
|
|
96
|
+
toDialect: config.targetDialect,
|
|
97
|
+
pretty: config.pretty,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
102
|
+
return {
|
|
103
|
+
index,
|
|
104
|
+
originalSQL,
|
|
105
|
+
convertedSQL: '',
|
|
106
|
+
success: false,
|
|
107
|
+
verified: false,
|
|
108
|
+
method: 'failed',
|
|
109
|
+
error: `sqlglot transpile error: ${error}`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (!transpileResult.success || transpileResult.errors.length > 0) {
|
|
113
|
+
// sqlglot failed — try LLM fallback
|
|
114
|
+
if (config.llmFallback) {
|
|
115
|
+
return this.tryLLMFallback(index, originalSQL, transpileResult.sql, transpileResult.errors.join('; '), config, llmFallback, verifier, log);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
index,
|
|
119
|
+
originalSQL,
|
|
120
|
+
convertedSQL: transpileResult.sql,
|
|
121
|
+
success: false,
|
|
122
|
+
verified: false,
|
|
123
|
+
method: 'failed',
|
|
124
|
+
error: transpileResult.errors.join('; '),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
let convertedSQL = transpileResult.sql;
|
|
128
|
+
// Remove trailing semicolons added by sqlglot — we add our own
|
|
129
|
+
convertedSQL = convertedSQL.replace(/;\s*$/, '').trim();
|
|
130
|
+
// Step 2: Optionally verify against target database
|
|
131
|
+
if (config.verify && verifier) {
|
|
132
|
+
const verifyError = await verifier.Verify(convertedSQL);
|
|
133
|
+
if (verifyError) {
|
|
134
|
+
log(` Verification failed: ${verifyError.slice(0, 100)}`);
|
|
135
|
+
// Try LLM fallback for verification failures
|
|
136
|
+
if (config.llmFallback) {
|
|
137
|
+
return this.tryLLMFallback(index, originalSQL, convertedSQL, verifyError, config, llmFallback, verifier, log);
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
index,
|
|
141
|
+
originalSQL,
|
|
142
|
+
convertedSQL,
|
|
143
|
+
success: false,
|
|
144
|
+
verified: false,
|
|
145
|
+
method: 'sqlglot',
|
|
146
|
+
error: `Verification failed: ${verifyError}`,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
index,
|
|
152
|
+
originalSQL,
|
|
153
|
+
convertedSQL,
|
|
154
|
+
success: true,
|
|
155
|
+
verified: config.verify && verifier !== undefined,
|
|
156
|
+
method: 'sqlglot',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Attempt LLM-based fix for a failed conversion.
|
|
161
|
+
*/
|
|
162
|
+
async tryLLMFallback(index, originalSQL, failedSQL, error, config, llmFallback, verifier, log) {
|
|
163
|
+
let lastError = error;
|
|
164
|
+
let currentFailedSQL = failedSQL;
|
|
165
|
+
for (let attempt = 0; attempt < config.maxLLMRetries; attempt++) {
|
|
166
|
+
log(` LLM fallback attempt ${attempt + 1}/${config.maxLLMRetries}...`);
|
|
167
|
+
const llmResult = await llmFallback.FixConversion(originalSQL, currentFailedSQL, lastError, config.sourceDialect, config.targetDialect);
|
|
168
|
+
if (!llmResult.sql) {
|
|
169
|
+
return {
|
|
170
|
+
index,
|
|
171
|
+
originalSQL,
|
|
172
|
+
convertedSQL: currentFailedSQL,
|
|
173
|
+
success: false,
|
|
174
|
+
verified: false,
|
|
175
|
+
method: 'failed',
|
|
176
|
+
error: `LLM fallback returned null after ${attempt + 1} attempts. Last error: ${lastError}`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
let llmSQL = llmResult.sql.replace(/;\s*$/, '').trim();
|
|
180
|
+
// Verify LLM output if verification is enabled
|
|
181
|
+
if (config.verify && verifier) {
|
|
182
|
+
const verifyError = await verifier.Verify(llmSQL);
|
|
183
|
+
if (verifyError) {
|
|
184
|
+
log(` LLM output verification failed: ${verifyError.slice(0, 100)}`);
|
|
185
|
+
lastError = verifyError;
|
|
186
|
+
currentFailedSQL = llmSQL;
|
|
187
|
+
continue; // Retry with LLM
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
index,
|
|
192
|
+
originalSQL,
|
|
193
|
+
convertedSQL: llmSQL,
|
|
194
|
+
success: true,
|
|
195
|
+
verified: config.verify && verifier !== undefined,
|
|
196
|
+
method: 'llm',
|
|
197
|
+
llmModel: llmResult.model,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
index,
|
|
202
|
+
originalSQL,
|
|
203
|
+
convertedSQL: currentFailedSQL,
|
|
204
|
+
success: false,
|
|
205
|
+
verified: false,
|
|
206
|
+
method: 'failed',
|
|
207
|
+
error: `LLM fallback exhausted ${config.maxLLMRetries} retries. Last error: ${lastError}`,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
buildResult(statements, outputSQL, config, startTime) {
|
|
211
|
+
const successCount = statements.filter((s) => s.success).length;
|
|
212
|
+
const failureCount = statements.filter((s) => !s.success).length;
|
|
213
|
+
const sqlglotCount = statements.filter((s) => s.method === 'sqlglot' && s.success).length;
|
|
214
|
+
const llmCount = statements.filter((s) => s.method === 'llm' && s.success).length;
|
|
215
|
+
const passthroughCount = statements.filter((s) => s.method === 'passthrough').length;
|
|
216
|
+
return {
|
|
217
|
+
success: failureCount === 0,
|
|
218
|
+
totalStatements: statements.length,
|
|
219
|
+
successCount,
|
|
220
|
+
failureCount,
|
|
221
|
+
sqlglotCount,
|
|
222
|
+
llmCount,
|
|
223
|
+
passthroughCount,
|
|
224
|
+
statements,
|
|
225
|
+
outputFile: config.outputFile,
|
|
226
|
+
outputSQL,
|
|
227
|
+
durationMs: Date.now() - startTime,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=ConversionPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversionPipeline.js","sourceRoot":"","sources":["../src/ConversionPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AASnD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IAA/B;QACU,WAAM,GAAyB,IAAI,CAAC;QAC3B,aAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IAgSpD,CAAC;IA9RC;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,MAAgC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAE5C,kBAAkB;QAClB,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,YAAY;YACnC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;YACtC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;QAElB,w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C,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,aAAa,CAAC,CAAC,MAAM,CAAC;QAErF,OAAO;YACL,OAAO,EAAE,YAAY,KAAK,CAAC;YAC3B,eAAe,EAAE,UAAU,CAAC,MAAM;YAClC,YAAY;YACZ,YAAY;YACZ,YAAY;YACZ,QAAQ;YACR,gBAAgB;YAChB,UAAU;YACV,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,SAAS;YACT,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;SACnC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IDatabaseAuditor, AuditReport } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compares source and target database inventories to produce an audit report.
|
|
4
|
+
* Uses pluggable IDatabaseAuditor implementations for actual database access.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DatabaseAuditRunner {
|
|
7
|
+
/**
|
|
8
|
+
* Run an audit comparing source and target databases.
|
|
9
|
+
* @param sourceAuditor Auditor connected to the source database
|
|
10
|
+
* @param targetAuditor Auditor connected to the target database
|
|
11
|
+
* @param sourceSchema Schema name in source database
|
|
12
|
+
* @param targetSchema Schema name in target database
|
|
13
|
+
*/
|
|
14
|
+
RunAudit(sourceAuditor: IDatabaseAuditor, targetAuditor: IDatabaseAuditor, sourceSchema?: string, targetSchema?: string): Promise<AuditReport>;
|
|
15
|
+
/**
|
|
16
|
+
* Format an audit report as a human-readable string.
|
|
17
|
+
*/
|
|
18
|
+
FormatReport(report: AuditReport): string;
|
|
19
|
+
private findMissing;
|
|
20
|
+
private compareRowCounts;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=DatabaseAuditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseAuditor.d.ts","sourceRoot":"","sources":["../src/DatabaseAuditor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EAGZ,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B;;;;;;OAMG;IACG,QAAQ,CACZ,aAAa,EAAE,gBAAgB,EAC/B,aAAa,EAAE,gBAAgB,EAC/B,YAAY,CAAC,EAAE,MAAM,EACrB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,WAAW,CAAC;IAoBvB;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM;IA4CzC,OAAO,CAAC,WAAW;IA+BnB,OAAO,CAAC,gBAAgB;CAmBzB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares source and target database inventories to produce an audit report.
|
|
3
|
+
* Uses pluggable IDatabaseAuditor implementations for actual database access.
|
|
4
|
+
*/
|
|
5
|
+
export class DatabaseAuditRunner {
|
|
6
|
+
/**
|
|
7
|
+
* Run an audit comparing source and target databases.
|
|
8
|
+
* @param sourceAuditor Auditor connected to the source database
|
|
9
|
+
* @param targetAuditor Auditor connected to the target database
|
|
10
|
+
* @param sourceSchema Schema name in source database
|
|
11
|
+
* @param targetSchema Schema name in target database
|
|
12
|
+
*/
|
|
13
|
+
async RunAudit(sourceAuditor, targetAuditor, sourceSchema, targetSchema) {
|
|
14
|
+
const [sourceInventory, targetInventory, sourceRowCounts, targetRowCounts] = await Promise.all([
|
|
15
|
+
sourceAuditor.GetInventory(sourceSchema),
|
|
16
|
+
targetAuditor.GetInventory(targetSchema),
|
|
17
|
+
sourceAuditor.GetRowCounts(sourceSchema),
|
|
18
|
+
targetAuditor.GetRowCounts(targetSchema),
|
|
19
|
+
]);
|
|
20
|
+
const missing = this.findMissing(sourceInventory, targetInventory);
|
|
21
|
+
const rowCountMismatches = this.compareRowCounts(sourceRowCounts, targetRowCounts);
|
|
22
|
+
return {
|
|
23
|
+
source: sourceInventory,
|
|
24
|
+
target: targetInventory,
|
|
25
|
+
missing,
|
|
26
|
+
rowCountMismatches,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format an audit report as a human-readable string.
|
|
31
|
+
*/
|
|
32
|
+
FormatReport(report) {
|
|
33
|
+
const lines = [];
|
|
34
|
+
lines.push('=== SQL Conversion Audit Report ===');
|
|
35
|
+
lines.push('');
|
|
36
|
+
lines.push('--- Source Database ---');
|
|
37
|
+
lines.push(` Tables: ${report.source.tables.length}`);
|
|
38
|
+
lines.push(` Views: ${report.source.views.length}`);
|
|
39
|
+
lines.push(` Functions: ${report.source.functions.length}`);
|
|
40
|
+
lines.push(` Triggers: ${report.source.triggers.length}`);
|
|
41
|
+
lines.push(` Indexes: ${report.source.indexes.length}`);
|
|
42
|
+
lines.push('');
|
|
43
|
+
lines.push('--- Target Database ---');
|
|
44
|
+
lines.push(` Tables: ${report.target.tables.length}`);
|
|
45
|
+
lines.push(` Views: ${report.target.views.length}`);
|
|
46
|
+
lines.push(` Functions: ${report.target.functions.length}`);
|
|
47
|
+
lines.push(` Triggers: ${report.target.triggers.length}`);
|
|
48
|
+
lines.push(` Indexes: ${report.target.indexes.length}`);
|
|
49
|
+
lines.push('');
|
|
50
|
+
if (report.missing.length > 0) {
|
|
51
|
+
lines.push(`--- Missing from Target (${report.missing.length}) ---`);
|
|
52
|
+
for (const obj of report.missing) {
|
|
53
|
+
lines.push(` - ${obj}`);
|
|
54
|
+
}
|
|
55
|
+
lines.push('');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
lines.push('--- No Missing Objects ---');
|
|
59
|
+
lines.push('');
|
|
60
|
+
}
|
|
61
|
+
if (report.rowCountMismatches.length > 0) {
|
|
62
|
+
lines.push(`--- Row Count Mismatches (${report.rowCountMismatches.length}) ---`);
|
|
63
|
+
for (const m of report.rowCountMismatches) {
|
|
64
|
+
lines.push(` ${m.tableName}: source=${m.sourceCount}, target=${m.targetCount}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
lines.push('--- Row Counts Match ---');
|
|
69
|
+
}
|
|
70
|
+
return lines.join('\n');
|
|
71
|
+
}
|
|
72
|
+
findMissing(source, target) {
|
|
73
|
+
const missing = [];
|
|
74
|
+
const targetTableSet = new Set(target.tables.map((t) => t.toLowerCase()));
|
|
75
|
+
const targetViewSet = new Set(target.views.map((v) => v.toLowerCase()));
|
|
76
|
+
const targetFuncSet = new Set(target.functions.map((f) => f.toLowerCase()));
|
|
77
|
+
const targetTriggerSet = new Set(target.triggers.map((t) => t.toLowerCase()));
|
|
78
|
+
for (const t of source.tables) {
|
|
79
|
+
if (!targetTableSet.has(t.toLowerCase())) {
|
|
80
|
+
missing.push(`TABLE: ${t}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const v of source.views) {
|
|
84
|
+
if (!targetViewSet.has(v.toLowerCase())) {
|
|
85
|
+
missing.push(`VIEW: ${v}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const f of source.functions) {
|
|
89
|
+
if (!targetFuncSet.has(f.toLowerCase())) {
|
|
90
|
+
missing.push(`FUNCTION: ${f}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const t of source.triggers) {
|
|
94
|
+
if (!targetTriggerSet.has(t.toLowerCase())) {
|
|
95
|
+
missing.push(`TRIGGER: ${t}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return missing;
|
|
99
|
+
}
|
|
100
|
+
compareRowCounts(source, target) {
|
|
101
|
+
const mismatches = [];
|
|
102
|
+
for (const [tableName, sourceCount] of source) {
|
|
103
|
+
const targetCount = target.get(tableName.toLowerCase()) ?? target.get(tableName) ?? -1;
|
|
104
|
+
if (targetCount === -1) {
|
|
105
|
+
// Table missing from target — already reported in missing objects
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (sourceCount !== targetCount) {
|
|
109
|
+
mismatches.push({ tableName, sourceCount, targetCount });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return mismatches;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=DatabaseAuditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseAuditor.js","sourceRoot":"","sources":["../src/DatabaseAuditor.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAC9B;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CACZ,aAA+B,EAC/B,aAA+B,EAC/B,YAAqB,EACrB,YAAqB;QAErB,MAAM,CAAC,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,CAAC,GACxE,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,aAAa,CAAC,YAAY,CAAC,YAAY,CAAC;YACxC,aAAa,CAAC,YAAY,CAAC,YAAY,CAAC;YACxC,aAAa,CAAC,YAAY,CAAC,YAAY,CAAC;YACxC,aAAa,CAAC,YAAY,CAAC,YAAY,CAAC;SACzC,CAAC,CAAC;QAEL,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;QACnE,MAAM,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;QAEnF,OAAO;YACL,MAAM,EAAE,eAAe;YACvB,MAAM,EAAE,eAAe;YACvB,OAAO;YACP,kBAAkB;SACnB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,MAAmB;QAC9B,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QAClD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEf,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;QACtC,KAAK,CAAC,IAAI,CAAC,gBAAgB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAC1D,KA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3B,MAAM,UAAU,GAAuB,EAAE,CAAC;QAE1C,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,MAAM,EAAE,CAAC;YAC9C,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YACvF,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;gBACvB,kEAAkE;gBAClE,SAAS;YACX,CAAC;YACD,IAAI,WAAW,KAAK,WAAW,EAAE,CAAC;gBAChC,UAAU,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ILLMFallback } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default no-op LLM fallback implementation.
|
|
4
|
+
* Always returns null (no LLM available).
|
|
5
|
+
* Replace with a real implementation to enable LLM-based SQL fix-up.
|
|
6
|
+
*/
|
|
7
|
+
export declare class NoOpLLMFallback implements ILLMFallback {
|
|
8
|
+
FixConversion(): Promise<{
|
|
9
|
+
sql: string | null;
|
|
10
|
+
model?: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=LLMFallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLMFallback.d.ts","sourceRoot":"","sources":["../src/LLMFallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAC5C,aAAa,IAAI,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAGvE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default no-op LLM fallback implementation.
|
|
3
|
+
* Always returns null (no LLM available).
|
|
4
|
+
* Replace with a real implementation to enable LLM-based SQL fix-up.
|
|
5
|
+
*/
|
|
6
|
+
export class NoOpLLMFallback {
|
|
7
|
+
async FixConversion() {
|
|
8
|
+
return { sql: null };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=LLMFallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LLMFallback.js","sourceRoot":"","sources":["../src/LLMFallback.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAC1B,KAAK,CAAC,aAAa;QACjB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a SQL file into individual statements, handling:
|
|
3
|
+
* - T-SQL GO batch separators
|
|
4
|
+
* - Semicolon-delimited statements
|
|
5
|
+
* - Multi-line string literals (single quotes)
|
|
6
|
+
* - Dollar-quoted strings ($$...$$ in PostgreSQL)
|
|
7
|
+
* - Block comments
|
|
8
|
+
* - Line comments (-- ...)
|
|
9
|
+
* - BEGIN...END blocks (don't split inside them)
|
|
10
|
+
* - CREATE FUNCTION/PROCEDURE bodies
|
|
11
|
+
* - Empty statements and whitespace-only segments
|
|
12
|
+
*/
|
|
13
|
+
export declare class SQLFileSplitter {
|
|
14
|
+
/**
|
|
15
|
+
* Split SQL text into individual statements.
|
|
16
|
+
* @param sql The full SQL file content
|
|
17
|
+
* @param dialect 'tsql' uses GO as batch separator, others use semicolons
|
|
18
|
+
* @returns Array of non-empty SQL statements
|
|
19
|
+
*/
|
|
20
|
+
Split(sql: string, dialect?: 'tsql' | 'postgres' | string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Split by T-SQL GO batch separator.
|
|
23
|
+
* GO must appear on its own line (case-insensitive), optionally preceded/followed by whitespace.
|
|
24
|
+
*/
|
|
25
|
+
private splitByGo;
|
|
26
|
+
/**
|
|
27
|
+
* Split by semicolons, respecting:
|
|
28
|
+
* - String literals (single quotes)
|
|
29
|
+
* - Dollar-quoted strings ($tag$...$tag$)
|
|
30
|
+
* - Block comments
|
|
31
|
+
* - Line comments
|
|
32
|
+
* - BEGIN...END blocks
|
|
33
|
+
* - CREATE FUNCTION/PROCEDURE bodies
|
|
34
|
+
*/
|
|
35
|
+
private splitBySemicolon;
|
|
36
|
+
/** Find the end of a block comment, handling nested comments */
|
|
37
|
+
private findBlockCommentEnd;
|
|
38
|
+
/** Consume a dollar-quoted string ($tag$...$tag$) */
|
|
39
|
+
private consumeDollarQuote;
|
|
40
|
+
/** Consume a single-quoted string literal, handling escaped quotes ('') */
|
|
41
|
+
private consumeStringLiteral;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a keyword appears at position i, bounded by non-word chars.
|
|
44
|
+
* Case-insensitive.
|
|
45
|
+
*/
|
|
46
|
+
private matchesKeyword;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=SQLFileSplitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQLFileSplitter.d.ts","sourceRoot":"","sources":["../src/SQLFileSplitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,qBAAa,eAAe;IAC1B;;;;;OAKG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,GAAG,UAAU,GAAG,MAAe,GAAG,MAAM,EAAE;IAO5E;;;OAGG;IACH,OAAO,CAAC,SAAS;IA4BjB;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IAkFxB,gEAAgE;IAChE,OAAO,CAAC,mBAAmB;IAiB3B,qDAAqD;IACrD,OAAO,CAAC,kBAAkB;IAoB1B,2EAA2E;IAC3E,OAAO,CAAC,oBAAoB;IAoB5B;;;OAGG;IACH,OAAO,CAAC,cAAc;CAavB"}
|