Files
immich-redaktions-plugin/tests/db/download-history-index-migration-sql.test.ts
T
Leon Tonhäuser 0b65fbba16 fix: rebuild migration history as baseline so migrate works on prod
Squash the 13 historical migrations into one generated baseline whose
journal entry reuses the original 0000 timestamp: the migrator skips it
on every existing database (prod journal stuck at 0006) and applies it
only on fresh ones. Parity with the old chain verified via pg_dump diff
plus fresh/existing/prod-simulated drizzle-kit migrate runs. Historical
files move to drizzle-history/pre-squash-2026-08/ for integration tests
that exercise legacy migration behavior.

Also repair db tests that already failed before this change:
- raw SQL targeted users, but the table has always been "user"
- membership recheck mocked legacy getAsset.albums instead of searchPhotos
- audit rollback assertion walks drizzle's wrapped error cause chain
- keyset index probe pinned to NULLS LAST ordering, removing a planner
  cost tie-break that flipped with index creation order
2026-08-25 11:56:52 +02:00

20 lines
856 B
TypeScript

import { readFile } from "node:fs/promises";
import path from "node:path";
import { expect, test } from "vitest";
test("0004 adds both editorial history keyset indexes without rewriting history", async () => {
const migration = await readFile(
path.join(process.cwd(), "drizzle-history/pre-squash-2026-08/0004_download_history_indexes.sql"),
"utf8",
);
expect(migration).toContain(
'CREATE INDEX "download_events_editorial_authorized_id_idx" ON "download_events" USING btree ("editorial_account_id","authorized_at" DESC NULLS LAST,"id" DESC NULLS LAST)',
);
expect(migration).toContain(
'CREATE INDEX "usages_editorial_created_id_idx" ON "usages" USING btree ("editorial_account_id","created_at" DESC NULLS LAST,"id" DESC NULLS LAST)',
);
expect(migration).not.toMatch(/delete\s+from\s+"?(usages|download_events)"?/i);
});