|
4 | 4 | import type { Sql } from 'postgres' |
5 | 5 | import { describe, expect, it, vi } from 'vitest' |
6 | 6 | import { repairUnknownTableRowProvenance } from './0005_repair_unknown_table_row_provenance' |
| 7 | +import { repairUnknownTableRowProvenanceSecondPass } from './0006_repair_unknown_table_row_provenance_second_pass' |
7 | 8 |
|
8 | 9 | function normalizeSql(value: string): string { |
9 | 10 | return value.replace(/\s+/g, ' ').trim() |
@@ -105,3 +106,31 @@ describe('0005 repair unknown table row provenance', () => { |
105 | 106 | expect(cursors).toEqual(['', 'row-1']) |
106 | 107 | }) |
107 | 108 | }) |
| 109 | + |
| 110 | +/** |
| 111 | + * 0005 is finished — the runner records a name and never offers it again — but it cleared only the |
| 112 | + * backlog that existed when it ran, and the writers producing that backlog kept running. The second |
| 113 | + * pass exists to clear what accumulated since, and shares the first's implementation because the |
| 114 | + * lock ordering and the status re-check are subtleties worth having once. |
| 115 | + */ |
| 116 | +describe('0006 second pass', () => { |
| 117 | + it('repairs on the same walk as the first pass rather than restating it', async () => { |
| 118 | + const { sql, statements, cursors } = createSqlHarness([['row-1'], []]) |
| 119 | + |
| 120 | + await repairUnknownTableRowProvenanceSecondPass.up(sql) |
| 121 | + |
| 122 | + expect(cursors).toEqual(['', 'row-1']) |
| 123 | + const lockIndex = statements.findIndex((statement) => statement.includes('FOR UPDATE')) |
| 124 | + const deleteIndex = statements.findIndex((statement) => |
| 125 | + statement.startsWith('DELETE FROM user_table_row_secret_provenance') |
| 126 | + ) |
| 127 | + expect(deleteIndex).toBeGreaterThan(lockIndex) |
| 128 | + expect(statements[deleteIndex]).toContain("AND status = 'unknown'") |
| 129 | + }) |
| 130 | + |
| 131 | + it('is a distinct entry so a repair that ran twice is recorded twice', () => { |
| 132 | + expect(repairUnknownTableRowProvenanceSecondPass.name).not.toBe( |
| 133 | + repairUnknownTableRowProvenance.name |
| 134 | + ) |
| 135 | + }) |
| 136 | +}) |
0 commit comments