Skip to content

Commit 92edf2f

Browse files
committed
more friendly error for duplicate skills in the same workspace
1 parent dfddb60 commit 92edf2f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

apps/sim/lib/workflows/skills/operations.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { db } from '@sim/db'
22
import { skill } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
4-
import { and, desc, eq } from 'drizzle-orm'
4+
import { and, desc, eq, ne } from 'drizzle-orm'
55
import { nanoid } from 'nanoid'
66
import { generateRequestId } from '@/lib/core/utils/request'
77

@@ -36,6 +36,20 @@ export async function upsertSkills(params: {
3636
.limit(1)
3737

3838
if (existingSkill.length > 0) {
39+
if (s.name !== existingSkill[0].name) {
40+
const nameConflict = await tx
41+
.select({ id: skill.id })
42+
.from(skill)
43+
.where(
44+
and(eq(skill.workspaceId, workspaceId), eq(skill.name, s.name), ne(skill.id, s.id))
45+
)
46+
.limit(1)
47+
48+
if (nameConflict.length > 0) {
49+
throw new Error(`A skill with the name "${s.name}" already exists in this workspace`)
50+
}
51+
}
52+
3953
await tx
4054
.update(skill)
4155
.set({

0 commit comments

Comments
 (0)