| 72 | } |
| 73 | |
| 74 | async function applyTableChange( |
| 75 | tableName: `issue` | `comment`, |
| 76 | change: IssueChange | CommentChange, |
| 77 | sql: postgres.TransactionSql |
| 78 | ): Promise<void> { |
| 79 | const { |
| 80 | id, |
| 81 | modified_columns: modified_columns_raw, |
| 82 | new: isNew, |
| 83 | deleted, |
| 84 | } = change |
| 85 | const modified_columns = modified_columns_raw as (keyof typeof change)[] |
| 86 | |
| 87 | if (deleted) { |
| 88 | await sql` |
| 89 | DELETE FROM ${sql(tableName)} WHERE id = ${id} |
| 90 | ` |
| 91 | } else if (isNew) { |
| 92 | await sql` |
| 93 | INSERT INTO ${sql(tableName)} ${sql(change, `id`, ...modified_columns)} |
| 94 | ` |
| 95 | } else { |
| 96 | await sql` |
| 97 | UPDATE ${sql(tableName)} |
| 98 | SET ${sql(change, ...modified_columns)} |
| 99 | WHERE id = ${id} |
| 100 | ` |
| 101 | } |
| 102 | } |