1- import { db } from '@sim/db'
1+ import { dbReplica } from '@sim/db'
22import {
33 knowledgeBase ,
44 knowledgeConnector ,
@@ -302,7 +302,7 @@ export async function generateWorkspaceContext(
302302 ] = await Promise . all ( [
303303 getUsersWithPermissions ( workspaceId ) ,
304304
305- db
305+ dbReplica
306306 . select ( {
307307 id : workflow . id ,
308308 name : workflow . name ,
@@ -314,7 +314,7 @@ export async function generateWorkspaceContext(
314314 . from ( workflow )
315315 . where ( and ( eq ( workflow . workspaceId , workspaceId ) , isNull ( workflow . archivedAt ) ) ) ,
316316
317- db
317+ dbReplica
318318 . select ( {
319319 id : workflowFolder . id ,
320320 name : workflowFolder . name ,
@@ -323,7 +323,7 @@ export async function generateWorkspaceContext(
323323 . from ( workflowFolder )
324324 . where ( and ( eq ( workflowFolder . workspaceId , workspaceId ) , isNull ( workflowFolder . archivedAt ) ) ) ,
325325
326- db
326+ dbReplica
327327 . select ( {
328328 id : knowledgeBase . id ,
329329 name : knowledgeBase . name ,
@@ -332,7 +332,7 @@ export async function generateWorkspaceContext(
332332 . from ( knowledgeBase )
333333 . where ( and ( eq ( knowledgeBase . workspaceId , workspaceId ) , isNull ( knowledgeBase . deletedAt ) ) ) ,
334334
335- db
335+ dbReplica
336336 . select ( {
337337 id : userTableDefinitions . id ,
338338 name : userTableDefinitions . name ,
@@ -352,7 +352,7 @@ export async function generateWorkspaceContext(
352352
353353 listCustomTools ( { userId, workspaceId } ) ,
354354
355- db
355+ dbReplica
356356 . select ( {
357357 id : mcpServers . id ,
358358 name : mcpServers . name ,
@@ -364,7 +364,7 @@ export async function generateWorkspaceContext(
364364
365365 listSkills ( { workspaceId, includeBuiltins : false } ) ,
366366
367- db
367+ dbReplica
368368 . select ( {
369369 id : workflowSchedule . id ,
370370 jobTitle : workflowSchedule . jobTitle ,
@@ -388,7 +388,7 @@ export async function generateWorkspaceContext(
388388 tables . length > 0
389389 ? await Promise . all (
390390 tables . map ( async ( t ) => {
391- const [ row ] = await db
391+ const [ row ] = await dbReplica
392392 . select ( { count : count ( ) } )
393393 . from ( userTableRows )
394394 . where ( eq ( userTableRows . tableId , t . id ) )
@@ -400,7 +400,7 @@ export async function generateWorkspaceContext(
400400 const kbIds = kbs . map ( ( kb ) => kb . id )
401401 const connectorRows =
402402 kbIds . length > 0
403- ? await db
403+ ? await dbReplica
404404 . select ( {
405405 knowledgeBaseId : knowledgeConnector . knowledgeBaseId ,
406406 connectorType : knowledgeConnector . connectorType ,
0 commit comments