feat(migrate): migration_map idempotency ledger

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
root
2026-06-04 22:18:05 +10:00
parent bbb90c12c6
commit 681b091e4a
3 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { resetDb } from '../helpers/db.js';
import { migrateUp } from '../../lib/db/migrate.js';
import * as map from '../../lib/db/repos/migration_map.js';
import { randomUUID } from 'crypto';
beforeAll(async () => { await resetDb(); await migrateUp(); });
describe('migration_map', () => {
it('seen() is null until record(), then returns the entity id', async () => {
const eid = randomUUID();
expect(await map.seen('void1', 'wiki_pages:1', 'page')).toBeNull();
await map.record('void1', 'wiki_pages:1', 'page', eid);
expect(await map.seen('void1', 'wiki_pages:1', 'page')).toBe(eid);
});
it('record() is idempotent on the unique key', async () => {
const eid = randomUUID();
await map.record('plans', 'a.md', 'page', eid);
await map.record('plans', 'a.md', 'page', randomUUID()); // ignored
expect(await map.seen('plans', 'a.md', 'page')).toBe(eid);
});
});