(
data: { tableId: string; groupId: string; columnName: string },
requestId: string
)
| 837 | * `deleteWorkflowGroup` if needed. |
| 838 | */ |
| 839 | export async function deleteWorkflowGroupOutput( |
| 840 | data: { tableId: string; groupId: string; columnName: string }, |
| 841 | requestId: string |
| 842 | ): Promise<TableDefinition> { |
| 843 | return withLockedTable(data.tableId, async (table, trx) => { |
| 844 | const schema = table.schema |
| 845 | const groups = schema.workflowGroups ?? [] |
| 846 | const groupIndex = groups.findIndex((g) => g.id === data.groupId) |
| 847 | if (groupIndex === -1) { |
| 848 | throw new Error(`Workflow group "${data.groupId}" not found`) |
| 849 | } |
| 850 | const group = groups[groupIndex] |
| 851 | // `data.columnName` may be a column id (first-party) or display name |
| 852 | // (mothership/legacy); resolve to the stable id used everywhere below. |
| 853 | const targetColumn = schema.columns.find((c) => columnMatchesRef(c, data.columnName)) |
| 854 | const columnId = targetColumn ? getColumnId(targetColumn) : data.columnName |
| 855 | if (!group.outputs.some((o) => o.columnName === columnId)) { |
| 856 | throw new Error( |
| 857 | `Workflow group "${data.groupId}" has no output bound to column "${data.columnName}"` |
| 858 | ) |
| 859 | } |
| 860 | |
| 861 | const updatedGroup: WorkflowGroup = { |
| 862 | ...group, |
| 863 | outputs: group.outputs.filter((o) => o.columnName !== columnId), |
| 864 | } |
| 865 | const nextGroups = groups.map((g, i) => (i === groupIndex ? updatedGroup : g)) |
| 866 | const nextColumns = schema.columns.filter((c) => getColumnId(c) !== columnId) |
| 867 | const updatedSchema: TableSchema = { |
| 868 | ...schema, |
| 869 | columns: nextColumns, |
| 870 | workflowGroups: nextGroups, |
| 871 | } |
| 872 | |
| 873 | const updatedColumnOrder = table.metadata?.columnOrder?.filter((id) => id !== columnId) |
| 874 | assertValidSchema(updatedSchema, updatedColumnOrder) |
| 875 | |
| 876 | const updatedMetadata: TableMetadata | null = |
| 877 | updatedColumnOrder && table.metadata |
| 878 | ? { ...table.metadata, columnOrder: updatedColumnOrder } |
| 879 | : table.metadata |
| 880 | ? { ...table.metadata } |
| 881 | : null |
| 882 | |
| 883 | const now = new Date() |
| 884 | await setTableTxTimeouts(trx, { statementMs: 60_000 }) |
| 885 | await trx |
| 886 | .update(userTableDefinitions) |
| 887 | .set({ schema: updatedSchema, metadata: updatedMetadata, updatedAt: now }) |
| 888 | .where(eq(userTableDefinitions.id, data.tableId)) |
| 889 | await trx.execute( |
| 890 | sql`UPDATE user_table_rows SET data = data - ${columnId}::text WHERE table_id = ${data.tableId} AND data ? ${columnId}::text` |
| 891 | ) |
| 892 | |
| 893 | logger.info( |
| 894 | `[${requestId}] Removed output "${data.columnName}" from workflow group "${data.groupId}" in table ${data.tableId}` |
| 895 | ) |
| 896 |
no test coverage detected