mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 15:07:55 -05:00
fix(custom-tools): add composite index on custom tool names & workspace id (#2131)
This commit is contained in:
10
packages/db/migrations/0113_calm_tiger_shark.sql
Normal file
10
packages/db/migrations/0113_calm_tiger_shark.sql
Normal 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");
|
||||
7688
packages/db/migrations/meta/0113_snapshot.json
Normal file
7688
packages/db/migrations/meta/0113_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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
|
||||
),
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user