mcp-migration-advisor 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/build/analyzers/data-loss.js +3 -3
- package/build/analyzers/lock-risk.js +1 -1
- package/build/generators/rollback.js +16 -0
- package/build/index.js +8 -4
- package/build/parsers/flyway-sql.js +40 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,19 @@ Unlike MigrationPilot (PG-only, raw SQL analysis), this tool **parses Liquibase
|
|
|
22
22
|
- **Rollback Validation**: Checks rollback completeness for each changeSet
|
|
23
23
|
- **Actionable Recommendations**: Every risk includes a specific safe alternative
|
|
24
24
|
|
|
25
|
+
## Pro Tier
|
|
26
|
+
|
|
27
|
+
**Generate exportable diagnostic reports (HTML + PDF)** with a Pro license key.
|
|
28
|
+
|
|
29
|
+
- Full JVM thread dump analysis report with actionable recommendations
|
|
30
|
+
- PDF export for sharing with your team
|
|
31
|
+
- Priority support
|
|
32
|
+
|
|
33
|
+
<!-- TODO: replace placeholder Stripe Payment Link once STRIPE_SECRET_KEY is configured -->
|
|
34
|
+
**$9.99/month** — [Get Pro License](https://buy.stripe.com/PLACEHOLDER)
|
|
35
|
+
|
|
36
|
+
Pro license key activates the `generate_report` MCP tool in mcp-jvm-diagnostics.
|
|
37
|
+
|
|
25
38
|
## Installation
|
|
26
39
|
|
|
27
40
|
```bash
|
|
@@ -76,7 +76,7 @@ export function analyzeDataLoss(migration) {
|
|
|
76
76
|
case "OTHER": {
|
|
77
77
|
// Detect TRUNCATE
|
|
78
78
|
if (upper.includes("TRUNCATE")) {
|
|
79
|
-
const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(\w+)/i);
|
|
79
|
+
const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(?:\w+\.)?(\w+)/i);
|
|
80
80
|
issues.push({
|
|
81
81
|
risk: "CERTAIN",
|
|
82
82
|
statement: truncate(stmt.raw),
|
|
@@ -87,7 +87,7 @@ export function analyzeDataLoss(migration) {
|
|
|
87
87
|
}
|
|
88
88
|
// Detect DELETE without WHERE
|
|
89
89
|
if (upper.match(/DELETE\s+FROM/) && !upper.includes("WHERE")) {
|
|
90
|
-
const tableMatch = stmt.raw.match(/DELETE\s+FROM\s+(?:`|"|)?(\w+)/i);
|
|
90
|
+
const tableMatch = stmt.raw.match(/DELETE\s+FROM\s+(?:`|"|)?(?:\w+\.)?(\w+)/i);
|
|
91
91
|
issues.push({
|
|
92
92
|
risk: "CERTAIN",
|
|
93
93
|
statement: truncate(stmt.raw),
|
|
@@ -98,7 +98,7 @@ export function analyzeDataLoss(migration) {
|
|
|
98
98
|
}
|
|
99
99
|
// Detect UPDATE without WHERE
|
|
100
100
|
if (upper.match(/^UPDATE\b/) && !upper.includes("WHERE")) {
|
|
101
|
-
const tableMatch = stmt.raw.match(/UPDATE\s+(?:`|"|)?(\w+)/i);
|
|
101
|
+
const tableMatch = stmt.raw.match(/UPDATE\s+(?:`|"|)?(?:\w+\.)?(\w+)/i);
|
|
102
102
|
issues.push({
|
|
103
103
|
risk: "LIKELY",
|
|
104
104
|
statement: truncate(stmt.raw),
|
|
@@ -149,7 +149,7 @@ function analyzeStatement(stmt) {
|
|
|
149
149
|
}
|
|
150
150
|
// TRUNCATE acquires ACCESS EXCLUSIVE lock — same severity as DROP TABLE
|
|
151
151
|
if (stmt.type === "OTHER" && /\bTRUNCATE\b/i.test(stmt.raw)) {
|
|
152
|
-
const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(\w+)/i);
|
|
152
|
+
const tableMatch = stmt.raw.match(/TRUNCATE\s+(?:TABLE\s+)?(?:`|"|)?(?:\w+\.)?(\w+)/i);
|
|
153
153
|
risks.push({
|
|
154
154
|
severity: "HIGH",
|
|
155
155
|
statement: truncate(stmt.raw),
|
|
@@ -132,6 +132,22 @@ function generateRollbackStatement(stmt) {
|
|
|
132
132
|
warning: `Type change on ${stmt.tableName}.${stmt.columnName} requires knowing the original type. Check schema before migration.`,
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
+
if (stmt.details.setDefault === "true") {
|
|
136
|
+
return {
|
|
137
|
+
forward: stmt.raw,
|
|
138
|
+
rollback: `ALTER TABLE ${stmt.tableName} ALTER COLUMN ${stmt.columnName} DROP DEFAULT`,
|
|
139
|
+
isReversible: true,
|
|
140
|
+
warning: null,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (stmt.details.dropDefault === "true") {
|
|
144
|
+
return {
|
|
145
|
+
forward: stmt.raw,
|
|
146
|
+
rollback: `-- Cannot reverse DROP DEFAULT on ${stmt.tableName}.${stmt.columnName} — original default value unknown`,
|
|
147
|
+
isReversible: false,
|
|
148
|
+
warning: `DROP DEFAULT on ${stmt.tableName}.${stmt.columnName} requires knowing the original default value to reverse.`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
135
151
|
return {
|
|
136
152
|
forward: stmt.raw,
|
|
137
153
|
rollback: `-- Cannot reverse: ${stmt.raw.slice(0, 80)}`,
|
package/build/index.js
CHANGED
|
@@ -33,7 +33,7 @@ function formatParserWarnings(migration) {
|
|
|
33
33
|
}
|
|
34
34
|
// Handle --help
|
|
35
35
|
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
36
|
-
console.log(`mcp-migration-advisor v0.2.
|
|
36
|
+
console.log(`mcp-migration-advisor v0.2.6 — MCP server for database migration risk analysis
|
|
37
37
|
|
|
38
38
|
Usage:
|
|
39
39
|
mcp-migration-advisor [options]
|
|
@@ -52,7 +52,7 @@ Tools provided:
|
|
|
52
52
|
}
|
|
53
53
|
const server = new McpServer({
|
|
54
54
|
name: "mcp-migration-advisor",
|
|
55
|
-
version: "0.2.
|
|
55
|
+
version: "0.2.6",
|
|
56
56
|
});
|
|
57
57
|
// Tool 1: analyze_migration
|
|
58
58
|
server.tool("analyze_migration", "Analyze a SQL migration file for lock risks, data loss potential, and unsafe patterns. Supports Flyway (V__*.sql) and plain SQL.", {
|
|
@@ -190,7 +190,7 @@ server.tool("analyze_liquibase_yaml", "Analyze a Liquibase YAML changelog for lo
|
|
|
190
190
|
return { content: [{ type: "text", text: output }] };
|
|
191
191
|
});
|
|
192
192
|
// Tool 4: score_risk
|
|
193
|
-
server.tool("score_risk", "Calculate the
|
|
193
|
+
server.tool("score_risk", "Calculate the combined risk score (0-100) for a SQL migration. Aggregates both lock risk severity (ACCESS EXCLUSIVE, SHARE locks) and data loss potential (DROP, TRUNCATE, type changes) into a single score. Useful for CI gates and automated migration review pipelines.", {
|
|
194
194
|
filename: z.string().describe("Migration filename"),
|
|
195
195
|
sql: z.string().describe("The SQL content of the migration file"),
|
|
196
196
|
}, async ({ filename, sql }) => {
|
|
@@ -200,6 +200,8 @@ server.tool("score_risk", "Calculate the overall risk score (0-100) for a SQL mi
|
|
|
200
200
|
const riskScore = calculateRiskScore(lockRisks);
|
|
201
201
|
const criticalCount = lockRisks.filter(r => r.severity === "CRITICAL").length;
|
|
202
202
|
const highCount = lockRisks.filter(r => r.severity === "HIGH").length;
|
|
203
|
+
const mediumCount = lockRisks.filter(r => r.severity === "MEDIUM").length;
|
|
204
|
+
const lowCount = lockRisks.filter(r => r.severity === "LOW").length;
|
|
203
205
|
const dataLossCertain = dataLossIssues.filter(i => i.risk === "CERTAIN").length;
|
|
204
206
|
const dataLossLikely = dataLossIssues.filter(i => i.risk === "LIKELY").length;
|
|
205
207
|
const dataLossPossible = dataLossIssues.filter(i => i.risk === "POSSIBLE").length;
|
|
@@ -226,6 +228,8 @@ server.tool("score_risk", "Calculate the overall risk score (0-100) for a SQL mi
|
|
|
226
228
|
|----------|-------|--------------------|
|
|
227
229
|
| CRITICAL lock risks | ${criticalCount} | ${criticalCount * 30} |
|
|
228
230
|
| HIGH lock risks | ${highCount} | ${highCount * 20} |
|
|
231
|
+
| MEDIUM lock risks | ${mediumCount} | ${mediumCount * 10} |
|
|
232
|
+
| LOW lock risks | ${lowCount} | ${lowCount * 5} |
|
|
229
233
|
| Certain data loss | ${dataLossCertain} | ${dataLossCertain * 25} |
|
|
230
234
|
| Likely data loss | ${dataLossLikely} | ${dataLossLikely * 15} |
|
|
231
235
|
| Possible data loss | ${dataLossPossible} | ${dataLossPossible * 5} |
|
|
@@ -235,7 +239,7 @@ server.tool("score_risk", "Calculate the overall risk score (0-100) for a SQL mi
|
|
|
235
239
|
content: [{ type: "text", text: output }],
|
|
236
240
|
};
|
|
237
241
|
});
|
|
238
|
-
// Tool
|
|
242
|
+
// Tool 5: generate_rollback
|
|
239
243
|
server.tool("generate_rollback", "Generate reverse DDL to undo a SQL migration. Produces rollback SQL with warnings for irreversible operations (DROP TABLE, DROP COLUMN, type changes). Includes Flyway schema_history cleanup.", {
|
|
240
244
|
filename: z.string().describe("Migration filename (e.g., V2__add_user_email.sql)"),
|
|
241
245
|
sql: z.string().describe("The SQL content of the migration file"),
|
|
@@ -33,6 +33,8 @@ export function parseFlywayFilename(filename) {
|
|
|
33
33
|
* Split SQL text into individual statements.
|
|
34
34
|
* Handles semicolons, ignoring those inside string literals and comments.
|
|
35
35
|
* Single-quoted strings are tracked; escaped quotes ('') are handled correctly.
|
|
36
|
+
* PostgreSQL dollar-quoted strings ($$ or $tag$) are also tracked so that
|
|
37
|
+
* semicolons inside function/trigger bodies are not treated as statement separators.
|
|
36
38
|
*/
|
|
37
39
|
function splitStatements(sql) {
|
|
38
40
|
// Remove block comments
|
|
@@ -42,9 +44,40 @@ function splitStatements(sql) {
|
|
|
42
44
|
const stmts = [];
|
|
43
45
|
let current = "";
|
|
44
46
|
let inString = false;
|
|
47
|
+
let dollarTag = null; // non-null while inside a $tag$...$tag$ block
|
|
45
48
|
let i = 0;
|
|
46
49
|
while (i < cleaned.length) {
|
|
47
50
|
const char = cleaned[i];
|
|
51
|
+
// Dollar-quote handling (PostgreSQL $tag$...$tag$ or $$...$$).
|
|
52
|
+
// Must be checked before the regular single-quote path.
|
|
53
|
+
if (char === "$" && !inString) {
|
|
54
|
+
const rest = cleaned.substring(i);
|
|
55
|
+
if (dollarTag === null) {
|
|
56
|
+
// Try to open a dollar-quoted block
|
|
57
|
+
const openMatch = rest.match(/^\$(\w*)\$/);
|
|
58
|
+
if (openMatch) {
|
|
59
|
+
dollarTag = openMatch[0]; // e.g. "$$" or "$body$"
|
|
60
|
+
current += dollarTag;
|
|
61
|
+
i += dollarTag.length;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Try to close the current dollar-quoted block
|
|
67
|
+
if (rest.startsWith(dollarTag)) {
|
|
68
|
+
current += dollarTag;
|
|
69
|
+
i += dollarTag.length;
|
|
70
|
+
dollarTag = null;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// While inside a dollar-quoted block, pass everything through verbatim
|
|
76
|
+
if (dollarTag !== null) {
|
|
77
|
+
current += char;
|
|
78
|
+
i++;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
48
81
|
if (char === "'" && !inString) {
|
|
49
82
|
inString = true;
|
|
50
83
|
current += char;
|
|
@@ -81,11 +114,13 @@ function splitStatements(sql) {
|
|
|
81
114
|
}
|
|
82
115
|
return stmts;
|
|
83
116
|
}
|
|
84
|
-
// Pattern matchers for DDL statement types
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const
|
|
117
|
+
// Pattern matchers for DDL statement types.
|
|
118
|
+
// Table name patterns use (?:\w+\.)? to optionally consume a schema prefix (e.g. public.users),
|
|
119
|
+
// so that only the unqualified table name is captured in group 1.
|
|
120
|
+
const CREATE_TABLE_RE = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
|
|
121
|
+
const ALTER_TABLE_RE = /ALTER\s+TABLE\s+(?:ONLY\s+)?(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
|
|
122
|
+
const DROP_TABLE_RE = /DROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
|
|
123
|
+
const CREATE_INDEX_RE = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+NOT\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|\s).*?\bON\s+(?:`|"|)?(?:\w+\.)?(\w+)(?:`|"|)?/i;
|
|
89
124
|
const DROP_INDEX_RE = /DROP\s+INDEX\s+(?:CONCURRENTLY\s+)?(?:IF\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
|
|
90
125
|
const ADD_COLUMN_RE = /ADD\s+(?:COLUMN\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
|
|
91
126
|
const DROP_COLUMN_RE = /DROP\s+(?:COLUMN\s+)?(?:IF\s+EXISTS\s+)?(?:`|"|)?(\w+)(?:`|"|)?/i;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-migration-advisor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "MCP server for database migration risk analysis — Flyway and Liquibase XML/YAML/SQL support with lock detection and conflict analysis",
|
|
5
5
|
"mcpName": "io.github.dmitriusan/mcp-migration-advisor",
|
|
6
6
|
"main": "build/index.js",
|