mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat: migration api keys to use kysely (#15206)
This commit is contained in:
parent
3030e74fc3
commit
930f979960
9 changed files with 151 additions and 107 deletions
|
|
@ -1,77 +1,59 @@
|
|||
-- NOTE: This file is auto generated by ./sql-generator
|
||||
|
||||
-- ApiKeyRepository.getKey
|
||||
SELECT DISTINCT
|
||||
"distinctAlias"."APIKeyEntity_id" AS "ids_APIKeyEntity_id"
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
"APIKeyEntity"."id" AS "APIKeyEntity_id",
|
||||
"APIKeyEntity"."key" AS "APIKeyEntity_key",
|
||||
"APIKeyEntity"."userId" AS "APIKeyEntity_userId",
|
||||
"APIKeyEntity"."permissions" AS "APIKeyEntity_permissions",
|
||||
"APIKeyEntity__APIKeyEntity_user"."id" AS "APIKeyEntity__APIKeyEntity_user_id",
|
||||
"APIKeyEntity__APIKeyEntity_user"."name" AS "APIKeyEntity__APIKeyEntity_user_name",
|
||||
"APIKeyEntity__APIKeyEntity_user"."isAdmin" AS "APIKeyEntity__APIKeyEntity_user_isAdmin",
|
||||
"APIKeyEntity__APIKeyEntity_user"."email" AS "APIKeyEntity__APIKeyEntity_user_email",
|
||||
"APIKeyEntity__APIKeyEntity_user"."storageLabel" AS "APIKeyEntity__APIKeyEntity_user_storageLabel",
|
||||
"APIKeyEntity__APIKeyEntity_user"."oauthId" AS "APIKeyEntity__APIKeyEntity_user_oauthId",
|
||||
"APIKeyEntity__APIKeyEntity_user"."profileImagePath" AS "APIKeyEntity__APIKeyEntity_user_profileImagePath",
|
||||
"APIKeyEntity__APIKeyEntity_user"."shouldChangePassword" AS "APIKeyEntity__APIKeyEntity_user_shouldChangePassword",
|
||||
"APIKeyEntity__APIKeyEntity_user"."createdAt" AS "APIKeyEntity__APIKeyEntity_user_createdAt",
|
||||
"APIKeyEntity__APIKeyEntity_user"."deletedAt" AS "APIKeyEntity__APIKeyEntity_user_deletedAt",
|
||||
"APIKeyEntity__APIKeyEntity_user"."status" AS "APIKeyEntity__APIKeyEntity_user_status",
|
||||
"APIKeyEntity__APIKeyEntity_user"."updatedAt" AS "APIKeyEntity__APIKeyEntity_user_updatedAt",
|
||||
"APIKeyEntity__APIKeyEntity_user"."quotaSizeInBytes" AS "APIKeyEntity__APIKeyEntity_user_quotaSizeInBytes",
|
||||
"APIKeyEntity__APIKeyEntity_user"."quotaUsageInBytes" AS "APIKeyEntity__APIKeyEntity_user_quotaUsageInBytes",
|
||||
"APIKeyEntity__APIKeyEntity_user"."profileChangedAt" AS "APIKeyEntity__APIKeyEntity_user_profileChangedAt",
|
||||
"7f5f7a38bf327bfbbf826778460704c9a50fe6f4"."userId" AS "7f5f7a38bf327bfbbf826778460704c9a50fe6f4_userId",
|
||||
"7f5f7a38bf327bfbbf826778460704c9a50fe6f4"."key" AS "7f5f7a38bf327bfbbf826778460704c9a50fe6f4_key",
|
||||
"7f5f7a38bf327bfbbf826778460704c9a50fe6f4"."value" AS "7f5f7a38bf327bfbbf826778460704c9a50fe6f4_value"
|
||||
FROM
|
||||
"api_keys" "APIKeyEntity"
|
||||
LEFT JOIN "users" "APIKeyEntity__APIKeyEntity_user" ON "APIKeyEntity__APIKeyEntity_user"."id" = "APIKeyEntity"."userId"
|
||||
AND (
|
||||
"APIKeyEntity__APIKeyEntity_user"."deletedAt" IS NULL
|
||||
)
|
||||
LEFT JOIN "user_metadata" "7f5f7a38bf327bfbbf826778460704c9a50fe6f4" ON "7f5f7a38bf327bfbbf826778460704c9a50fe6f4"."userId" = "APIKeyEntity__APIKeyEntity_user"."id"
|
||||
WHERE
|
||||
(("APIKeyEntity"."key" = $1))
|
||||
) "distinctAlias"
|
||||
ORDER BY
|
||||
"APIKeyEntity_id" ASC
|
||||
LIMIT
|
||||
1
|
||||
select
|
||||
"api_keys"."id",
|
||||
"api_keys"."key",
|
||||
"api_keys"."userId",
|
||||
"api_keys"."permissions",
|
||||
to_json("user") as "user"
|
||||
from
|
||||
"api_keys"
|
||||
inner join lateral (
|
||||
select
|
||||
"users".*,
|
||||
(
|
||||
select
|
||||
array_agg("user_metadata") as "metadata"
|
||||
from
|
||||
"user_metadata"
|
||||
where
|
||||
"users"."id" = "user_metadata"."userId"
|
||||
) as "metadata"
|
||||
from
|
||||
"users"
|
||||
where
|
||||
"users"."id" = "api_keys"."userId"
|
||||
and "users"."deletedAt" is null
|
||||
) as "user" on true
|
||||
where
|
||||
"api_keys"."key" = $1
|
||||
|
||||
-- ApiKeyRepository.getById
|
||||
SELECT
|
||||
"APIKeyEntity"."id" AS "APIKeyEntity_id",
|
||||
"APIKeyEntity"."name" AS "APIKeyEntity_name",
|
||||
"APIKeyEntity"."userId" AS "APIKeyEntity_userId",
|
||||
"APIKeyEntity"."permissions" AS "APIKeyEntity_permissions",
|
||||
"APIKeyEntity"."createdAt" AS "APIKeyEntity_createdAt",
|
||||
"APIKeyEntity"."updatedAt" AS "APIKeyEntity_updatedAt"
|
||||
FROM
|
||||
"api_keys" "APIKeyEntity"
|
||||
WHERE
|
||||
(
|
||||
("APIKeyEntity"."userId" = $1)
|
||||
AND ("APIKeyEntity"."id" = $2)
|
||||
)
|
||||
LIMIT
|
||||
1
|
||||
select
|
||||
"id",
|
||||
"name",
|
||||
"userId",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"permissions"
|
||||
from
|
||||
"api_keys"
|
||||
where
|
||||
"id" = $1::uuid
|
||||
and "userId" = $2
|
||||
|
||||
-- ApiKeyRepository.getByUserId
|
||||
SELECT
|
||||
"APIKeyEntity"."id" AS "APIKeyEntity_id",
|
||||
"APIKeyEntity"."name" AS "APIKeyEntity_name",
|
||||
"APIKeyEntity"."userId" AS "APIKeyEntity_userId",
|
||||
"APIKeyEntity"."permissions" AS "APIKeyEntity_permissions",
|
||||
"APIKeyEntity"."createdAt" AS "APIKeyEntity_createdAt",
|
||||
"APIKeyEntity"."updatedAt" AS "APIKeyEntity_updatedAt"
|
||||
FROM
|
||||
"api_keys" "APIKeyEntity"
|
||||
WHERE
|
||||
(("APIKeyEntity"."userId" = $1))
|
||||
ORDER BY
|
||||
"APIKeyEntity"."createdAt" DESC
|
||||
select
|
||||
"id",
|
||||
"name",
|
||||
"userId",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"permissions"
|
||||
from
|
||||
"api_keys"
|
||||
where
|
||||
"userId" = $1
|
||||
order by
|
||||
"createdAt" desc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue