Files
immich-redaktions-plugin/tests/db/accounting-migration-sql.test.ts
T

44 lines
1.6 KiB
TypeScript

import { readFile } from "node:fs/promises";
import path from "node:path";
import { expect, test } from "vitest";
const migration = await readFile(
path.join(process.cwd(), "drizzle/0002_accounting_intents.sql"),
"utf8",
);
test("0002 retains legacy Immich text and gates only new non-canonical rows", () => {
expect(migration).not.toMatch(/ALTER COLUMN "immich_[^"]+" SET DATA TYPE uuid/);
expect(migration).toContain(
'ADD CONSTRAINT "album_grants_canonical_immich_album_id_check"',
);
expect(migration).toContain(
'ADD CONSTRAINT "usages_canonical_immich_asset_id_check"',
);
expect(migration).toContain(
'ADD CONSTRAINT "usages_canonical_immich_album_id_check"',
);
expect(migration).toContain(
'ADD CONSTRAINT "download_events_canonical_immich_asset_id_check"',
);
expect(migration.match(/NOT VALID/g)).toHaveLength(4);
});
test("0002 uses an explicit legacy kind instead of random UUID ordering for ambiguity", () => {
expect(migration).not.toContain('ORDER BY "authorized_at", "id"');
expect(migration).toContain("ELSE 'legacy'");
expect(migration).toContain("in ('new_usage', 'repeat_download', 'legacy')");
expect(migration).toContain("case_colliding_idempotency_keys");
});
test("0002 reconstructs only already-normalized printable ASCII text", () => {
expect(migration).not.toContain("btrim(");
expect(migration).toContain(
'octet_length(usage."purpose") = char_length(usage."purpose")',
);
expect(migration).toContain("!~ '[[:cntrl:]]'");
expect(migration).toContain("left(usage.\"purpose\", 1) <> ' '");
expect(migration).toContain("right(events.\"repeat_download_note\", 1) <> ' '");
});