-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathaltimate-core-migration.ts
More file actions
43 lines (41 loc) · 1.74 KB
/
altimate-core-migration.ts
File metadata and controls
43 lines (41 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import z from "zod"
import { Tool } from "../../tool/tool"
import { Dispatcher } from "../native"
export const AltimateCoreMigrationTool = Tool.define("altimate_core_migration", {
description:
"Analyze DDL migration safety. Detects potential data loss, type narrowing, missing defaults, and other risks in schema migration statements.",
parameters: z.object({
old_ddl: z.string().describe("Original DDL (before migration)"),
new_ddl: z.string().describe("New DDL (after migration)"),
dialect: z.string().optional().describe("SQL dialect (e.g. snowflake, postgres)"),
}),
async execute(args, ctx) {
try {
const result = await Dispatcher.call("altimate_core.migration", {
old_ddl: args.old_ddl,
new_ddl: args.new_ddl,
dialect: args.dialect ?? "",
})
const data = result.data as Record<string, any>
const riskCount = data.risks?.length ?? 0
return {
title: `Migration: ${riskCount === 0 ? "SAFE" : `${riskCount} risk(s)`}`,
metadata: { success: result.success, risk_count: riskCount },
output: formatMigration(data),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return { title: "Migration: ERROR", metadata: { success: false, risk_count: 0 }, output: `Failed: ${msg}` }
}
},
})
function formatMigration(data: Record<string, any>): string {
if (data.error) return `Error: ${data.error}`
if (!data.risks?.length) return "Migration appears safe. No risks detected."
const lines = ["Migration risks:\n"]
for (const r of data.risks) {
lines.push(` [${r.severity ?? "warning"}] ${r.type}: ${r.message}`)
if (r.recommendation) lines.push(` Recommendation: ${r.recommendation}`)
}
return lines.join("\n")
}