mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
refactor: migrate access repo to kysely (#15365)
This commit is contained in:
parent
89f40b311c
commit
378bd3c993
2 changed files with 367 additions and 477 deletions
|
|
@ -1,180 +1,137 @@
|
|||
-- NOTE: This file is auto generated by ./sql-generator
|
||||
|
||||
-- AccessRepository.activity.checkOwnerAccess
|
||||
SELECT
|
||||
"ActivityEntity"."id" AS "ActivityEntity_id"
|
||||
FROM
|
||||
"activity" "ActivityEntity"
|
||||
WHERE
|
||||
(
|
||||
("ActivityEntity"."id" IN ($1))
|
||||
AND ("ActivityEntity"."userId" = $2)
|
||||
)
|
||||
select
|
||||
"activity"."id"
|
||||
from
|
||||
"activity"
|
||||
where
|
||||
"activity"."id" in ($1)
|
||||
and "activity"."userId" = $2
|
||||
|
||||
-- AccessRepository.activity.checkAlbumOwnerAccess
|
||||
SELECT
|
||||
"ActivityEntity"."id" AS "ActivityEntity_id"
|
||||
FROM
|
||||
"activity" "ActivityEntity"
|
||||
LEFT JOIN "albums" "ActivityEntity__ActivityEntity_album" ON "ActivityEntity__ActivityEntity_album"."id" = "ActivityEntity"."albumId"
|
||||
AND (
|
||||
"ActivityEntity__ActivityEntity_album"."deletedAt" IS NULL
|
||||
)
|
||||
WHERE
|
||||
(
|
||||
("ActivityEntity"."id" IN ($1))
|
||||
AND (
|
||||
(
|
||||
(
|
||||
"ActivityEntity__ActivityEntity_album"."ownerId" = $2
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
select
|
||||
"activity"."id"
|
||||
from
|
||||
"activity"
|
||||
left join "albums" on "activity"."albumId" = "albums"."id"
|
||||
and "albums"."deletedAt" is null
|
||||
where
|
||||
"activity"."id" in ($1)
|
||||
and "albums"."ownerId" = $2::uuid
|
||||
|
||||
-- AccessRepository.activity.checkCreateAccess
|
||||
SELECT
|
||||
"album"."id" AS "album_id"
|
||||
FROM
|
||||
"albums" "album"
|
||||
LEFT JOIN "albums_shared_users_users" "album_albumUsers_users" ON "album_albumUsers_users"."albumsId" = "album"."id"
|
||||
LEFT JOIN "users" "albumUsers" ON "albumUsers"."id" = "album_albumUsers_users"."usersId"
|
||||
AND ("albumUsers"."deletedAt" IS NULL)
|
||||
WHERE
|
||||
(
|
||||
"album"."id" IN ($1)
|
||||
AND "album"."isActivityEnabled" = true
|
||||
AND (
|
||||
"album"."ownerId" = $2
|
||||
OR "albumUsers"."id" = $2
|
||||
)
|
||||
select
|
||||
"albums"."id"
|
||||
from
|
||||
"albums"
|
||||
left join "albums_shared_users_users" as "albumUsers" on "albumUsers"."albumsId" = "albums"."id"
|
||||
left join "users" on "users"."id" = "albumUsers"."usersId"
|
||||
and "users"."deletedAt" is null
|
||||
where
|
||||
"albums"."id" in ($1)
|
||||
and "albums"."isActivityEnabled" = $2
|
||||
and (
|
||||
"albums"."ownerId" = $3
|
||||
or "users"."id" = $4
|
||||
)
|
||||
AND ("album"."deletedAt" IS NULL)
|
||||
and "albums"."deletedAt" is null
|
||||
|
||||
-- AccessRepository.album.checkOwnerAccess
|
||||
SELECT
|
||||
"AlbumEntity"."id" AS "AlbumEntity_id"
|
||||
FROM
|
||||
"albums" "AlbumEntity"
|
||||
WHERE
|
||||
(
|
||||
(
|
||||
("AlbumEntity"."id" IN ($1))
|
||||
AND ("AlbumEntity"."ownerId" = $2)
|
||||
)
|
||||
)
|
||||
AND ("AlbumEntity"."deletedAt" IS NULL)
|
||||
select
|
||||
"albums"."id"
|
||||
from
|
||||
"albums"
|
||||
where
|
||||
"albums"."id" in ($1)
|
||||
and "albums"."ownerId" = $2
|
||||
and "albums"."deletedAt" is null
|
||||
|
||||
-- AccessRepository.album.checkSharedAlbumAccess
|
||||
SELECT
|
||||
"AlbumEntity"."id" AS "AlbumEntity_id"
|
||||
FROM
|
||||
"albums" "AlbumEntity"
|
||||
LEFT JOIN "albums_shared_users_users" "AlbumEntity__AlbumEntity_albumUsers" ON "AlbumEntity__AlbumEntity_albumUsers"."albumsId" = "AlbumEntity"."id"
|
||||
LEFT JOIN "users" "a641d58cf46d4a391ba060ac4dc337665c69ffea" ON "a641d58cf46d4a391ba060ac4dc337665c69ffea"."id" = "AlbumEntity__AlbumEntity_albumUsers"."usersId"
|
||||
AND (
|
||||
"a641d58cf46d4a391ba060ac4dc337665c69ffea"."deletedAt" IS NULL
|
||||
)
|
||||
WHERE
|
||||
(
|
||||
(
|
||||
("AlbumEntity"."id" IN ($1))
|
||||
AND (
|
||||
(
|
||||
(
|
||||
(
|
||||
(
|
||||
"a641d58cf46d4a391ba060ac4dc337665c69ffea"."id" = $2
|
||||
)
|
||||
)
|
||||
)
|
||||
AND (
|
||||
"AlbumEntity__AlbumEntity_albumUsers"."role" IN ($3, $4)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
AND ("AlbumEntity"."deletedAt" IS NULL)
|
||||
select
|
||||
"albums"."id"
|
||||
from
|
||||
"albums"
|
||||
left join "albums_shared_users_users" as "albumUsers" on "albumUsers"."albumsId" = "albums"."id"
|
||||
left join "users" on "users"."id" = "albumUsers"."usersId"
|
||||
and "users"."deletedAt" is null
|
||||
where
|
||||
"albums"."id" in ($1)
|
||||
and "albums"."deletedAt" is null
|
||||
and "users"."id" = $2
|
||||
and "albumUsers"."role" in ($3, $4)
|
||||
|
||||
-- AccessRepository.album.checkSharedLinkAccess
|
||||
SELECT
|
||||
"SharedLinkEntity"."albumId" AS "SharedLinkEntity_albumId",
|
||||
"SharedLinkEntity"."id" AS "SharedLinkEntity_id"
|
||||
FROM
|
||||
"shared_links" "SharedLinkEntity"
|
||||
WHERE
|
||||
(
|
||||
("SharedLinkEntity"."id" = $1)
|
||||
AND ("SharedLinkEntity"."albumId" IN ($2))
|
||||
)
|
||||
select
|
||||
"shared_links"."albumId"
|
||||
from
|
||||
"shared_links"
|
||||
where
|
||||
"shared_links"."id" = $1
|
||||
and "shared_links"."albumId" in ($2)
|
||||
|
||||
-- AccessRepository.asset.checkAlbumAccess
|
||||
SELECT
|
||||
"asset"."id" AS "assetId",
|
||||
"asset"."livePhotoVideoId" AS "livePhotoVideoId"
|
||||
FROM
|
||||
"albums" "album"
|
||||
INNER JOIN "albums_assets_assets" "album_asset" ON "album_asset"."albumsId" = "album"."id"
|
||||
INNER JOIN "assets" "asset" ON "asset"."id" = "album_asset"."assetsId"
|
||||
AND ("asset"."deletedAt" IS NULL)
|
||||
LEFT JOIN "albums_shared_users_users" "album_albumUsers_users" ON "album_albumUsers_users"."albumsId" = "album"."id"
|
||||
LEFT JOIN "users" "albumUsers" ON "albumUsers"."id" = "album_albumUsers_users"."usersId"
|
||||
AND ("albumUsers"."deletedAt" IS NULL)
|
||||
WHERE
|
||||
(
|
||||
array["asset"."id", "asset"."livePhotoVideoId"] && array[$1]::uuid []
|
||||
AND (
|
||||
"album"."ownerId" = $2
|
||||
OR "albumUsers"."id" = $2
|
||||
)
|
||||
select
|
||||
"assets"."id",
|
||||
"assets"."livePhotoVideoId"
|
||||
from
|
||||
"albums"
|
||||
inner join "albums_assets_assets" as "albumAssets" on "albums"."id" = "albumAssets"."albumsId"
|
||||
inner join "assets" on "assets"."id" = "albumAssets"."assetsId"
|
||||
and "assets"."deletedAt" is null
|
||||
left join "albums_shared_users_users" as "albumUsers" on "albumUsers"."albumsId" = "albums"."id"
|
||||
left join "users" on "users"."id" = "albumUsers"."usersId"
|
||||
and "users"."deletedAt" is null
|
||||
where
|
||||
array["assets"."id", "assets"."livePhotoVideoId"] && array[$1]::uuid []
|
||||
and (
|
||||
"albums"."ownerId" = $2
|
||||
or "users"."id" = $3
|
||||
)
|
||||
AND ("album"."deletedAt" IS NULL)
|
||||
and "albums"."deletedAt" is null
|
||||
|
||||
-- AccessRepository.asset.checkOwnerAccess
|
||||
SELECT
|
||||
"AssetEntity"."id" AS "AssetEntity_id"
|
||||
FROM
|
||||
"assets" "AssetEntity"
|
||||
WHERE
|
||||
(
|
||||
("AssetEntity"."id" IN ($1))
|
||||
AND ("AssetEntity"."ownerId" = $2)
|
||||
)
|
||||
select
|
||||
"assets"."id"
|
||||
from
|
||||
"assets"
|
||||
where
|
||||
"assets"."id" in ($1)
|
||||
and "assets"."ownerId" = $2
|
||||
|
||||
-- AccessRepository.asset.checkPartnerAccess
|
||||
SELECT
|
||||
"asset"."id" AS "assetId"
|
||||
FROM
|
||||
"partners" "partner"
|
||||
INNER JOIN "users" "sharedBy" ON "sharedBy"."id" = "partner"."sharedById"
|
||||
AND ("sharedBy"."deletedAt" IS NULL)
|
||||
INNER JOIN "assets" "asset" ON "asset"."ownerId" = "sharedBy"."id"
|
||||
AND ("asset"."deletedAt" IS NULL)
|
||||
WHERE
|
||||
select
|
||||
"assets"."id"
|
||||
from
|
||||
"partners" as "partner"
|
||||
inner join "users" as "sharedBy" on "sharedBy"."id" = "partner"."sharedById"
|
||||
and "sharedBy"."deletedAt" is null
|
||||
inner join "assets" on "assets"."ownerId" = "sharedBy"."id"
|
||||
and "assets"."deletedAt" is null
|
||||
where
|
||||
"partner"."sharedWithId" = $1
|
||||
AND "asset"."isArchived" = false
|
||||
AND "asset"."id" IN ($2)
|
||||
and "assets"."isArchived" = $2
|
||||
and "assets"."id" in ($3)
|
||||
|
||||
-- AccessRepository.asset.checkSharedLinkAccess
|
||||
SELECT
|
||||
"assets"."id" AS "assetId",
|
||||
"assets"."livePhotoVideoId" AS "assetLivePhotoVideoId",
|
||||
"albumAssets"."id" AS "albumAssetId",
|
||||
"albumAssets"."livePhotoVideoId" AS "albumAssetLivePhotoVideoId"
|
||||
FROM
|
||||
"shared_links" "sharedLink"
|
||||
LEFT JOIN "albums" "album" ON "album"."id" = "sharedLink"."albumId"
|
||||
AND ("album"."deletedAt" IS NULL)
|
||||
LEFT JOIN "shared_link__asset" "assets_sharedLink" ON "assets_sharedLink"."sharedLinksId" = "sharedLink"."id"
|
||||
LEFT JOIN "assets" "assets" ON "assets"."id" = "assets_sharedLink"."assetsId"
|
||||
AND ("assets"."deletedAt" IS NULL)
|
||||
LEFT JOIN "albums_assets_assets" "album_albumAssets" ON "album_albumAssets"."albumsId" = "album"."id"
|
||||
LEFT JOIN "assets" "albumAssets" ON "albumAssets"."id" = "album_albumAssets"."assetsId"
|
||||
AND ("albumAssets"."deletedAt" IS NULL)
|
||||
WHERE
|
||||
"sharedLink"."id" = $1
|
||||
AND array[
|
||||
select
|
||||
"assets"."id" as "assetId",
|
||||
"assets"."livePhotoVideoId" as "assetLivePhotoVideoId",
|
||||
"albumAssets"."id" as "albumAssetId",
|
||||
"albumAssets"."livePhotoVideoId" as "albumAssetLivePhotoVideoId"
|
||||
from
|
||||
"shared_links"
|
||||
left join "albums" on "albums"."id" = "shared_links"."albumId"
|
||||
and "albums"."deletedAt" is null
|
||||
left join "shared_link__asset" on "shared_link__asset"."sharedLinksId" = "shared_links"."id"
|
||||
left join "assets" on "assets"."id" = "shared_link__asset"."assetsId"
|
||||
and "assets"."deletedAt" is null
|
||||
left join "albums_assets_assets" on "albums_assets_assets"."albumsId" = "albums"."id"
|
||||
left join "assets" as "albumAssets" on "albumAssets"."id" = "albums_assets_assets"."assetsId"
|
||||
and "albumAssets"."deletedAt" is null
|
||||
where
|
||||
"shared_links"."id" = $1
|
||||
and array[
|
||||
"assets"."id",
|
||||
"assets"."livePhotoVideoId",
|
||||
"albumAssets"."id",
|
||||
|
|
@ -182,100 +139,76 @@ WHERE
|
|||
] && array[$2]::uuid []
|
||||
|
||||
-- AccessRepository.authDevice.checkOwnerAccess
|
||||
SELECT
|
||||
"SessionEntity"."id" AS "SessionEntity_id"
|
||||
FROM
|
||||
"sessions" "SessionEntity"
|
||||
WHERE
|
||||
(
|
||||
("SessionEntity"."userId" = $1)
|
||||
AND ("SessionEntity"."id" IN ($2))
|
||||
)
|
||||
select
|
||||
"sessions"."id"
|
||||
from
|
||||
"sessions"
|
||||
where
|
||||
"sessions"."userId" = $1
|
||||
and "sessions"."id" in ($2)
|
||||
|
||||
-- AccessRepository.memory.checkOwnerAccess
|
||||
SELECT
|
||||
"MemoryEntity"."id" AS "MemoryEntity_id"
|
||||
FROM
|
||||
"memories" "MemoryEntity"
|
||||
WHERE
|
||||
(
|
||||
(
|
||||
("MemoryEntity"."id" IN ($1))
|
||||
AND ("MemoryEntity"."ownerId" = $2)
|
||||
)
|
||||
)
|
||||
AND ("MemoryEntity"."deletedAt" IS NULL)
|
||||
select
|
||||
"memories"."id"
|
||||
from
|
||||
"memories"
|
||||
where
|
||||
"memories"."id" in ($1)
|
||||
and "memories"."ownerId" = $2
|
||||
and "memories"."deletedAt" is null
|
||||
|
||||
-- AccessRepository.person.checkOwnerAccess
|
||||
SELECT
|
||||
"PersonEntity"."id" AS "PersonEntity_id"
|
||||
FROM
|
||||
"person" "PersonEntity"
|
||||
WHERE
|
||||
(
|
||||
("PersonEntity"."id" IN ($1))
|
||||
AND ("PersonEntity"."ownerId" = $2)
|
||||
)
|
||||
select
|
||||
"person"."id"
|
||||
from
|
||||
"person"
|
||||
where
|
||||
"person"."id" in ($1)
|
||||
and "person"."ownerId" = $2
|
||||
|
||||
-- AccessRepository.person.checkFaceOwnerAccess
|
||||
SELECT
|
||||
"AssetFaceEntity"."id" AS "AssetFaceEntity_id"
|
||||
FROM
|
||||
"asset_faces" "AssetFaceEntity"
|
||||
LEFT JOIN "assets" "AssetFaceEntity__AssetFaceEntity_asset" ON "AssetFaceEntity__AssetFaceEntity_asset"."id" = "AssetFaceEntity"."assetId"
|
||||
AND (
|
||||
"AssetFaceEntity__AssetFaceEntity_asset"."deletedAt" IS NULL
|
||||
)
|
||||
WHERE
|
||||
(
|
||||
("AssetFaceEntity"."id" IN ($1))
|
||||
AND (
|
||||
(
|
||||
(
|
||||
"AssetFaceEntity__AssetFaceEntity_asset"."ownerId" = $2
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
select
|
||||
"asset_faces"."id"
|
||||
from
|
||||
"asset_faces"
|
||||
left join "assets" on "assets"."id" = "asset_faces"."assetId"
|
||||
and "assets"."deletedAt" is null
|
||||
where
|
||||
"asset_faces"."id" in ($1)
|
||||
and "assets"."ownerId" = $2
|
||||
|
||||
-- AccessRepository.partner.checkUpdateAccess
|
||||
SELECT
|
||||
"partner"."sharedById" AS "partner_sharedById",
|
||||
"partner"."sharedWithId" AS "partner_sharedWithId"
|
||||
FROM
|
||||
"partners" "partner"
|
||||
WHERE
|
||||
"partner"."sharedById" IN ($1)
|
||||
AND "partner"."sharedWithId" = $2
|
||||
select
|
||||
"partners"."sharedById"
|
||||
from
|
||||
"partners"
|
||||
where
|
||||
"partners"."sharedById" in ($1)
|
||||
and "partners"."sharedWithId" = $2
|
||||
|
||||
-- AccessRepository.stack.checkOwnerAccess
|
||||
SELECT
|
||||
"StackEntity"."id" AS "StackEntity_id"
|
||||
FROM
|
||||
"asset_stack" "StackEntity"
|
||||
WHERE
|
||||
(
|
||||
("StackEntity"."id" IN ($1))
|
||||
AND ("StackEntity"."ownerId" = $2)
|
||||
)
|
||||
select
|
||||
"stacks"."id"
|
||||
from
|
||||
"asset_stack" as "stacks"
|
||||
where
|
||||
"stacks"."id" in ($1)
|
||||
and "stacks"."ownerId" = $2
|
||||
|
||||
-- AccessRepository.tag.checkOwnerAccess
|
||||
SELECT
|
||||
"TagEntity"."id" AS "TagEntity_id"
|
||||
FROM
|
||||
"tags" "TagEntity"
|
||||
WHERE
|
||||
(
|
||||
("TagEntity"."id" IN ($1))
|
||||
AND ("TagEntity"."userId" = $2)
|
||||
)
|
||||
select
|
||||
"tags"."id"
|
||||
from
|
||||
"tags"
|
||||
where
|
||||
"tags"."id" in ($1)
|
||||
and "tags"."userId" = $2
|
||||
|
||||
-- AccessRepository.timeline.checkPartnerAccess
|
||||
SELECT
|
||||
"partner"."sharedById" AS "partner_sharedById",
|
||||
"partner"."sharedWithId" AS "partner_sharedWithId"
|
||||
FROM
|
||||
"partners" "partner"
|
||||
WHERE
|
||||
"partner"."sharedById" IN ($1)
|
||||
AND "partner"."sharedWithId" = $2
|
||||
select
|
||||
"partners"."sharedById"
|
||||
from
|
||||
"partners"
|
||||
where
|
||||
"partners"."sharedById" in ($1)
|
||||
and "partners"."sharedWithId" = $2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue