@@ -571,7 +571,12 @@ export async function addTableColumnsWithTx(
571571 )
572572 }
573573
574- const updatedSchema : TableSchema = { columns : [ ...table . schema . columns , ...additions ] }
574+ // Spread `table.schema` first so workflow groups (and any future top-level
575+ // schema fields) survive a CSV import that only adds plain columns.
576+ const updatedSchema : TableSchema = {
577+ ...table . schema ,
578+ columns : [ ...table . schema . columns , ...additions ] ,
579+ }
575580 const now = new Date ( )
576581
577582 await trx
@@ -945,7 +950,9 @@ export async function batchInsertRows(
945950 table : TableDefinition ,
946951 requestId : string
947952) : Promise < TableRow [ ] > {
948- return db . transaction ( ( trx ) => batchInsertRowsWithTx ( trx , data , table , requestId ) )
953+ const result = await db . transaction ( ( trx ) => batchInsertRowsWithTx ( trx , data , table , requestId ) )
954+ dispatchAfterBatchInsert ( table , result , requestId )
955+ return result
949956}
950957
951958/**
@@ -1043,12 +1050,24 @@ export async function batchInsertRowsWithTx(
10431050 updatedAt : r . updatedAt ,
10441051 } ) )
10451052
1046- void fireTableTrigger ( data . tableId , table . name , 'insert' , result , null , table . schema , requestId )
1047- void scheduleRunsForRows ( table , result )
1048-
10491053 return result
10501054}
10511055
1056+ /**
1057+ * Side-effect dispatch for an insert batch. Caller fires this AFTER the
1058+ * surrounding transaction commits — `fireTableTrigger` and
1059+ * `scheduleRunsForRows` both read through the global db connection, so firing
1060+ * inside the tx can see no rows and no-op.
1061+ */
1062+ export function dispatchAfterBatchInsert (
1063+ table : TableDefinition ,
1064+ result : TableRow [ ] ,
1065+ requestId : string
1066+ ) : void {
1067+ void fireTableTrigger ( table . id , table . name , 'insert' , result , null , table . schema , requestId )
1068+ void scheduleRunsForRows ( table , result )
1069+ }
1070+
10521071/**
10531072 * Replaces all rows in a table with a new set of rows. Deletes existing rows
10541073 * and inserts the provided rows inside a single transaction so the table is
0 commit comments