Skip to content

Commit 4baad33

Browse files
committed
fix(db): address review feedback (joinedAt backfill, mcp delete error, chatDeploy projection, sql newline)
1 parent e3f1907 commit 4baad33

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

apps/sim/lib/copilot/tools/handlers/deployment/manage.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ export async function executeCheckDeploymentStatus(
4343
.where(eq(workflow.id, workflowId))
4444
.limit(1),
4545
db
46-
.select()
46+
.select({
47+
id: chat.id,
48+
identifier: chat.identifier,
49+
title: chat.title,
50+
description: chat.description,
51+
authType: chat.authType,
52+
allowedEmails: chat.allowedEmails,
53+
outputConfigs: chat.outputConfigs,
54+
password: chat.password,
55+
customizations: chat.customizations,
56+
})
4757
.from(chat)
4858
.where(and(eq(chat.workflowId, workflowId), isNull(chat.archivedAt)))
4959
.limit(1),

apps/sim/lib/credentials/environment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function ensureWorkspaceCredentialMemberships(
9595
updatedAt: now,
9696
}))
9797

98-
// `joinedAt` is omitted from SET so the original value is preserved on conflict.
98+
// `joinedAt` uses COALESCE so a non-null existing value is preserved but null is backfilled.
9999
await db
100100
.insert(credentialMember)
101101
.values(values)
@@ -104,6 +104,7 @@ async function ensureWorkspaceCredentialMemberships(
104104
set: {
105105
role: sql`excluded.role`,
106106
status: 'active',
107+
joinedAt: sql`COALESCE(${credentialMember.joinedAt}, excluded.joined_at)`,
107108
invitedBy: ownerUserId,
108109
updatedAt: now,
109110
},

apps/sim/lib/mcp/orchestration/workflow-mcp-lifecycle.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit'
22
import { db, workflow, workflowMcpServer, workflowMcpTool } from '@sim/db'
33
import { createLogger } from '@sim/logger'
44
import { generateId } from '@sim/utils/id'
5-
import { and, eq, inArray, isNull, sql } from 'drizzle-orm'
5+
import { and, eq, inArray, isNull } from 'drizzle-orm'
66
import { mcpPubSub } from '@/lib/mcp/pubsub'
77
import { generateParameterSchemaForWorkflow } from '@/lib/mcp/workflow-mcp-sync'
88
import { sanitizeToolName } from '@/lib/mcp/workflow-tool-schema'
@@ -515,15 +515,25 @@ export async function performDeleteWorkflowMcpTool(
515515
params: PerformDeleteWorkflowMcpToolParams
516516
): Promise<PerformDeleteWorkflowMcpToolResult> {
517517
try {
518-
const [tool] = await db
519-
.delete(workflowMcpTool)
518+
const [server] = await db
519+
.select({ id: workflowMcpServer.id })
520+
.from(workflowMcpServer)
520521
.where(
521522
and(
522-
eq(workflowMcpTool.id, params.toolId),
523-
eq(workflowMcpTool.serverId, params.serverId),
524-
sql`EXISTS (SELECT 1 FROM ${workflowMcpServer} WHERE ${workflowMcpServer.id} = ${params.serverId} AND ${workflowMcpServer.workspaceId} = ${params.workspaceId} AND ${workflowMcpServer.deletedAt} IS NULL)`
523+
eq(workflowMcpServer.id, params.serverId),
524+
eq(workflowMcpServer.workspaceId, params.workspaceId),
525+
isNull(workflowMcpServer.deletedAt)
525526
)
526527
)
528+
.limit(1)
529+
530+
if (!server) return { success: false, error: 'Server not found', errorCode: 'not_found' }
531+
532+
const [tool] = await db
533+
.delete(workflowMcpTool)
534+
.where(
535+
and(eq(workflowMcpTool.id, params.toolId), eq(workflowMcpTool.serverId, params.serverId))
536+
)
527537
.returning()
528538

529539
if (!tool) return { success: false, error: 'Tool not found', errorCode: 'not_found' }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CREATE INDEX "idx_chat_on_workflow_id_archived_at" ON "chat" USING btree ("workflow_id","archived_at");--> statement-breakpoint
22
CREATE INDEX "idx_webhook_on_provider_is_active_workflow_id_deploym_bdeed5468" ON "webhook" USING btree ("provider","is_active","workflow_id","deployment_version_id");--> statement-breakpoint
33
CREATE INDEX "idx_webhook_on_workflow_id_block_id_updated_at_desc" ON "webhook" USING btree ("workflow_id","block_id","updated_at" DESC NULLS LAST);--> statement-breakpoint
4-
CREATE INDEX "idx_workflow_schedule_on_source_workspace_id_source_t_c07f3bba6" ON "workflow_schedule" USING btree ("source_workspace_id","source_type","archived_at","status");
4+
CREATE INDEX "idx_workflow_schedule_on_source_workspace_id_source_t_c07f3bba6" ON "workflow_schedule" USING btree ("source_workspace_id","source_type","archived_at","status");

0 commit comments

Comments
 (0)