(dbCtx: DbOrTx)
| 946 | const { workflowId, tx } = params |
| 947 | |
| 948 | const executeUndeploy = async (dbCtx: DbOrTx) => { |
| 949 | if (!(await lockWorkflowForUpdate(dbCtx, workflowId))) { |
| 950 | throw new Error('Workflow not found') |
| 951 | } |
| 952 | |
| 953 | const deploymentVersions = await dbCtx |
| 954 | .select({ id: workflowDeploymentVersion.id }) |
| 955 | .from(workflowDeploymentVersion) |
| 956 | .where(eq(workflowDeploymentVersion.workflowId, workflowId)) |
| 957 | const deploymentVersionIds = deploymentVersions.map((version) => version.id) |
| 958 | |
| 959 | const { deleteSchedulesForWorkflow } = await import('@/lib/workflows/schedules/deploy') |
| 960 | await deleteSchedulesForWorkflow(workflowId, dbCtx) |
| 961 | |
| 962 | await dbCtx |
| 963 | .update(workflowDeploymentVersion) |
| 964 | .set({ isActive: false }) |
| 965 | .where(eq(workflowDeploymentVersion.workflowId, workflowId)) |
| 966 | |
| 967 | await dbCtx |
| 968 | .update(workflow) |
| 969 | .set({ isDeployed: false, deployedAt: null }) |
| 970 | .where(eq(workflow.id, workflowId)) |
| 971 | |
| 972 | await params.onUndeployTransaction?.(dbCtx, { deploymentVersionIds }) |
| 973 | } |
| 974 | |
| 975 | try { |
| 976 | if (tx) { |
no test coverage detected