Files
immich/server/src/queries/user.repository.sql

392 lines
6.8 KiB
MySQL
Raw Normal View History

-- NOTE: This file is auto generated by ./sql-generator
-- UserRepository.get
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
"quotaUsageInBytes",
(
select
coalesce(json_agg(agg), '[]')
from
(
select
2025-04-10 15:53:21 +01:00
"user_metadata"."key",
"user_metadata"."value"
from
"user_metadata"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "user_metadata"."userId"
) as agg
) as "metadata"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."id" = $1
and "user"."deletedAt" is null
-- UserRepository.getAdmin
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
2025-04-10 15:53:21 +01:00
"quotaUsageInBytes",
(
select
coalesce(json_agg(agg), '[]')
from
(
select
"user_metadata"."key",
"user_metadata"."value"
from
"user_metadata"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "user_metadata"."userId"
2025-04-10 15:53:21 +01:00
) as agg
) as "metadata"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."isAdmin" = $1
and "user"."deletedAt" is null
-- UserRepository.getFileSamples
select
"id",
"profileImagePath"
from
"user"
where
"profileImagePath" != ''
limit
3
-- UserRepository.hasAdmin
select
2025-07-14 10:13:06 -04:00
"user"."id"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."isAdmin" = $1
and "user"."deletedAt" is null
-- UserRepository.getForPinCode
select
2025-07-14 10:13:06 -04:00
"user"."pinCode",
"user"."password"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."id" = $1
and "user"."deletedAt" is null
-- UserRepository.getForChangePassword
select
2025-07-14 10:13:06 -04:00
"user"."id",
"user"."password"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."id" = $1
and "user"."deletedAt" is null
-- UserRepository.getByEmail
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
2025-04-10 15:53:21 +01:00
"quotaUsageInBytes",
(
select
coalesce(json_agg(agg), '[]')
from
(
select
"user_metadata"."key",
"user_metadata"."value"
from
"user_metadata"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "user_metadata"."userId"
2025-04-10 15:53:21 +01:00
) as agg
) as "metadata"
from
2025-07-14 10:13:06 -04:00
"user"
where
"email" = $1
2025-07-14 10:13:06 -04:00
and "user"."deletedAt" is null
-- UserRepository.getByStorageLabel
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
"quotaUsageInBytes"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."storageLabel" = $1
and "user"."deletedAt" is null
-- UserRepository.getByOAuthId
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
2025-04-10 15:53:21 +01:00
"quotaUsageInBytes",
(
select
coalesce(json_agg(agg), '[]')
from
(
select
"user_metadata"."key",
"user_metadata"."value"
from
"user_metadata"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "user_metadata"."userId"
2025-04-10 15:53:21 +01:00
) as agg
) as "metadata"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."oauthId" = $1
and "user"."deletedAt" is null
-- UserRepository.getDeletedAfter
select
"id"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."deletedAt" < $1
-- UserRepository.getList (with deleted)
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
"quotaUsageInBytes",
(
select
coalesce(json_agg(agg), '[]')
from
(
select
2025-04-10 15:53:21 +01:00
"user_metadata"."key",
"user_metadata"."value"
from
"user_metadata"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "user_metadata"."userId"
) as agg
) as "metadata"
from
2025-07-14 10:13:06 -04:00
"user"
order by
"createdAt" desc
-- UserRepository.getList (without deleted)
select
"id",
"name",
"email",
2025-04-28 09:54:51 -04:00
"avatarColor",
"profileImagePath",
"profileChangedAt",
"createdAt",
"updatedAt",
"deletedAt",
"isAdmin",
"status",
"oauthId",
"profileImagePath",
"shouldChangePassword",
"storageLabel",
"quotaSizeInBytes",
"quotaUsageInBytes",
(
select
coalesce(json_agg(agg), '[]')
from
(
select
2025-04-10 15:53:21 +01:00
"user_metadata"."key",
"user_metadata"."value"
from
"user_metadata"
where
2025-07-14 10:13:06 -04:00
"user"."id" = "user_metadata"."userId"
) as agg
) as "metadata"
from
2025-07-14 10:13:06 -04:00
"user"
where
2025-07-14 10:13:06 -04:00
"user"."deletedAt" is null
order by
"createdAt" desc
-- UserRepository.getUserStats
select
2025-07-14 10:13:06 -04:00
"user"."id" as "userId",
"user"."name" as "userName",
"user"."quotaSizeInBytes",
count(*) filter (
where
(
2025-07-14 10:13:06 -04:00
"asset"."type" = 'IMAGE'
and "asset"."visibility" != 'hidden'
)
) as "photos",
count(*) filter (
where
(
2025-07-14 10:13:06 -04:00
"asset"."type" = 'VIDEO'
and "asset"."visibility" != 'hidden'
)
) as "videos",
coalesce(
2025-07-14 10:13:06 -04:00
sum("asset_exif"."fileSizeInByte") filter (
where
2025-07-14 10:13:06 -04:00
"asset"."libraryId" is null
),
0
) as "usage",
coalesce(
2025-07-14 10:13:06 -04:00
sum("asset_exif"."fileSizeInByte") filter (
where
(
2025-07-14 10:13:06 -04:00
"asset"."libraryId" is null
and "asset"."type" = 'IMAGE'
)
),
0
) as "usagePhotos",
coalesce(
2025-07-14 10:13:06 -04:00
sum("asset_exif"."fileSizeInByte") filter (
where
(
2025-07-14 10:13:06 -04:00
"asset"."libraryId" is null
and "asset"."type" = 'VIDEO'
)
),
0
) as "usageVideos"
from
2025-07-14 10:13:06 -04:00
"user"
left join "asset" on "asset"."ownerId" = "user"."id"
and "asset"."deletedAt" is null
left join "asset_exif" on "asset_exif"."assetId" = "asset"."id"
group by
2025-07-14 10:13:06 -04:00
"user"."id"
order by
2025-07-14 10:13:06 -04:00
"user"."createdAt" asc
-- UserRepository.updateUsage
2025-07-14 10:13:06 -04:00
update "user"
set
"quotaUsageInBytes" = "quotaUsageInBytes" + $1,
"updatedAt" = $2
where
"id" = $3::uuid
2025-07-14 10:13:06 -04:00
and "user"."deletedAt" is null
-- UserRepository.syncUsage
2025-07-14 10:13:06 -04:00
update "user"
set
"quotaUsageInBytes" = (
select
2025-07-14 10:13:06 -04:00
coalesce(sum("asset_exif"."fileSizeInByte"), 0) as "usage"
from
2025-07-14 10:13:06 -04:00
"asset"
left join "asset_exif" on "asset_exif"."assetId" = "asset"."id"
where
2025-07-14 10:13:06 -04:00
"asset"."libraryId" is null
and "asset"."ownerId" = "user"."id"
),
"updatedAt" = $1
where
2025-07-14 10:13:06 -04:00
"user"."deletedAt" is null
and "user"."id" = $2::uuid