({
driver,
tableName,
tableSchema,
data,
}: {
driver: BaseDriver;
tableName: string;
tableSchema: DatabaseTableSchema;
data: OptimizeTableState;
})
| 69 | } |
| 70 | |
| 71 | export async function commitChange({ |
| 72 | driver, |
| 73 | tableName, |
| 74 | tableSchema, |
| 75 | data, |
| 76 | }: { |
| 77 | driver: BaseDriver; |
| 78 | tableName: string; |
| 79 | tableSchema: DatabaseTableSchema; |
| 80 | data: OptimizeTableState; |
| 81 | }): Promise<{ errorMessage?: string }> { |
| 82 | const plans = generateTableChangePlan({ |
| 83 | tableSchema, |
| 84 | data, |
| 85 | }); |
| 86 | |
| 87 | try { |
| 88 | const result = await driver.updateTableData( |
| 89 | tableSchema.schemaName, |
| 90 | tableName, |
| 91 | plans.map((p) => p.plan), |
| 92 | tableSchema |
| 93 | ); |
| 94 | |
| 95 | data.applyChanges( |
| 96 | plans.map((p, idx) => { |
| 97 | return { |
| 98 | row: p.row, |
| 99 | updated: result[idx]?.record ?? {}, |
| 100 | }; |
| 101 | }) |
| 102 | ); |
| 103 | } catch (e) { |
| 104 | return { errorMessage: (e as Error).message }; |
| 105 | } |
| 106 | |
| 107 | return {}; |
| 108 | } |
no test coverage detected