11import crypto from 'crypto'
22import {
33 db ,
4- webhook ,
54 workflow ,
65 workflowBlocks ,
76 workflowDeploymentVersion ,
@@ -22,7 +21,6 @@ import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/w
2221const logger = createLogger ( 'WorkflowDBHelpers' )
2322
2423export type WorkflowDeploymentVersion = InferSelectModel < typeof workflowDeploymentVersion >
25- type WebhookRecord = InferSelectModel < typeof webhook >
2624type SubflowInsert = InferInsertModel < typeof workflowSubflows >
2725
2826export interface WorkflowDeploymentVersionResponse {
@@ -337,18 +335,6 @@ export async function saveWorkflowToNormalizedTables(
337335
338336 // Start a transaction
339337 await db . transaction ( async ( tx ) => {
340- // Snapshot existing webhooks before deletion to preserve them through the cycle
341- let existingWebhooks : WebhookRecord [ ] = [ ]
342- try {
343- existingWebhooks = await tx . select ( ) . from ( webhook ) . where ( eq ( webhook . workflowId , workflowId ) )
344- } catch ( webhookError ) {
345- // Webhook table might not be available in test environments
346- logger . debug ( 'Could not load webhooks before save, skipping preservation' , {
347- error : webhookError instanceof Error ? webhookError . message : String ( webhookError ) ,
348- } )
349- }
350-
351- // Clear existing data for this workflow
352338 await Promise . all ( [
353339 tx . delete ( workflowBlocks ) . where ( eq ( workflowBlocks . workflowId , workflowId ) ) ,
354340 tx . delete ( workflowEdges ) . where ( eq ( workflowEdges . workflowId , workflowId ) ) ,
@@ -419,42 +405,6 @@ export async function saveWorkflowToNormalizedTables(
419405 if ( subflowInserts . length > 0 ) {
420406 await tx . insert ( workflowSubflows ) . values ( subflowInserts )
421407 }
422-
423- // Re-insert preserved webhooks if any exist and their blocks still exist
424- if ( existingWebhooks . length > 0 ) {
425- try {
426- const webhookInserts = existingWebhooks
427- . filter ( ( wh ) => ! ! state . blocks ?. [ wh . blockId ?? '' ] )
428- . map ( ( wh ) => ( {
429- id : wh . id ,
430- workflowId : wh . workflowId ,
431- blockId : wh . blockId ,
432- path : wh . path ,
433- provider : wh . provider ,
434- providerConfig : wh . providerConfig ,
435- credentialSetId : wh . credentialSetId ,
436- isActive : wh . isActive ,
437- createdAt : wh . createdAt ,
438- updatedAt : new Date ( ) ,
439- } ) )
440-
441- if ( webhookInserts . length > 0 ) {
442- await tx . insert ( webhook ) . values ( webhookInserts )
443- logger . debug ( `Preserved ${ webhookInserts . length } webhook(s) through workflow save` , {
444- workflowId,
445- } )
446- }
447- } catch ( webhookInsertError ) {
448- // Webhook preservation is optional - don't fail the entire save if it errors
449- logger . warn ( 'Could not preserve webhooks during save' , {
450- error :
451- webhookInsertError instanceof Error
452- ? webhookInsertError . message
453- : String ( webhookInsertError ) ,
454- workflowId,
455- } )
456- }
457- }
458408 } )
459409
460410 return { success : true }
0 commit comments