mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat: sync albums and album users (#18377)
This commit is contained in:
parent
58af574241
commit
cd288533a1
41 changed files with 2811 additions and 934 deletions
|
|
@ -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,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue