-
Notifications
You must be signed in to change notification settings - Fork 18
refactor: enforce unique environment and deployment names in a workspace #1058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,16 +176,26 @@ const postDeployment: AsyncTypedHandler< | |
|
|
||
| const id = uuidv4(); | ||
|
|
||
| await db.insert(schema.deployment).values({ | ||
| id, | ||
| name: body.name, | ||
| description: body.description ?? "", | ||
| resourceSelector: body.resourceSelector ?? "false", | ||
| jobAgentSelector: body.jobAgentSelector ?? "false", | ||
| jobAgentConfig: body.jobAgentConfig ?? {}, | ||
| metadata: body.metadata ?? {}, | ||
| workspaceId, | ||
| }); | ||
| try { | ||
| await db.insert(schema.deployment).values({ | ||
| id, | ||
| name: body.name, | ||
| description: body.description ?? "", | ||
| resourceSelector: body.resourceSelector ?? "false", | ||
| jobAgentSelector: body.jobAgentSelector ?? "false", | ||
| jobAgentConfig: body.jobAgentConfig ?? {}, | ||
| metadata: body.metadata ?? {}, | ||
| workspaceId, | ||
| }); | ||
| } catch (error: any) { | ||
| if (error.code === "23505") | ||
| throw new ApiError( | ||
| "Deployment name already exists in this workspace", | ||
| 409, | ||
| "DUPLICATE_NAME", | ||
| ); | ||
| throw error; | ||
| } | ||
|
|
||
| enqueueReleaseTargetsForDeployment(db, workspaceId, id); | ||
|
|
||
|
|
@@ -204,30 +214,40 @@ const upsertDeployment: AsyncTypedHandler< | |
|
|
||
| const jobAgentConfig = body.jobAgentConfig ?? {}; | ||
|
|
||
| await db | ||
| .insert(schema.deployment) | ||
| .values({ | ||
| id: deploymentId, | ||
| name: body.name, | ||
| description: body.description ?? "", | ||
| resourceSelector: body.resourceSelector ?? "false", | ||
| jobAgentSelector: body.jobAgentSelector ?? "false", | ||
| jobAgentConfig, | ||
| metadata: body.metadata ?? {}, | ||
| workspaceId, | ||
| }) | ||
| .onConflictDoUpdate({ | ||
| target: schema.deployment.id, | ||
| set: { | ||
| try { | ||
| await db | ||
| .insert(schema.deployment) | ||
| .values({ | ||
| id: deploymentId, | ||
| name: body.name, | ||
| description: body.description ?? "", | ||
| resourceSelector: body.resourceSelector ?? "false", | ||
| jobAgentSelector: body.jobAgentSelector ?? "false", | ||
| jobAgentConfig, | ||
| metadata: body.metadata ?? {}, | ||
| ...(body.jobAgentSelector != null | ||
| ? { jobAgentSelector: body.jobAgentSelector, jobAgentConfig } | ||
| : {}), | ||
| }, | ||
| }); | ||
| workspaceId, | ||
| }) | ||
| .onConflictDoUpdate({ | ||
| target: schema.deployment.id, | ||
| set: { | ||
| name: body.name, | ||
| description: body.description ?? "", | ||
| resourceSelector: body.resourceSelector ?? "false", | ||
| metadata: body.metadata ?? {}, | ||
| ...(body.jobAgentSelector != null | ||
| ? { jobAgentSelector: body.jobAgentSelector, jobAgentConfig } | ||
| : {}), | ||
| }, | ||
|
Comment on lines
+230
to
+240
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PUT can no longer clear or independently update job-agent settings. The update branch only writes Suggested fix .onConflictDoUpdate({
target: schema.deployment.id,
set: {
name: body.name,
description: body.description ?? "",
resourceSelector: body.resourceSelector ?? "false",
+ jobAgentSelector: body.jobAgentSelector ?? "false",
+ jobAgentConfig,
metadata: body.metadata ?? {},
- ...(body.jobAgentSelector != null
- ? { jobAgentSelector: body.jobAgentSelector, jobAgentConfig }
- : {}),
},
});🤖 Prompt for AI Agents |
||
| }); | ||
| } catch (error: any) { | ||
| if (error.code === "23505") | ||
| throw new ApiError( | ||
| "Deployment name already exists in this workspace", | ||
| 409, | ||
| "DUPLICATE_NAME", | ||
| ); | ||
|
Comment on lines
+243
to
+248
|
||
| throw error; | ||
| } | ||
|
|
||
| enqueueReleaseTargetsForDeployment(db, workspaceId, deploymentId); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.