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

+20 -17
View File
@@ -225,21 +225,9 @@ test("requires an active grant for the exact requested album", async () => {
test("rechecks exact album membership after database locks before inserting", async () => {
const editorialId = await seedEditorial();
const { usageService, immich } = createServices();
immich.getAsset
.mockResolvedValueOnce({
id: assetId,
type: "IMAGE" as const,
originalFileName: "jubel.jpg",
originalMimeType: "image/jpeg",
albums: [{ id: albumId }],
})
.mockResolvedValueOnce({
id: assetId,
type: "IMAGE" as const,
originalFileName: "jubel.jpg",
originalMimeType: "image/jpeg",
albums: [],
});
immich.searchPhotos
.mockResolvedValueOnce({ items: [{ id: assetId }], total: 1, nextPage: null, previousPage: null })
.mockResolvedValueOnce({ items: [], total: 0, nextPage: null, previousPage: null });
await expect(usageService.createNewUsage(newInput(editorialId))).rejects.toMatchObject({
code: "ASSET_NOT_IN_ALBUM",
@@ -248,7 +236,7 @@ test("rechecks exact album membership after database locks before inserting", as
.select({ value: count() })
.from(usages)
.where(eq(usages.editorialAccountId, editorialId));
expect(immich.getAlbum).toHaveBeenCalledTimes(2);
expect(immich.getAlbum).toHaveBeenCalledTimes(1);
expect(usageCount.value).toBe(0);
});
@@ -397,6 +385,19 @@ test("the same key may be reused by a different editorial but not for a differen
});
});
function errorChainIncludes(expected: string) {
return (error: unknown): boolean => {
let current = error;
while (current instanceof Error) {
if (current.message.includes(expected)) return true;
const cause: unknown = current.cause;
if (!cause) break;
current = cause;
}
return false;
};
}
test("an audit failure rolls back both the usage and authorized event", async () => {
const editorialId = await seedEditorial();
const { usageService } = createServices();
@@ -413,7 +414,9 @@ test("an audit failure rolls back both the usage and authorized event", async ()
`);
try {
await expect(usageService.createNewUsage(newInput(editorialId))).rejects.toThrow("audit rejected");
await expect(usageService.createNewUsage(newInput(editorialId))).rejects.toSatisfy(
errorChainIncludes("audit rejected"),
);
} finally {
await testDb.pool.query("drop trigger reject_billable_usage_audit on audit_events");
await testDb.pool.query("drop function reject_billable_usage_audit()");