Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALTER TABLE "mcp_query_data" ADD COLUMN "sql_query" text;--> statement-breakpoint
ALTER TABLE "mcp_query_data" ADD COLUMN "database_id" text;--> statement-breakpoint
UPDATE "mcp_query_data"
SET
"sql_query" = "mcp_call_log"."tool_input"->>'sql_query',
"database_id" = "mcp_call_log"."tool_input"->>'database_id'
FROM "mcp_call_log"
WHERE "mcp_call_log"."id" = "mcp_query_data"."call_log_id"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When an expired MCP query is reattached before this migration runs, call_log_id may point to the attaching tool rather than the original execute_sql call, so this join skips the row and leaves its SQL definition null. Backfill by matching the original query ID from the execute_sql log output, or preserve the original execute_sql association during cache refresh.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/backend/migrations-postgres/0064_persist_mcp_query_definitions.sql, line 8:

<comment>When an expired MCP query is reattached before this migration runs, `call_log_id` may point to the attaching tool rather than the original `execute_sql` call, so this join skips the row and leaves its SQL definition null. Backfill by matching the original query ID from the execute_sql log output, or preserve the original execute_sql association during cache refresh.</comment>

<file context>
@@ -0,0 +1,9 @@
+	"sql_query" = "mcp_call_log"."tool_input"->>'sql_query',
+	"database_id" = "mcp_call_log"."tool_input"->>'database_id'
+FROM "mcp_call_log"
+WHERE "mcp_call_log"."id" = "mcp_query_data"."call_log_id"
+	AND "mcp_call_log"."tool_name" = 'execute_sql';
</file context>

AND "mcp_call_log"."tool_name" = 'execute_sql';
Loading
Loading