fix: enforce one active logical album grant
This commit is contained in:
1 parent
74ab2eb85f
commit
c400167b8f
9 files changed
+577
-45
No files matched your search
@@ -8,11 +8,12 @@ const migration = await readFile(
|
||||
"utf8",
|
||||
);
|
||||
|
||||
test("0002 retains legacy Immich text and gates only new non-canonical rows", () => {
|
||||
test("0002 retains legacy Immich text and accepts case-variant historical UUIDs", () => {
|
||||
expect(migration).not.toMatch(/ALTER COLUMN "immich_[^"]+" SET DATA TYPE uuid/);
|
||||
expect(migration).toContain(
|
||||
'ADD CONSTRAINT "album_grants_canonical_immich_album_id_check"',
|
||||
'ADD CONSTRAINT "album_grants_immich_album_id_uuid_check"',
|
||||
);
|
||||
expect(migration).toContain('CHECK ("album_grants"."immich_album_id" ~*');
|
||||
expect(migration).toContain(
|
||||
'ADD CONSTRAINT "usages_canonical_immich_asset_id_check"',
|
||||
);
|
||||
@@ -25,6 +26,25 @@ test("0002 retains legacy Immich text and gates only new non-canonical rows", ()
|
||||
expect(migration.match(/NOT VALID/g)).toHaveLength(4);
|
||||
});
|
||||
|
||||
test("0002 consolidates active case duplicates before adding their partial unique index", () => {
|
||||
const consolidation = migration.indexOf('ranked_active_album_grants AS');
|
||||
const activeIndex = migration.indexOf(
|
||||
'CREATE UNIQUE INDEX "album_grants_editorial_active_album_unique"',
|
||||
);
|
||||
|
||||
expect(consolidation).toBeGreaterThan(-1);
|
||||
expect(migration).toContain(
|
||||
'PARTITION BY "editorial_account_id", lower("immich_album_id")',
|
||||
);
|
||||
expect(migration).toContain(
|
||||
'ORDER BY ("immich_album_id" = lower("immich_album_id")) DESC, "granted_at", "id"',
|
||||
);
|
||||
expect(activeIndex).toBeGreaterThan(consolidation);
|
||||
expect(migration).toContain(
|
||||
'ON "album_grants" ("editorial_account_id", lower("immich_album_id")) WHERE "revoked_at" IS NULL',
|
||||
);
|
||||
});
|
||||
|
||||
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'");
|
||||
|
||||
Reference in new issue
Block a user