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
This commit is contained in:
Leon Tonhäuser committed 2026-08-25 11:56:52 +02:00
1 parent 2949149170
commit 0b65fbba16
40 files changed
+2389 -128

No files matched your search

+9 -2
View File
@@ -391,19 +391,26 @@ test("history ordering queries can use the editorial keyset indexes", async () =
try {
await client.query("begin");
await client.query("set local enable_seqscan = off");
await client.query("set local enable_sort = off");
// The keyset indexes sort NULLS LAST, so the probe queries must ask for the
// same null ordering. Otherwise the index cannot satisfy the ORDER BY, a
// Sort node is unavoidable and which scan feeds it is a cost tie-break
// between equal indexes that flips with index creation order.
const events = await client.query(
"explain (costs off) select id from download_events where editorial_account_id = $1 order by authorized_at desc, id desc limit 26",
"explain (costs off) select id from download_events where editorial_account_id = $1 order by authorized_at desc nulls last, id desc nulls last limit 26",
[own.editorialId],
);
const usageRows = await client.query(
"explain (costs off) select id from usages where editorial_account_id = $1 order by created_at desc, id desc limit 21",
"explain (costs off) select id from usages where editorial_account_id = $1 order by created_at desc nulls last, id desc nulls last limit 21",
[own.editorialId],
);
const eventPlan = events.rows.map((row) => row["QUERY PLAN"]).join("\n");
const usagePlan = usageRows.rows.map((row) => row["QUERY PLAN"]).join("\n");
expect(eventPlan).toContain("download_events_editorial_authorized_id_idx");
expect(eventPlan).not.toContain("Sort");
expect(usagePlan).toContain("usages_editorial_created_id_idx");
expect(usagePlan).not.toContain("Sort");
} finally {
await client.query("rollback");
client.release();