mcp-migration-advisor 0.2.5 → 0.2.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/README.md +13 -0
- package/build/analyzers/data-loss.js +3 -3
- package/build/analyzers/lock-risk.js +1 -1
- package/build/index.js +2 -2
- 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),
|
package/build/index.js
CHANGED
|
@@ -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 }) => {
|
|
@@ -235,7 +235,7 @@ server.tool("score_risk", "Calculate the overall risk score (0-100) for a SQL mi
|
|
|
235
235
|
content: [{ type: "text", text: output }],
|
|
236
236
|
};
|
|
237
237
|
});
|
|
238
|
-
// Tool
|
|
238
|
+
// Tool 5: generate_rollback
|
|
239
239
|
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
240
|
filename: z.string().describe("Migration filename (e.g., V2__add_user_email.sql)"),
|
|
241
241
|
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.6",
|
|
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",
|