feat: sync albums and album users (#18377)

This commit is contained in:
Jason Rasmussen 2025-05-21 15:35:32 -04:00 committed by GitHub
parent 58af574241
commit cd288533a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 2811 additions and 934 deletions

View file

@ -23,6 +23,19 @@ export const immich_uuid_v7 = registerFunction({
synchronize: false,
});
export const album_user_after_insert = registerFunction({
name: 'album_user_after_insert',
returnType: 'TRIGGER',
language: 'PLPGSQL',
body: `
BEGIN
UPDATE albums SET "updatedAt" = clock_timestamp(), "updateId" = immich_uuid_v7(clock_timestamp())
WHERE "id" IN (SELECT DISTINCT "albumsId" FROM inserted_rows);
RETURN NULL;
END`,
synchronize: false,
});
export const updated_at = registerFunction({
name: 'updated_at',
returnType: 'TRIGGER',
@ -114,3 +127,38 @@ export const assets_delete_audit = registerFunction({
END`,
synchronize: false,
});
export const albums_delete_audit = registerFunction({
name: 'albums_delete_audit',
returnType: 'TRIGGER',
language: 'PLPGSQL',
body: `
BEGIN
INSERT INTO albums_audit ("albumId", "userId")
SELECT "id", "ownerId"
FROM OLD;
RETURN NULL;
END`,
synchronize: false,
});
export const album_users_delete_audit = registerFunction({
name: 'album_users_delete_audit',
returnType: 'TRIGGER',
language: 'PLPGSQL',
body: `
BEGIN
INSERT INTO albums_audit ("albumId", "userId")
SELECT "albumsId", "usersId"
FROM OLD;
IF pg_trigger_depth() = 1 THEN
INSERT INTO album_users_audit ("albumId", "userId")
SELECT "albumsId", "usersId"
FROM OLD;
END IF;
RETURN NULL;
END`,
synchronize: false,
});