fix(custom-tools): add composite index on custom tool names & workspace id (#2131)

This commit is contained in:
Waleed
2025-11-28 15:33:08 -08:00
committed by GitHub
parent a10e1a63af
commit 21a640af50
6 changed files with 7717 additions and 46 deletions

View File

@@ -0,0 +1,10 @@
-- Step 1: Convert non-UUID IDs to UUIDs (preserve existing UUIDs)
-- This allows same title in different workspaces by removing function-name-based IDs
UPDATE "custom_tools"
SET "id" = gen_random_uuid()::text
WHERE workspace_id IS NOT NULL -- Only update workspace-scoped tools
AND "id" !~ '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'; -- Skip if already UUID
-- Step 2: Add composite unique constraint on (workspace_id, title)
-- This enforces uniqueness per workspace, not globally
CREATE UNIQUE INDEX "custom_tools_workspace_title_unique" ON "custom_tools" USING btree ("workspace_id","title");

File diff suppressed because it is too large Load Diff

View File

@@ -785,6 +785,13 @@
"when": 1764095386986,
"tag": "0112_tired_blink",
"breakpoints": true
},
{
"idx": 113,
"version": "7",
"when": 1764370369484,
"tag": "0113_calm_tiger_shark",
"breakpoints": true
}
]
}

View File

@@ -656,6 +656,10 @@ export const customTools = pgTable(
},
(table) => ({
workspaceIdIdx: index('custom_tools_workspace_id_idx').on(table.workspaceId),
workspaceTitleUnique: uniqueIndex('custom_tools_workspace_title_unique').on(
table.workspaceId,
table.title
),
})
)