Skip to content

Commit 793b8da

Browse files
fix(scripts): skip deleted table workflows
1 parent 319c3dc commit 793b8da

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

‎apps/sim/scripts/backfill-table-workflow-deployments.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @vitest-environment node
33
*/
4+
import { dbChainMockFns, resetDbChainMock } from '@sim/testing'
45
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
56

67
const { mockLoadRuntimeSecrets, mockPerformFullDeploy } = vi.hoisted(() => ({
@@ -20,6 +21,7 @@ import {
2021
backfillTableWorkflowDeployments,
2122
deployTableWorkflow,
2223
parseTableWorkflowDeploymentBackfillArgs,
24+
postgresTableWorkflowDeploymentStore,
2325
prepareTableWorkflowDeploymentBackfillEnvironment,
2426
TABLE_WORKFLOW_DEPLOYMENT_BATCH_SIZE,
2527
type TableWorkflowDeploymentCandidate,
@@ -32,6 +34,10 @@ const ORIGINAL_ENV = {
3234
SIM_ENV_SECRET_ID: process.env.SIM_ENV_SECRET_ID,
3335
}
3436

37+
interface MockSqlQuery {
38+
toSQL(): { sql: string }
39+
}
40+
3541
function restoreEnvironmentVariable(key: keyof typeof ORIGINAL_ENV): void {
3642
const value = ORIGINAL_ENV[key]
3743
if (value === undefined) {
@@ -63,6 +69,7 @@ function store(
6369
describe('backfillTableWorkflowDeployments', () => {
6470
beforeEach(() => {
6571
vi.clearAllMocks()
72+
resetDbChainMock()
6673
})
6774

6875
afterEach(() => {
@@ -112,6 +119,17 @@ describe('backfillTableWorkflowDeployments', () => {
112119
expect(mockLoadRuntimeSecrets).not.toHaveBeenCalled()
113120
})
114121

122+
it('silently excludes missing and archived workflow references from integrity checks', async () => {
123+
await postgresTableWorkflowDeploymentStore.assertIntegrity()
124+
125+
const referenceQuery = dbChainMockFns.execute.mock.calls[2]?.[0] as MockSqlQuery
126+
const queryText = referenceQuery.toSQL().sql
127+
expect(queryText).toContain('INNER JOIN workflow')
128+
expect(queryText).toContain('workflow.archived_at IS NULL')
129+
expect(queryText).not.toContain('LEFT JOIN workflow')
130+
expect(queryText).not.toContain('workflow.id IS NULL')
131+
})
132+
115133
it('deploys bounded keyset pages and verifies the final desired state', async () => {
116134
const listCandidates = vi
117135
.fn<TableWorkflowDeploymentStore['listCandidates']>()

‎apps/sim/scripts/backfill-table-workflow-deployments.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ interface InvalidWorkflowReferenceRow extends Record<string, unknown> {
7373
table_id: string
7474
table_workspace_id: string
7575
workflow_id: string
76-
workflow_workspace_id: string | null
76+
workflow_workspace_id: string
7777
}
7878

7979
interface MultipleActiveVersionsRow extends Record<string, unknown> {
@@ -212,22 +212,16 @@ async function assertTableWorkflowIntegrity(): Promise<void> {
212212
table_workflow_groups.workflow_id,
213213
workflow.workspace_id AS workflow_workspace_id
214214
FROM table_workflow_groups
215-
LEFT JOIN workflow ON workflow.id = table_workflow_groups.workflow_id
215+
INNER JOIN workflow ON workflow.id = table_workflow_groups.workflow_id
216+
AND workflow.archived_at IS NULL
216217
WHERE table_workflow_groups.workflow_id <> ''
217-
AND (
218-
workflow.id IS NULL
219-
OR (
220-
workflow.archived_at IS NULL
221-
AND workflow.workspace_id IS DISTINCT FROM table_workflow_groups.table_workspace_id
222-
)
223-
)
218+
AND workflow.workspace_id IS DISTINCT FROM table_workflow_groups.table_workspace_id
224219
LIMIT 1
225220
`)
226221
if (invalidReference) {
227-
const workflowScope = invalidReference.workflow_workspace_id ?? 'missing'
228222
throw new Error(
229223
`Table ${invalidReference.table_id} in workspace ${invalidReference.table_workspace_id} ` +
230-
`references workflow ${invalidReference.workflow_id} in workspace ${workflowScope}`
224+
`references workflow ${invalidReference.workflow_id} in workspace ${invalidReference.workflow_workspace_id}`
231225
)
232226
}
233227

0 commit comments

Comments
 (0)