mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
refactor: migration tag repository to kysely (#16398)
This commit is contained in:
parent
ff19502035
commit
d1fd0076cc
12 changed files with 343 additions and 245 deletions
|
|
@ -1,10 +1,118 @@
|
|||
-- NOTE: This file is auto generated by ./sql-generator
|
||||
|
||||
-- TagRepository.getAssetIds
|
||||
SELECT
|
||||
"tag_asset"."assetsId" AS "assetId"
|
||||
FROM
|
||||
"tag_asset" "tag_asset"
|
||||
WHERE
|
||||
"tag_asset"."tagsId" = $1
|
||||
AND "tag_asset"."assetsId" IN ($2)
|
||||
-- TagRepository.get
|
||||
select
|
||||
"id",
|
||||
"value",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"color",
|
||||
"parentId"
|
||||
from
|
||||
"tags"
|
||||
where
|
||||
"id" = $1
|
||||
|
||||
-- TagRepository.getByValue
|
||||
select
|
||||
"id",
|
||||
"value",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"color",
|
||||
"parentId"
|
||||
from
|
||||
"tags"
|
||||
where
|
||||
"userId" = $1
|
||||
and "value" = $2
|
||||
|
||||
-- TagRepository.upsertValue
|
||||
begin
|
||||
insert into
|
||||
"tags" ("userId", "value", "parentId")
|
||||
values
|
||||
($1, $2, $3)
|
||||
on conflict ("userId", "value") do update
|
||||
set
|
||||
"parentId" = $4
|
||||
returning
|
||||
*
|
||||
rollback
|
||||
|
||||
-- TagRepository.getAll
|
||||
select
|
||||
"id",
|
||||
"value",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"color",
|
||||
"parentId"
|
||||
from
|
||||
"tags"
|
||||
where
|
||||
"userId" = $1
|
||||
order by
|
||||
"value" asc
|
||||
|
||||
-- TagRepository.create
|
||||
insert into
|
||||
"tags" ("userId", "color", "value")
|
||||
values
|
||||
($1, $2, $3)
|
||||
returning
|
||||
*
|
||||
|
||||
-- TagRepository.update
|
||||
update "tags"
|
||||
set
|
||||
"color" = $1
|
||||
where
|
||||
"id" = $2
|
||||
returning
|
||||
*
|
||||
|
||||
-- TagRepository.delete
|
||||
delete from "tags"
|
||||
where
|
||||
"id" = $1
|
||||
|
||||
-- TagRepository.addAssetIds
|
||||
insert into
|
||||
"tag_asset" ("tagsId", "assetsId")
|
||||
values
|
||||
($1, $2)
|
||||
|
||||
-- TagRepository.removeAssetIds
|
||||
delete from "tag_asset"
|
||||
where
|
||||
"tagsId" = $1
|
||||
and "assetsId" in ($2)
|
||||
|
||||
-- TagRepository.replaceAssetTags
|
||||
begin
|
||||
delete from "tag_asset"
|
||||
where
|
||||
"assetsId" = $1
|
||||
insert into
|
||||
"tag_asset" ("tagsId", "assetsId")
|
||||
values
|
||||
($1, $2)
|
||||
on conflict do nothing
|
||||
returning
|
||||
*
|
||||
rollback
|
||||
|
||||
-- TagRepository.deleteEmptyTags
|
||||
begin
|
||||
select
|
||||
"tags"."id",
|
||||
count("assets"."id") as "count"
|
||||
from
|
||||
"assets"
|
||||
inner join "tag_asset" on "tag_asset"."assetsId" = "assets"."id"
|
||||
inner join "tags_closure" on "tags_closure"."id_descendant" = "tag_asset"."tagsId"
|
||||
inner join "tags" on "tags"."id" = "tags_closure"."id_descendant"
|
||||
group by
|
||||
"tags"."id"
|
||||
commit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue