mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor: database column names (#23356)
This commit is contained in:
parent
0df70365d7
commit
29c14a3f58
43 changed files with 467 additions and 368 deletions
|
|
@ -356,7 +356,7 @@ export const columns = {
|
|||
'asset.stackId',
|
||||
'asset.libraryId',
|
||||
],
|
||||
syncAlbumUser: ['album_user.albumsId as albumId', 'album_user.usersId as userId', 'album_user.role'],
|
||||
syncAlbumUser: ['album_user.albumId as albumId', 'album_user.userId as userId', 'album_user.role'],
|
||||
syncStack: ['stack.id', 'stack.createdAt', 'stack.updatedAt', 'stack.primaryAssetId', 'stack.ownerId'],
|
||||
syncUser: ['id', 'name', 'email', 'avatarColor', 'deletedAt', 'updateId', 'profileImagePath', 'profileChangedAt'],
|
||||
stack: ['stack.id', 'stack.primaryAssetId', 'ownerId'],
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ select
|
|||
"album"."id"
|
||||
from
|
||||
"album"
|
||||
left join "album_user" as "albumUsers" on "albumUsers"."albumsId" = "album"."id"
|
||||
left join "user" on "user"."id" = "albumUsers"."usersId"
|
||||
left join "album_user" as "albumUsers" on "albumUsers"."albumId" = "album"."id"
|
||||
left join "user" on "user"."id" = "albumUsers"."userId"
|
||||
and "user"."deletedAt" is null
|
||||
where
|
||||
"album"."id" in ($1)
|
||||
|
|
@ -52,8 +52,8 @@ select
|
|||
"album"."id"
|
||||
from
|
||||
"album"
|
||||
left join "album_user" on "album_user"."albumsId" = "album"."id"
|
||||
left join "user" on "user"."id" = "album_user"."usersId"
|
||||
left join "album_user" on "album_user"."albumId" = "album"."id"
|
||||
left join "user" on "user"."id" = "album_user"."userId"
|
||||
and "user"."deletedAt" is null
|
||||
where
|
||||
"album"."id" in ($1)
|
||||
|
|
@ -81,11 +81,11 @@ select
|
|||
"asset"."livePhotoVideoId"
|
||||
from
|
||||
"album"
|
||||
inner join "album_asset" as "albumAssets" on "album"."id" = "albumAssets"."albumsId"
|
||||
inner join "asset" on "asset"."id" = "albumAssets"."assetsId"
|
||||
inner join "album_asset" as "albumAssets" on "album"."id" = "albumAssets"."albumId"
|
||||
inner join "asset" on "asset"."id" = "albumAssets"."assetId"
|
||||
and "asset"."deletedAt" is null
|
||||
left join "album_user" as "albumUsers" on "albumUsers"."albumsId" = "album"."id"
|
||||
left join "user" on "user"."id" = "albumUsers"."usersId"
|
||||
left join "album_user" as "albumUsers" on "albumUsers"."albumId" = "album"."id"
|
||||
left join "user" on "user"."id" = "albumUsers"."userId"
|
||||
and "user"."deletedAt" is null
|
||||
cross join "target"
|
||||
where
|
||||
|
|
@ -136,11 +136,11 @@ from
|
|||
"shared_link"
|
||||
left join "album" on "album"."id" = "shared_link"."albumId"
|
||||
and "album"."deletedAt" is null
|
||||
left join "shared_link_asset" on "shared_link_asset"."sharedLinksId" = "shared_link"."id"
|
||||
left join "asset" on "asset"."id" = "shared_link_asset"."assetsId"
|
||||
left join "shared_link_asset" on "shared_link_asset"."sharedLinkId" = "shared_link"."id"
|
||||
left join "asset" on "asset"."id" = "shared_link_asset"."assetId"
|
||||
and "asset"."deletedAt" is null
|
||||
left join "album_asset" on "album_asset"."albumsId" = "album"."id"
|
||||
left join "asset" as "albumAssets" on "albumAssets"."id" = "album_asset"."assetsId"
|
||||
left join "album_asset" on "album_asset"."albumId" = "album"."id"
|
||||
left join "asset" as "albumAssets" on "albumAssets"."id" = "album_asset"."assetId"
|
||||
and "albumAssets"."deletedAt" is null
|
||||
where
|
||||
"shared_link"."id" = $1
|
||||
|
|
|
|||
|
|
@ -43,13 +43,13 @@ select
|
|||
from
|
||||
"user"
|
||||
where
|
||||
"user"."id" = "album_user"."usersId"
|
||||
"user"."id" = "album_user"."userId"
|
||||
) as obj
|
||||
) as "user"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
"album_user"."albumId" = "album"."id"
|
||||
) as agg
|
||||
) as "albumUsers",
|
||||
(
|
||||
|
|
@ -76,9 +76,9 @@ select
|
|||
from
|
||||
"asset"
|
||||
left join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
|
||||
inner join "album_asset" on "album_asset"."assetsId" = "asset"."id"
|
||||
inner join "album_asset" on "album_asset"."assetId" = "asset"."id"
|
||||
where
|
||||
"album_asset"."albumsId" = "album"."id"
|
||||
"album_asset"."albumId" = "album"."id"
|
||||
and "asset"."deletedAt" is null
|
||||
and "asset"."visibility" in ('archive', 'timeline')
|
||||
order by
|
||||
|
|
@ -134,18 +134,18 @@ select
|
|||
from
|
||||
"user"
|
||||
where
|
||||
"user"."id" = "album_user"."usersId"
|
||||
"user"."id" = "album_user"."userId"
|
||||
) as obj
|
||||
) as "user"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
"album_user"."albumId" = "album"."id"
|
||||
) as agg
|
||||
) as "albumUsers"
|
||||
from
|
||||
"album"
|
||||
inner join "album_asset" on "album_asset"."albumsId" = "album"."id"
|
||||
inner join "album_asset" on "album_asset"."albumId" = "album"."id"
|
||||
where
|
||||
(
|
||||
"album"."ownerId" = $1
|
||||
|
|
@ -154,11 +154,11 @@ where
|
|||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
and "album_user"."usersId" = $2
|
||||
"album_user"."albumId" = "album"."id"
|
||||
and "album_user"."userId" = $2
|
||||
)
|
||||
)
|
||||
and "album_asset"."assetsId" = $3
|
||||
and "album_asset"."assetId" = $3
|
||||
and "album"."deletedAt" is null
|
||||
order by
|
||||
"album"."createdAt" desc,
|
||||
|
|
@ -166,7 +166,7 @@ order by
|
|||
|
||||
-- AlbumRepository.getMetadataForIds
|
||||
select
|
||||
"album_asset"."albumsId" as "albumId",
|
||||
"album_asset"."albumId" as "albumId",
|
||||
min(
|
||||
("asset"."localDateTime" AT TIME ZONE 'UTC'::text)::date
|
||||
) as "startDate",
|
||||
|
|
@ -177,13 +177,13 @@ select
|
|||
count("asset"."id")::int as "assetCount"
|
||||
from
|
||||
"asset"
|
||||
inner join "album_asset" on "album_asset"."assetsId" = "asset"."id"
|
||||
inner join "album_asset" on "album_asset"."assetId" = "asset"."id"
|
||||
where
|
||||
"asset"."visibility" in ('archive', 'timeline')
|
||||
and "album_asset"."albumsId" in ($1)
|
||||
and "album_asset"."albumId" in ($1)
|
||||
and "asset"."deletedAt" is null
|
||||
group by
|
||||
"album_asset"."albumsId"
|
||||
"album_asset"."albumId"
|
||||
|
||||
-- AlbumRepository.getOwned
|
||||
select
|
||||
|
|
@ -228,13 +228,13 @@ select
|
|||
from
|
||||
"user"
|
||||
where
|
||||
"user"."id" = "album_user"."usersId"
|
||||
"user"."id" = "album_user"."userId"
|
||||
) as obj
|
||||
) as "user"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
"album_user"."albumId" = "album"."id"
|
||||
) as agg
|
||||
) as "albumUsers",
|
||||
(
|
||||
|
|
@ -283,13 +283,13 @@ select
|
|||
from
|
||||
"user"
|
||||
where
|
||||
"user"."id" = "album_user"."usersId"
|
||||
"user"."id" = "album_user"."userId"
|
||||
) as obj
|
||||
) as "user"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
"album_user"."albumId" = "album"."id"
|
||||
) as agg
|
||||
) as "albumUsers",
|
||||
(
|
||||
|
|
@ -332,10 +332,10 @@ where
|
|||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
"album_user"."albumId" = "album"."id"
|
||||
and (
|
||||
"album"."ownerId" = $1
|
||||
or "album_user"."usersId" = $2
|
||||
or "album_user"."userId" = $2
|
||||
)
|
||||
)
|
||||
or exists (
|
||||
|
|
@ -382,7 +382,7 @@ where
|
|||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."albumsId" = "album"."id"
|
||||
"album_user"."albumId" = "album"."id"
|
||||
)
|
||||
and not exists (
|
||||
select
|
||||
|
|
@ -397,7 +397,7 @@ order by
|
|||
-- AlbumRepository.removeAssetsFromAll
|
||||
delete from "album_asset"
|
||||
where
|
||||
"album_asset"."assetsId" in ($1)
|
||||
"album_asset"."assetId" in ($1)
|
||||
|
||||
-- AlbumRepository.getAssetIds
|
||||
select
|
||||
|
|
@ -405,8 +405,8 @@ select
|
|||
from
|
||||
"album_asset"
|
||||
where
|
||||
"album_asset"."albumsId" = $1
|
||||
and "album_asset"."assetsId" in ($2)
|
||||
"album_asset"."albumId" = $1
|
||||
and "album_asset"."assetId" in ($2)
|
||||
|
||||
-- AlbumRepository.getContributorCounts
|
||||
select
|
||||
|
|
@ -414,10 +414,10 @@ select
|
|||
count(*) as "assetCount"
|
||||
from
|
||||
"album_asset"
|
||||
inner join "asset" on "asset"."id" = "assetsId"
|
||||
inner join "asset" on "asset"."id" = "assetId"
|
||||
where
|
||||
"asset"."deletedAt" is null
|
||||
and "album_asset"."albumsId" = $1
|
||||
and "album_asset"."albumId" = $1
|
||||
group by
|
||||
"asset"."ownerId"
|
||||
order by
|
||||
|
|
@ -427,10 +427,10 @@ order by
|
|||
insert into
|
||||
"album_asset"
|
||||
select
|
||||
"album_asset"."albumsId",
|
||||
$1 as "assetsId"
|
||||
"album_asset"."albumId",
|
||||
$1 as "assetId"
|
||||
from
|
||||
"album_asset"
|
||||
where
|
||||
"album_asset"."assetsId" = $2
|
||||
"album_asset"."assetId" = $2
|
||||
on conflict do nothing
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
-- AlbumUserRepository.create
|
||||
insert into
|
||||
"album_user" ("usersId", "albumsId")
|
||||
"album_user" ("userId", "albumId")
|
||||
values
|
||||
($1, $2)
|
||||
returning
|
||||
"usersId",
|
||||
"albumsId",
|
||||
"userId",
|
||||
"albumId",
|
||||
"role"
|
||||
|
||||
-- AlbumUserRepository.update
|
||||
|
|
@ -15,13 +15,13 @@ update "album_user"
|
|||
set
|
||||
"role" = $1
|
||||
where
|
||||
"usersId" = $2
|
||||
and "albumsId" = $3
|
||||
"userId" = $2
|
||||
and "albumId" = $3
|
||||
returning
|
||||
*
|
||||
|
||||
-- AlbumUserRepository.delete
|
||||
delete from "album_user"
|
||||
where
|
||||
"usersId" = $1
|
||||
and "albumsId" = $2
|
||||
"userId" = $1
|
||||
and "albumId" = $2
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ select
|
|||
"tag"."value"
|
||||
from
|
||||
"tag"
|
||||
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId"
|
||||
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagId"
|
||||
where
|
||||
"asset"."id" = "tag_asset"."assetsId"
|
||||
"asset"."id" = "tag_asset"."assetId"
|
||||
) as agg
|
||||
) as "tags"
|
||||
from
|
||||
|
|
|
|||
|
|
@ -160,9 +160,9 @@ select
|
|||
"tag"."parentId"
|
||||
from
|
||||
"tag"
|
||||
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId"
|
||||
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagId"
|
||||
where
|
||||
"asset"."id" = "tag_asset"."assetsId"
|
||||
"asset"."id" = "tag_asset"."assetId"
|
||||
) as agg
|
||||
) as "tags",
|
||||
to_json("asset_exif") as "exifInfo"
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ where
|
|||
from
|
||||
"album_asset"
|
||||
where
|
||||
"asset"."id" = "album_asset"."assetsId"
|
||||
and "album_asset"."albumsId" in ($3)
|
||||
"asset"."id" = "album_asset"."assetId"
|
||||
and "album_asset"."albumId" in ($3)
|
||||
)
|
||||
)
|
||||
order by
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ select
|
|||
"asset".*
|
||||
from
|
||||
"asset"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
||||
where
|
||||
"memory_asset"."memoriesId" = "memory"."id"
|
||||
and "asset"."visibility" = 'timeline'
|
||||
|
|
@ -66,7 +66,7 @@ select
|
|||
"asset".*
|
||||
from
|
||||
"asset"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
||||
where
|
||||
"memory_asset"."memoriesId" = "memory"."id"
|
||||
and "asset"."visibility" = 'timeline'
|
||||
|
|
@ -104,7 +104,7 @@ select
|
|||
"asset".*
|
||||
from
|
||||
"asset"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
||||
where
|
||||
"memory_asset"."memoriesId" = "memory"."id"
|
||||
and "asset"."visibility" = 'timeline'
|
||||
|
|
@ -137,7 +137,7 @@ select
|
|||
"asset".*
|
||||
from
|
||||
"asset"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId"
|
||||
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
|
||||
where
|
||||
"memory_asset"."memoriesId" = "memory"."id"
|
||||
and "asset"."visibility" = 'timeline'
|
||||
|
|
@ -159,15 +159,15 @@ where
|
|||
|
||||
-- MemoryRepository.getAssetIds
|
||||
select
|
||||
"assetsId"
|
||||
"assetId"
|
||||
from
|
||||
"memory_asset"
|
||||
where
|
||||
"memoriesId" = $1
|
||||
and "assetsId" in ($2)
|
||||
and "assetId" in ($2)
|
||||
|
||||
-- MemoryRepository.addAssetIds
|
||||
insert into
|
||||
"memory_asset" ("memoriesId", "assetsId")
|
||||
"memory_asset" ("memoriesId", "assetId")
|
||||
values
|
||||
($1, $2)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
insert into
|
||||
"shared_link_asset"
|
||||
select
|
||||
$1 as "assetsId",
|
||||
"shared_link_asset"."sharedLinksId"
|
||||
$1 as "assetId",
|
||||
"shared_link_asset"."sharedLinkId"
|
||||
from
|
||||
"shared_link_asset"
|
||||
where
|
||||
"shared_link_asset"."assetsId" = $2
|
||||
"shared_link_asset"."assetId" = $2
|
||||
on conflict do nothing
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ from
|
|||
to_json("exifInfo") as "exifInfo"
|
||||
from
|
||||
"shared_link_asset"
|
||||
inner join "asset" on "asset"."id" = "shared_link_asset"."assetsId"
|
||||
inner join "asset" on "asset"."id" = "shared_link_asset"."assetId"
|
||||
inner join lateral (
|
||||
select
|
||||
"asset_exif".*
|
||||
|
|
@ -29,7 +29,7 @@ from
|
|||
"asset_exif"."assetId" = "asset"."id"
|
||||
) as "exifInfo" on true
|
||||
where
|
||||
"shared_link"."id" = "shared_link_asset"."sharedLinksId"
|
||||
"shared_link"."id" = "shared_link_asset"."sharedLinkId"
|
||||
and "asset"."deletedAt" is null
|
||||
order by
|
||||
"asset"."fileCreatedAt" asc
|
||||
|
|
@ -51,7 +51,7 @@ from
|
|||
to_json("owner") as "owner"
|
||||
from
|
||||
"album"
|
||||
left join "album_asset" on "album_asset"."albumsId" = "album"."id"
|
||||
left join "album_asset" on "album_asset"."albumId" = "album"."id"
|
||||
left join lateral (
|
||||
select
|
||||
"asset".*,
|
||||
|
|
@ -67,7 +67,7 @@ from
|
|||
"asset_exif"."assetId" = "asset"."id"
|
||||
) as "exifInfo" on true
|
||||
where
|
||||
"album_asset"."assetsId" = "asset"."id"
|
||||
"album_asset"."assetId" = "asset"."id"
|
||||
and "asset"."deletedAt" is null
|
||||
order by
|
||||
"asset"."fileCreatedAt" asc
|
||||
|
|
@ -108,14 +108,14 @@ select distinct
|
|||
to_json("album") as "album"
|
||||
from
|
||||
"shared_link"
|
||||
left join "shared_link_asset" on "shared_link_asset"."sharedLinksId" = "shared_link"."id"
|
||||
left join "shared_link_asset" on "shared_link_asset"."sharedLinkId" = "shared_link"."id"
|
||||
left join lateral (
|
||||
select
|
||||
json_agg("asset") as "assets"
|
||||
from
|
||||
"asset"
|
||||
where
|
||||
"asset"."id" = "shared_link_asset"."assetsId"
|
||||
"asset"."id" = "shared_link_asset"."assetId"
|
||||
and "asset"."deletedAt" is null
|
||||
) as "assets" on true
|
||||
left join lateral (
|
||||
|
|
|
|||
|
|
@ -89,9 +89,9 @@ select
|
|||
"tag"."parentId"
|
||||
from
|
||||
"tag"
|
||||
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId"
|
||||
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagId"
|
||||
where
|
||||
"tag_asset"."assetsId" = "asset"."id"
|
||||
"tag_asset"."assetId" = "asset"."id"
|
||||
) as agg
|
||||
) as "tags",
|
||||
to_json("exifInfo") as "exifInfo"
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
-- SyncRepository.album.getCreatedAfter
|
||||
select
|
||||
"albumsId" as "id",
|
||||
"albumId" as "id",
|
||||
"createId"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"usersId" = $1
|
||||
"userId" = $1
|
||||
and "createId" >= $2
|
||||
and "createId" < $3
|
||||
order by
|
||||
|
|
@ -40,13 +40,13 @@ select distinct
|
|||
"album"."updateId"
|
||||
from
|
||||
"album" as "album"
|
||||
left join "album_user" as "album_users" on "album"."id" = "album_users"."albumsId"
|
||||
left join "album_user" as "album_users" on "album"."id" = "album_users"."albumId"
|
||||
where
|
||||
"album"."updateId" < $1
|
||||
and "album"."updateId" > $2
|
||||
and (
|
||||
"album"."ownerId" = $3
|
||||
or "album_users"."usersId" = $4
|
||||
or "album_users"."userId" = $4
|
||||
)
|
||||
order by
|
||||
"album"."updateId" asc
|
||||
|
|
@ -72,12 +72,12 @@ select
|
|||
"album_asset"."updateId"
|
||||
from
|
||||
"album_asset" as "album_asset"
|
||||
inner join "asset" on "asset"."id" = "album_asset"."assetsId"
|
||||
inner join "asset" on "asset"."id" = "album_asset"."assetId"
|
||||
where
|
||||
"album_asset"."updateId" < $1
|
||||
and "album_asset"."updateId" <= $2
|
||||
and "album_asset"."updateId" >= $3
|
||||
and "album_asset"."albumsId" = $4
|
||||
and "album_asset"."albumId" = $4
|
||||
order by
|
||||
"album_asset"."updateId" asc
|
||||
|
||||
|
|
@ -102,16 +102,16 @@ select
|
|||
"asset"."updateId"
|
||||
from
|
||||
"asset" as "asset"
|
||||
inner join "album_asset" on "album_asset"."assetsId" = "asset"."id"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumsId"
|
||||
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId"
|
||||
inner join "album_asset" on "album_asset"."assetId" = "asset"."id"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumId"
|
||||
left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
|
||||
where
|
||||
"asset"."updateId" < $1
|
||||
and "asset"."updateId" > $2
|
||||
and "album_asset"."updateId" <= $3
|
||||
and (
|
||||
"album"."ownerId" = $4
|
||||
or "album_user"."usersId" = $5
|
||||
or "album_user"."userId" = $5
|
||||
)
|
||||
order by
|
||||
"asset"."updateId" asc
|
||||
|
|
@ -137,15 +137,15 @@ select
|
|||
"asset"."libraryId"
|
||||
from
|
||||
"album_asset" as "album_asset"
|
||||
inner join "asset" on "asset"."id" = "album_asset"."assetsId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumsId"
|
||||
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId"
|
||||
inner join "asset" on "asset"."id" = "album_asset"."assetId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumId"
|
||||
left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
|
||||
where
|
||||
"album_asset"."updateId" < $1
|
||||
and "album_asset"."updateId" > $2
|
||||
and (
|
||||
"album"."ownerId" = $3
|
||||
or "album_user"."usersId" = $4
|
||||
or "album_user"."userId" = $4
|
||||
)
|
||||
order by
|
||||
"album_asset"."updateId" asc
|
||||
|
|
@ -180,12 +180,12 @@ select
|
|||
"album_asset"."updateId"
|
||||
from
|
||||
"album_asset" as "album_asset"
|
||||
inner join "asset_exif" on "asset_exif"."assetId" = "album_asset"."assetsId"
|
||||
inner join "asset_exif" on "asset_exif"."assetId" = "album_asset"."assetId"
|
||||
where
|
||||
"album_asset"."updateId" < $1
|
||||
and "album_asset"."updateId" <= $2
|
||||
and "album_asset"."updateId" >= $3
|
||||
and "album_asset"."albumsId" = $4
|
||||
and "album_asset"."albumId" = $4
|
||||
order by
|
||||
"album_asset"."updateId" asc
|
||||
|
||||
|
|
@ -219,16 +219,16 @@ select
|
|||
"asset_exif"."updateId"
|
||||
from
|
||||
"asset_exif" as "asset_exif"
|
||||
inner join "album_asset" on "album_asset"."assetsId" = "asset_exif"."assetId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumsId"
|
||||
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId"
|
||||
inner join "album_asset" on "album_asset"."assetId" = "asset_exif"."assetId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumId"
|
||||
left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
|
||||
where
|
||||
"asset_exif"."updateId" < $1
|
||||
and "asset_exif"."updateId" > $2
|
||||
and "album_asset"."updateId" <= $3
|
||||
and (
|
||||
"album"."ownerId" = $4
|
||||
or "album_user"."usersId" = $5
|
||||
or "album_user"."userId" = $5
|
||||
)
|
||||
order by
|
||||
"asset_exif"."updateId" asc
|
||||
|
|
@ -263,23 +263,23 @@ select
|
|||
"asset_exif"."fps"
|
||||
from
|
||||
"album_asset" as "album_asset"
|
||||
inner join "asset_exif" on "asset_exif"."assetId" = "album_asset"."assetsId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumsId"
|
||||
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId"
|
||||
inner join "asset_exif" on "asset_exif"."assetId" = "album_asset"."assetId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumId"
|
||||
left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
|
||||
where
|
||||
"album_asset"."updateId" < $1
|
||||
and "album_asset"."updateId" > $2
|
||||
and (
|
||||
"album"."ownerId" = $3
|
||||
or "album_user"."usersId" = $4
|
||||
or "album_user"."userId" = $4
|
||||
)
|
||||
order by
|
||||
"album_asset"."updateId" asc
|
||||
|
||||
-- SyncRepository.albumToAsset.getBackfill
|
||||
select
|
||||
"album_asset"."assetsId" as "assetId",
|
||||
"album_asset"."albumsId" as "albumId",
|
||||
"album_asset"."assetId" as "assetId",
|
||||
"album_asset"."albumId" as "albumId",
|
||||
"album_asset"."updateId"
|
||||
from
|
||||
"album_asset" as "album_asset"
|
||||
|
|
@ -287,7 +287,7 @@ where
|
|||
"album_asset"."updateId" < $1
|
||||
and "album_asset"."updateId" <= $2
|
||||
and "album_asset"."updateId" >= $3
|
||||
and "album_asset"."albumsId" = $4
|
||||
and "album_asset"."albumId" = $4
|
||||
order by
|
||||
"album_asset"."updateId" asc
|
||||
|
||||
|
|
@ -311,11 +311,11 @@ where
|
|||
union
|
||||
(
|
||||
select
|
||||
"album_user"."albumsId" as "id"
|
||||
"album_user"."albumId" as "id"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."usersId" = $4
|
||||
"album_user"."userId" = $4
|
||||
)
|
||||
)
|
||||
order by
|
||||
|
|
@ -323,27 +323,27 @@ order by
|
|||
|
||||
-- SyncRepository.albumToAsset.getUpserts
|
||||
select
|
||||
"album_asset"."assetsId" as "assetId",
|
||||
"album_asset"."albumsId" as "albumId",
|
||||
"album_asset"."assetId" as "assetId",
|
||||
"album_asset"."albumId" as "albumId",
|
||||
"album_asset"."updateId"
|
||||
from
|
||||
"album_asset" as "album_asset"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumsId"
|
||||
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId"
|
||||
inner join "album" on "album"."id" = "album_asset"."albumId"
|
||||
left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
|
||||
where
|
||||
"album_asset"."updateId" < $1
|
||||
and "album_asset"."updateId" > $2
|
||||
and (
|
||||
"album"."ownerId" = $3
|
||||
or "album_user"."usersId" = $4
|
||||
or "album_user"."userId" = $4
|
||||
)
|
||||
order by
|
||||
"album_asset"."updateId" asc
|
||||
|
||||
-- SyncRepository.albumUser.getBackfill
|
||||
select
|
||||
"album_user"."albumsId" as "albumId",
|
||||
"album_user"."usersId" as "userId",
|
||||
"album_user"."albumId" as "albumId",
|
||||
"album_user"."userId" as "userId",
|
||||
"album_user"."role",
|
||||
"album_user"."updateId"
|
||||
from
|
||||
|
|
@ -352,7 +352,7 @@ where
|
|||
"album_user"."updateId" < $1
|
||||
and "album_user"."updateId" <= $2
|
||||
and "album_user"."updateId" >= $3
|
||||
and "albumsId" = $4
|
||||
and "albumId" = $4
|
||||
order by
|
||||
"album_user"."updateId" asc
|
||||
|
||||
|
|
@ -376,11 +376,11 @@ where
|
|||
union
|
||||
(
|
||||
select
|
||||
"album_user"."albumsId" as "id"
|
||||
"album_user"."albumId" as "id"
|
||||
from
|
||||
"album_user"
|
||||
where
|
||||
"album_user"."usersId" = $4
|
||||
"album_user"."userId" = $4
|
||||
)
|
||||
)
|
||||
order by
|
||||
|
|
@ -388,8 +388,8 @@ order by
|
|||
|
||||
-- SyncRepository.albumUser.getUpserts
|
||||
select
|
||||
"album_user"."albumsId" as "albumId",
|
||||
"album_user"."usersId" as "userId",
|
||||
"album_user"."albumId" as "albumId",
|
||||
"album_user"."userId" as "userId",
|
||||
"album_user"."role",
|
||||
"album_user"."updateId"
|
||||
from
|
||||
|
|
@ -397,7 +397,7 @@ from
|
|||
where
|
||||
"album_user"."updateId" < $1
|
||||
and "album_user"."updateId" > $2
|
||||
and "album_user"."albumsId" in (
|
||||
and "album_user"."albumId" in (
|
||||
select
|
||||
"id"
|
||||
from
|
||||
|
|
@ -407,11 +407,11 @@ where
|
|||
union
|
||||
(
|
||||
select
|
||||
"albumUsers"."albumsId" as "id"
|
||||
"albumUsers"."albumId" as "id"
|
||||
from
|
||||
"album_user" as "albumUsers"
|
||||
where
|
||||
"albumUsers"."usersId" = $4
|
||||
"albumUsers"."userId" = $4
|
||||
)
|
||||
)
|
||||
order by
|
||||
|
|
@ -656,7 +656,7 @@ order by
|
|||
-- SyncRepository.memoryToAsset.getUpserts
|
||||
select
|
||||
"memoriesId" as "memoryId",
|
||||
"assetsId" as "assetId",
|
||||
"assetId" as "assetId",
|
||||
"updateId"
|
||||
from
|
||||
"memory_asset" as "memory_asset"
|
||||
|
|
|
|||
|
|
@ -84,15 +84,15 @@ where
|
|||
|
||||
-- TagRepository.addAssetIds
|
||||
insert into
|
||||
"tag_asset" ("tagsId", "assetsId")
|
||||
"tag_asset" ("tagId", "assetId")
|
||||
values
|
||||
($1, $2)
|
||||
|
||||
-- TagRepository.removeAssetIds
|
||||
delete from "tag_asset"
|
||||
where
|
||||
"tagsId" = $1
|
||||
and "assetsId" in ($2)
|
||||
"tagId" = $1
|
||||
and "assetId" in ($2)
|
||||
|
||||
-- TagRepository.upsertAssetIds
|
||||
insert into
|
||||
|
|
@ -107,9 +107,9 @@ returning
|
|||
begin
|
||||
delete from "tag_asset"
|
||||
where
|
||||
"assetsId" = $1
|
||||
"assetId" = $1
|
||||
insert into
|
||||
"tag_asset" ("tagsId", "assetsId")
|
||||
"tag_asset" ("tagId", "assetId")
|
||||
values
|
||||
($1, $2)
|
||||
on conflict do nothing
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ class ActivityAccess {
|
|||
return this.db
|
||||
.selectFrom('album')
|
||||
.select('album.id')
|
||||
.leftJoin('album_user as albumUsers', 'albumUsers.albumsId', 'album.id')
|
||||
.leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.usersId').on('user.deletedAt', 'is', null))
|
||||
.leftJoin('album_user as albumUsers', 'albumUsers.albumId', 'album.id')
|
||||
.leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.userId').on('user.deletedAt', 'is', null))
|
||||
.where('album.id', 'in', [...albumIds])
|
||||
.where('album.isActivityEnabled', '=', true)
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('user.id', '=', userId)]))
|
||||
|
|
@ -96,8 +96,8 @@ class AlbumAccess {
|
|||
return this.db
|
||||
.selectFrom('album')
|
||||
.select('album.id')
|
||||
.leftJoin('album_user', 'album_user.albumsId', 'album.id')
|
||||
.leftJoin('user', (join) => join.onRef('user.id', '=', 'album_user.usersId').on('user.deletedAt', 'is', null))
|
||||
.leftJoin('album_user', 'album_user.albumId', 'album.id')
|
||||
.leftJoin('user', (join) => join.onRef('user.id', '=', 'album_user.userId').on('user.deletedAt', 'is', null))
|
||||
.where('album.id', 'in', [...albumIds])
|
||||
.where('album.deletedAt', 'is', null)
|
||||
.where('user.id', '=', userId)
|
||||
|
|
@ -138,12 +138,12 @@ class AssetAccess {
|
|||
return this.db
|
||||
.with('target', (qb) => qb.selectNoFrom(sql`array[${sql.join([...assetIds])}]::uuid[]`.as('ids')))
|
||||
.selectFrom('album')
|
||||
.innerJoin('album_asset as albumAssets', 'album.id', 'albumAssets.albumsId')
|
||||
.innerJoin('album_asset as albumAssets', 'album.id', 'albumAssets.albumId')
|
||||
.innerJoin('asset', (join) =>
|
||||
join.onRef('asset.id', '=', 'albumAssets.assetsId').on('asset.deletedAt', 'is', null),
|
||||
join.onRef('asset.id', '=', 'albumAssets.assetId').on('asset.deletedAt', 'is', null),
|
||||
)
|
||||
.leftJoin('album_user as albumUsers', 'albumUsers.albumsId', 'album.id')
|
||||
.leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.usersId').on('user.deletedAt', 'is', null))
|
||||
.leftJoin('album_user as albumUsers', 'albumUsers.albumId', 'album.id')
|
||||
.leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.userId').on('user.deletedAt', 'is', null))
|
||||
.crossJoin('target')
|
||||
.select(['asset.id', 'asset.livePhotoVideoId'])
|
||||
.where((eb) =>
|
||||
|
|
@ -223,13 +223,13 @@ class AssetAccess {
|
|||
return this.db
|
||||
.selectFrom('shared_link')
|
||||
.leftJoin('album', (join) => join.onRef('album.id', '=', 'shared_link.albumId').on('album.deletedAt', 'is', null))
|
||||
.leftJoin('shared_link_asset', 'shared_link_asset.sharedLinksId', 'shared_link.id')
|
||||
.leftJoin('shared_link_asset', 'shared_link_asset.sharedLinkId', 'shared_link.id')
|
||||
.leftJoin('asset', (join) =>
|
||||
join.onRef('asset.id', '=', 'shared_link_asset.assetsId').on('asset.deletedAt', 'is', null),
|
||||
join.onRef('asset.id', '=', 'shared_link_asset.assetId').on('asset.deletedAt', 'is', null),
|
||||
)
|
||||
.leftJoin('album_asset', 'album_asset.albumsId', 'album.id')
|
||||
.leftJoin('album_asset', 'album_asset.albumId', 'album.id')
|
||||
.leftJoin('asset as albumAssets', (join) =>
|
||||
join.onRef('albumAssets.id', '=', 'album_asset.assetsId').on('albumAssets.deletedAt', 'is', null),
|
||||
join.onRef('albumAssets.id', '=', 'album_asset.assetId').on('albumAssets.deletedAt', 'is', null),
|
||||
)
|
||||
.select([
|
||||
'asset.id as assetId',
|
||||
|
|
|
|||
|
|
@ -7,36 +7,36 @@ import { DB } from 'src/schema';
|
|||
import { AlbumUserTable } from 'src/schema/tables/album-user.table';
|
||||
|
||||
export type AlbumPermissionId = {
|
||||
albumsId: string;
|
||||
usersId: string;
|
||||
albumId: string;
|
||||
userId: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class AlbumUserRepository {
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
@GenerateSql({ params: [{ usersId: DummyValue.UUID, albumsId: DummyValue.UUID }] })
|
||||
@GenerateSql({ params: [{ userId: DummyValue.UUID, albumId: DummyValue.UUID }] })
|
||||
create(albumUser: Insertable<AlbumUserTable>) {
|
||||
return this.db
|
||||
.insertInto('album_user')
|
||||
.values(albumUser)
|
||||
.returning(['usersId', 'albumsId', 'role'])
|
||||
.returning(['userId', 'albumId', 'role'])
|
||||
.executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ usersId: DummyValue.UUID, albumsId: DummyValue.UUID }, { role: AlbumUserRole.Viewer }] })
|
||||
update({ usersId, albumsId }: AlbumPermissionId, dto: Updateable<AlbumUserTable>) {
|
||||
@GenerateSql({ params: [{ userId: DummyValue.UUID, albumId: DummyValue.UUID }, { role: AlbumUserRole.Viewer }] })
|
||||
update({ userId, albumId }: AlbumPermissionId, dto: Updateable<AlbumUserTable>) {
|
||||
return this.db
|
||||
.updateTable('album_user')
|
||||
.set(dto)
|
||||
.where('usersId', '=', usersId)
|
||||
.where('albumsId', '=', albumsId)
|
||||
.where('userId', '=', userId)
|
||||
.where('albumId', '=', albumId)
|
||||
.returningAll()
|
||||
.executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ usersId: DummyValue.UUID, albumsId: DummyValue.UUID }] })
|
||||
async delete({ usersId, albumsId }: AlbumPermissionId): Promise<void> {
|
||||
await this.db.deleteFrom('album_user').where('usersId', '=', usersId).where('albumsId', '=', albumsId).execute();
|
||||
@GenerateSql({ params: [{ userId: DummyValue.UUID, albumId: DummyValue.UUID }] })
|
||||
async delete({ userId, albumId }: AlbumPermissionId): Promise<void> {
|
||||
await this.db.deleteFrom('album_user').where('userId', '=', userId).where('albumId', '=', albumId).execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ const withAlbumUsers = (eb: ExpressionBuilder<DB, 'album'>) => {
|
|||
.selectFrom('album_user')
|
||||
.select('album_user.role')
|
||||
.select((eb) =>
|
||||
jsonObjectFrom(eb.selectFrom('user').select(columns.user).whereRef('user.id', '=', 'album_user.usersId'))
|
||||
jsonObjectFrom(eb.selectFrom('user').select(columns.user).whereRef('user.id', '=', 'album_user.userId'))
|
||||
.$notNull()
|
||||
.as('user'),
|
||||
)
|
||||
.whereRef('album_user.albumsId', '=', 'album.id'),
|
||||
.whereRef('album_user.albumId', '=', 'album.id'),
|
||||
)
|
||||
.$notNull()
|
||||
.as('albumUsers');
|
||||
|
|
@ -57,8 +57,8 @@ const withAssets = (eb: ExpressionBuilder<DB, 'album'>) => {
|
|||
.selectAll('asset')
|
||||
.leftJoin('asset_exif', 'asset.id', 'asset_exif.assetId')
|
||||
.select((eb) => eb.table('asset_exif').$castTo<Exif>().as('exifInfo'))
|
||||
.innerJoin('album_asset', 'album_asset.assetsId', 'asset.id')
|
||||
.whereRef('album_asset.albumsId', '=', 'album.id')
|
||||
.innerJoin('album_asset', 'album_asset.assetId', 'asset.id')
|
||||
.whereRef('album_asset.albumId', '=', 'album.id')
|
||||
.where('asset.deletedAt', 'is', null)
|
||||
.$call(withDefaultVisibility)
|
||||
.orderBy('asset.fileCreatedAt', 'desc')
|
||||
|
|
@ -92,19 +92,19 @@ export class AlbumRepository {
|
|||
return this.db
|
||||
.selectFrom('album')
|
||||
.selectAll('album')
|
||||
.innerJoin('album_asset', 'album_asset.albumsId', 'album.id')
|
||||
.innerJoin('album_asset', 'album_asset.albumId', 'album.id')
|
||||
.where((eb) =>
|
||||
eb.or([
|
||||
eb('album.ownerId', '=', ownerId),
|
||||
eb.exists(
|
||||
eb
|
||||
.selectFrom('album_user')
|
||||
.whereRef('album_user.albumsId', '=', 'album.id')
|
||||
.where('album_user.usersId', '=', ownerId),
|
||||
.whereRef('album_user.albumId', '=', 'album.id')
|
||||
.where('album_user.userId', '=', ownerId),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.where('album_asset.assetsId', '=', assetId)
|
||||
.where('album_asset.assetId', '=', assetId)
|
||||
.where('album.deletedAt', 'is', null)
|
||||
.orderBy('album.createdAt', 'desc')
|
||||
.select(withOwner)
|
||||
|
|
@ -125,16 +125,16 @@ export class AlbumRepository {
|
|||
this.db
|
||||
.selectFrom('asset')
|
||||
.$call(withDefaultVisibility)
|
||||
.innerJoin('album_asset', 'album_asset.assetsId', 'asset.id')
|
||||
.select('album_asset.albumsId as albumId')
|
||||
.innerJoin('album_asset', 'album_asset.assetId', 'asset.id')
|
||||
.select('album_asset.albumId as albumId')
|
||||
.select((eb) => eb.fn.min(sql<Date>`("asset"."localDateTime" AT TIME ZONE 'UTC'::text)::date`).as('startDate'))
|
||||
.select((eb) => eb.fn.max(sql<Date>`("asset"."localDateTime" AT TIME ZONE 'UTC'::text)::date`).as('endDate'))
|
||||
// lastModifiedAssetTimestamp is only used in mobile app, please remove if not need
|
||||
.select((eb) => eb.fn.max('asset.updatedAt').as('lastModifiedAssetTimestamp'))
|
||||
.select((eb) => sql<number>`${eb.fn.count('asset.id')}::int`.as('assetCount'))
|
||||
.where('album_asset.albumsId', 'in', ids)
|
||||
.where('album_asset.albumId', 'in', ids)
|
||||
.where('asset.deletedAt', 'is', null)
|
||||
.groupBy('album_asset.albumsId')
|
||||
.groupBy('album_asset.albumId')
|
||||
.execute()
|
||||
);
|
||||
}
|
||||
|
|
@ -166,8 +166,8 @@ export class AlbumRepository {
|
|||
eb.exists(
|
||||
eb
|
||||
.selectFrom('album_user')
|
||||
.whereRef('album_user.albumsId', '=', 'album.id')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', ownerId), eb('album_user.usersId', '=', ownerId)])),
|
||||
.whereRef('album_user.albumId', '=', 'album.id')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', ownerId), eb('album_user.userId', '=', ownerId)])),
|
||||
),
|
||||
eb.exists(
|
||||
eb
|
||||
|
|
@ -195,7 +195,7 @@ export class AlbumRepository {
|
|||
.selectAll('album')
|
||||
.where('album.ownerId', '=', ownerId)
|
||||
.where('album.deletedAt', 'is', null)
|
||||
.where((eb) => eb.not(eb.exists(eb.selectFrom('album_user').whereRef('album_user.albumsId', '=', 'album.id'))))
|
||||
.where((eb) => eb.not(eb.exists(eb.selectFrom('album_user').whereRef('album_user.albumId', '=', 'album.id'))))
|
||||
.where((eb) => eb.not(eb.exists(eb.selectFrom('shared_link').whereRef('shared_link.albumId', '=', 'album.id'))))
|
||||
.select(withOwner)
|
||||
.orderBy('album.createdAt', 'desc')
|
||||
|
|
@ -217,7 +217,7 @@ export class AlbumRepository {
|
|||
@GenerateSql({ params: [[DummyValue.UUID]] })
|
||||
@Chunked()
|
||||
async removeAssetsFromAll(assetIds: string[]): Promise<void> {
|
||||
await this.db.deleteFrom('album_asset').where('album_asset.assetsId', 'in', assetIds).execute();
|
||||
await this.db.deleteFrom('album_asset').where('album_asset.assetId', 'in', assetIds).execute();
|
||||
}
|
||||
|
||||
@Chunked({ paramIndex: 1 })
|
||||
|
|
@ -228,8 +228,8 @@ export class AlbumRepository {
|
|||
|
||||
await this.db
|
||||
.deleteFrom('album_asset')
|
||||
.where('album_asset.albumsId', '=', albumId)
|
||||
.where('album_asset.assetsId', 'in', assetIds)
|
||||
.where('album_asset.albumId', '=', albumId)
|
||||
.where('album_asset.assetId', 'in', assetIds)
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
@ -250,10 +250,10 @@ export class AlbumRepository {
|
|||
return this.db
|
||||
.selectFrom('album_asset')
|
||||
.selectAll()
|
||||
.where('album_asset.albumsId', '=', albumId)
|
||||
.where('album_asset.assetsId', 'in', assetIds)
|
||||
.where('album_asset.albumId', '=', albumId)
|
||||
.where('album_asset.assetId', 'in', assetIds)
|
||||
.execute()
|
||||
.then((results) => new Set(results.map(({ assetsId }) => assetsId)));
|
||||
.then((results) => new Set(results.map(({ assetId }) => assetId)));
|
||||
}
|
||||
|
||||
async addAssetIds(albumId: string, assetIds: string[]): Promise<void> {
|
||||
|
|
@ -276,7 +276,7 @@ export class AlbumRepository {
|
|||
await tx
|
||||
.insertInto('album_user')
|
||||
.values(
|
||||
albumUsers.map((albumUser) => ({ albumsId: newAlbum.id, usersId: albumUser.userId, role: albumUser.role })),
|
||||
albumUsers.map((albumUser) => ({ albumId: newAlbum.id, userId: albumUser.userId, role: albumUser.role })),
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
|
@ -317,12 +317,12 @@ export class AlbumRepository {
|
|||
|
||||
await db
|
||||
.insertInto('album_asset')
|
||||
.values(assetIds.map((assetId) => ({ albumsId: albumId, assetsId: assetId })))
|
||||
.values(assetIds.map((assetId) => ({ albumId, assetId })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Chunked({ chunkSize: 30_000 })
|
||||
async addAssetIdsToAlbums(values: { albumsId: string; assetsId: string }[]): Promise<void> {
|
||||
async addAssetIdsToAlbums(values: { albumId: string; assetId: string }[]): Promise<void> {
|
||||
if (values.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -344,7 +344,7 @@ export class AlbumRepository {
|
|||
.updateTable('album')
|
||||
.set((eb) => ({
|
||||
albumThumbnailAssetId: this.updateThumbnailBuilder(eb)
|
||||
.select('album_asset.assetsId')
|
||||
.select('album_asset.assetId')
|
||||
.orderBy('asset.fileCreatedAt', 'desc')
|
||||
.limit(1),
|
||||
}))
|
||||
|
|
@ -360,7 +360,7 @@ export class AlbumRepository {
|
|||
eb.exists(
|
||||
this.updateThumbnailBuilder(eb)
|
||||
.select(sql`1`.as('1'))
|
||||
.whereRef('album.albumThumbnailAssetId', '=', 'album_asset.assetsId'), // Has invalid assets
|
||||
.whereRef('album.albumThumbnailAssetId', '=', 'album_asset.assetId'), // Has invalid assets
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
|
@ -375,9 +375,9 @@ export class AlbumRepository {
|
|||
return eb
|
||||
.selectFrom('album_asset')
|
||||
.innerJoin('asset', (join) =>
|
||||
join.onRef('album_asset.assetsId', '=', 'asset.id').on('asset.deletedAt', 'is', null),
|
||||
join.onRef('album_asset.assetId', '=', 'asset.id').on('asset.deletedAt', 'is', null),
|
||||
)
|
||||
.whereRef('album_asset.albumsId', '=', 'album.id');
|
||||
.whereRef('album_asset.albumId', '=', 'album.id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -388,9 +388,9 @@ export class AlbumRepository {
|
|||
getContributorCounts(id: string) {
|
||||
return this.db
|
||||
.selectFrom('album_asset')
|
||||
.innerJoin('asset', 'asset.id', 'assetsId')
|
||||
.innerJoin('asset', 'asset.id', 'assetId')
|
||||
.where('asset.deletedAt', 'is', sql.lit(null))
|
||||
.where('album_asset.albumsId', '=', id)
|
||||
.where('album_asset.albumId', '=', id)
|
||||
.select('asset.ownerId as userId')
|
||||
.select((eb) => eb.fn.countAll<number>().as('assetCount'))
|
||||
.groupBy('asset.ownerId')
|
||||
|
|
@ -405,8 +405,8 @@ export class AlbumRepository {
|
|||
.expression((eb) =>
|
||||
eb
|
||||
.selectFrom('album_asset')
|
||||
.select((eb) => ['album_asset.albumsId', eb.val(targetAssetId).as('assetsId')])
|
||||
.where('album_asset.assetsId', '=', sourceAssetId),
|
||||
.select((eb) => ['album_asset.albumId', eb.val(targetAssetId).as('assetId')])
|
||||
.where('album_asset.assetId', '=', sourceAssetId),
|
||||
)
|
||||
.onConflict((oc) => oc.doNothing())
|
||||
.execute();
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ export class AssetJobRepository {
|
|||
eb
|
||||
.selectFrom('tag')
|
||||
.select(['tag.value'])
|
||||
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagsId')
|
||||
.whereRef('asset.id', '=', 'tag_asset.assetsId'),
|
||||
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagId')
|
||||
.whereRef('asset.id', '=', 'tag_asset.assetId'),
|
||||
).as('tags'),
|
||||
)
|
||||
.limit(1)
|
||||
|
|
|
|||
|
|
@ -563,8 +563,8 @@ export class AssetRepository {
|
|||
.$if(!!options.visibility, (qb) => qb.where('asset.visibility', '=', options.visibility!))
|
||||
.$if(!!options.albumId, (qb) =>
|
||||
qb
|
||||
.innerJoin('album_asset', 'asset.id', 'album_asset.assetsId')
|
||||
.where('album_asset.albumsId', '=', asUuid(options.albumId!)),
|
||||
.innerJoin('album_asset', 'asset.id', 'album_asset.assetId')
|
||||
.where('album_asset.albumId', '=', asUuid(options.albumId!)),
|
||||
)
|
||||
.$if(!!options.personId, (qb) => hasPeople(qb, [options.personId!]))
|
||||
.$if(!!options.withStacked, (qb) =>
|
||||
|
|
@ -641,8 +641,8 @@ export class AssetRepository {
|
|||
eb.exists(
|
||||
eb
|
||||
.selectFrom('album_asset')
|
||||
.whereRef('album_asset.assetsId', '=', 'asset.id')
|
||||
.where('album_asset.albumsId', '=', asUuid(options.albumId!)),
|
||||
.whereRef('album_asset.assetId', '=', 'asset.id')
|
||||
.where('album_asset.albumId', '=', asUuid(options.albumId!)),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ export class DownloadRepository {
|
|||
|
||||
downloadAlbumId(albumId: string) {
|
||||
return builder(this.db)
|
||||
.innerJoin('album_asset', 'asset.id', 'album_asset.assetsId')
|
||||
.where('album_asset.albumsId', '=', albumId)
|
||||
.innerJoin('album_asset', 'asset.id', 'album_asset.assetId')
|
||||
.where('album_asset.albumId', '=', albumId)
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ export class MapRepository {
|
|||
eb.exists((eb) =>
|
||||
eb
|
||||
.selectFrom('album_asset')
|
||||
.whereRef('asset.id', '=', 'album_asset.assetsId')
|
||||
.where('album_asset.albumsId', 'in', albumIds),
|
||||
.whereRef('asset.id', '=', 'album_asset.assetId')
|
||||
.where('album_asset.albumId', 'in', albumIds),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export class MemoryRepository implements IBulkAsset {
|
|||
await this.db
|
||||
.deleteFrom('memory_asset')
|
||||
.using('asset')
|
||||
.whereRef('memory_asset.assetsId', '=', 'asset.id')
|
||||
.whereRef('memory_asset.assetId', '=', 'asset.id')
|
||||
.where('asset.visibility', '!=', AssetVisibility.Timeline)
|
||||
.execute();
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ export class MemoryRepository implements IBulkAsset {
|
|||
eb
|
||||
.selectFrom('asset')
|
||||
.selectAll('asset')
|
||||
.innerJoin('memory_asset', 'asset.id', 'memory_asset.assetsId')
|
||||
.innerJoin('memory_asset', 'asset.id', 'memory_asset.assetId')
|
||||
.whereRef('memory_asset.memoriesId', '=', 'memory.id')
|
||||
.orderBy('asset.fileCreatedAt', 'asc')
|
||||
.where('asset.visibility', '=', sql.lit(AssetVisibility.Timeline))
|
||||
|
|
@ -86,7 +86,7 @@ export class MemoryRepository implements IBulkAsset {
|
|||
const { id } = await tx.insertInto('memory').values(memory).returning('id').executeTakeFirstOrThrow();
|
||||
|
||||
if (assetIds.size > 0) {
|
||||
const values = [...assetIds].map((assetId) => ({ memoriesId: id, assetsId: assetId }));
|
||||
const values = [...assetIds].map((assetId) => ({ memoriesId: id, assetId }));
|
||||
await tx.insertInto('memory_asset').values(values).execute();
|
||||
}
|
||||
|
||||
|
|
@ -116,12 +116,12 @@ export class MemoryRepository implements IBulkAsset {
|
|||
|
||||
const results = await this.db
|
||||
.selectFrom('memory_asset')
|
||||
.select(['assetsId'])
|
||||
.select(['assetId'])
|
||||
.where('memoriesId', '=', id)
|
||||
.where('assetsId', 'in', assetIds)
|
||||
.where('assetId', 'in', assetIds)
|
||||
.execute();
|
||||
|
||||
return new Set(results.map(({ assetsId }) => assetsId));
|
||||
return new Set(results.map(({ assetId }) => assetId));
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
|
||||
|
|
@ -132,7 +132,7 @@ export class MemoryRepository implements IBulkAsset {
|
|||
|
||||
await this.db
|
||||
.insertInto('memory_asset')
|
||||
.values(assetIds.map((assetId) => ({ memoriesId: id, assetsId: assetId })))
|
||||
.values(assetIds.map((assetId) => ({ memoriesId: id, assetId })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ export class MemoryRepository implements IBulkAsset {
|
|||
return;
|
||||
}
|
||||
|
||||
await this.db.deleteFrom('memory_asset').where('memoriesId', '=', id).where('assetsId', 'in', assetIds).execute();
|
||||
await this.db.deleteFrom('memory_asset').where('memoriesId', '=', id).where('assetId', 'in', assetIds).execute();
|
||||
}
|
||||
|
||||
private getByIdBuilder(id: string) {
|
||||
|
|
@ -155,7 +155,7 @@ export class MemoryRepository implements IBulkAsset {
|
|||
eb
|
||||
.selectFrom('asset')
|
||||
.selectAll('asset')
|
||||
.innerJoin('memory_asset', 'asset.id', 'memory_asset.assetsId')
|
||||
.innerJoin('memory_asset', 'asset.id', 'memory_asset.assetId')
|
||||
.whereRef('memory_asset.memoriesId', '=', 'memory.id')
|
||||
.orderBy('asset.fileCreatedAt', 'asc')
|
||||
.where('asset.visibility', '=', sql.lit(AssetVisibility.Timeline))
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ import { DB } from 'src/schema';
|
|||
export class SharedLinkAssetRepository {
|
||||
constructor(@InjectKysely() private db: Kysely<DB>) {}
|
||||
|
||||
async remove(sharedLinkId: string, assetsId: string[]) {
|
||||
async remove(sharedLinkId: string, assetId: string[]) {
|
||||
const deleted = await this.db
|
||||
.deleteFrom('shared_link_asset')
|
||||
.where('shared_link_asset.sharedLinksId', '=', sharedLinkId)
|
||||
.where('shared_link_asset.assetsId', 'in', assetsId)
|
||||
.returning('assetsId')
|
||||
.where('shared_link_asset.sharedLinkId', '=', sharedLinkId)
|
||||
.where('shared_link_asset.assetId', 'in', assetId)
|
||||
.returning('assetId')
|
||||
.execute();
|
||||
|
||||
return deleted.map((row) => row.assetsId);
|
||||
return deleted.map((row) => row.assetId);
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [{ sourceAssetId: DummyValue.UUID, targetAssetId: DummyValue.UUID }] })
|
||||
|
|
@ -24,8 +24,8 @@ export class SharedLinkAssetRepository {
|
|||
.expression((eb) =>
|
||||
eb
|
||||
.selectFrom('shared_link_asset')
|
||||
.select((eb) => [eb.val(targetAssetId).as('assetsId'), 'shared_link_asset.sharedLinksId'])
|
||||
.where('shared_link_asset.assetsId', '=', sourceAssetId),
|
||||
.select((eb) => [eb.val(targetAssetId).as('assetId'), 'shared_link_asset.sharedLinkId'])
|
||||
.where('shared_link_asset.assetId', '=', sourceAssetId),
|
||||
)
|
||||
.onConflict((oc) => oc.doNothing())
|
||||
.execute();
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ export class SharedLinkRepository {
|
|||
(eb) =>
|
||||
eb
|
||||
.selectFrom('shared_link_asset')
|
||||
.whereRef('shared_link.id', '=', 'shared_link_asset.sharedLinksId')
|
||||
.innerJoin('asset', 'asset.id', 'shared_link_asset.assetsId')
|
||||
.whereRef('shared_link.id', '=', 'shared_link_asset.sharedLinkId')
|
||||
.innerJoin('asset', 'asset.id', 'shared_link_asset.assetId')
|
||||
.where('asset.deletedAt', 'is', null)
|
||||
.selectAll('asset')
|
||||
.innerJoinLateral(
|
||||
|
|
@ -53,13 +53,13 @@ export class SharedLinkRepository {
|
|||
.selectAll('album')
|
||||
.whereRef('album.id', '=', 'shared_link.albumId')
|
||||
.where('album.deletedAt', 'is', null)
|
||||
.leftJoin('album_asset', 'album_asset.albumsId', 'album.id')
|
||||
.leftJoin('album_asset', 'album_asset.albumId', 'album.id')
|
||||
.leftJoinLateral(
|
||||
(eb) =>
|
||||
eb
|
||||
.selectFrom('asset')
|
||||
.selectAll('asset')
|
||||
.whereRef('album_asset.assetsId', '=', 'asset.id')
|
||||
.whereRef('album_asset.assetId', '=', 'asset.id')
|
||||
.where('asset.deletedAt', 'is', null)
|
||||
.innerJoinLateral(
|
||||
(eb) =>
|
||||
|
|
@ -123,13 +123,13 @@ export class SharedLinkRepository {
|
|||
.selectFrom('shared_link')
|
||||
.selectAll('shared_link')
|
||||
.where('shared_link.userId', '=', userId)
|
||||
.leftJoin('shared_link_asset', 'shared_link_asset.sharedLinksId', 'shared_link.id')
|
||||
.leftJoin('shared_link_asset', 'shared_link_asset.sharedLinkId', 'shared_link.id')
|
||||
.leftJoinLateral(
|
||||
(eb) =>
|
||||
eb
|
||||
.selectFrom('asset')
|
||||
.select((eb) => eb.fn.jsonAgg('asset').as('assets'))
|
||||
.whereRef('asset.id', '=', 'shared_link_asset.assetsId')
|
||||
.whereRef('asset.id', '=', 'shared_link_asset.assetId')
|
||||
.where('asset.deletedAt', 'is', null)
|
||||
.as('assets'),
|
||||
(join) => join.onTrue(),
|
||||
|
|
@ -215,7 +215,7 @@ export class SharedLinkRepository {
|
|||
if (entity.assetIds && entity.assetIds.length > 0) {
|
||||
await this.db
|
||||
.insertInto('shared_link_asset')
|
||||
.values(entity.assetIds!.map((assetsId) => ({ assetsId, sharedLinksId: id })))
|
||||
.values(entity.assetIds!.map((assetId) => ({ assetId, sharedLinkId: id })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ export class SharedLinkRepository {
|
|||
if (entity.assetIds && entity.assetIds.length > 0) {
|
||||
await this.db
|
||||
.insertInto('shared_link_asset')
|
||||
.values(entity.assetIds!.map((assetsId) => ({ assetsId, sharedLinksId: id })))
|
||||
.values(entity.assetIds!.map((assetId) => ({ assetId, sharedLinkId: id })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
@ -249,12 +249,12 @@ export class SharedLinkRepository {
|
|||
.selectFrom('shared_link')
|
||||
.selectAll('shared_link')
|
||||
.where('shared_link.id', '=', id)
|
||||
.leftJoin('shared_link_asset', 'shared_link_asset.sharedLinksId', 'shared_link.id')
|
||||
.leftJoin('shared_link_asset', 'shared_link_asset.sharedLinkId', 'shared_link.id')
|
||||
.leftJoinLateral(
|
||||
(eb) =>
|
||||
eb
|
||||
.selectFrom('asset')
|
||||
.whereRef('asset.id', '=', 'shared_link_asset.assetsId')
|
||||
.whereRef('asset.id', '=', 'shared_link_asset.assetId')
|
||||
.selectAll('asset')
|
||||
.innerJoinLateral(
|
||||
(eb) =>
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ const withAssets = (eb: ExpressionBuilder<DB, 'stack'>, withTags = false) => {
|
|||
eb
|
||||
.selectFrom('tag')
|
||||
.select(columns.tag)
|
||||
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagsId')
|
||||
.whereRef('tag_asset.assetsId', '=', 'asset.id'),
|
||||
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagId')
|
||||
.whereRef('tag_asset.assetId', '=', 'asset.id'),
|
||||
).as('tags'),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -143,8 +143,8 @@ class AlbumSync extends BaseSync {
|
|||
getCreatedAfter({ nowId, userId, afterCreateId }: SyncCreatedAfterOptions) {
|
||||
return this.db
|
||||
.selectFrom('album_user')
|
||||
.select(['albumsId as id', 'createId'])
|
||||
.where('usersId', '=', userId)
|
||||
.select(['albumId as id', 'createId'])
|
||||
.where('userId', '=', userId)
|
||||
.$if(!!afterCreateId, (qb) => qb.where('createId', '>=', afterCreateId!))
|
||||
.where('createId', '<', nowId)
|
||||
.orderBy('createId', 'asc')
|
||||
|
|
@ -168,8 +168,8 @@ class AlbumSync extends BaseSync {
|
|||
const userId = options.userId;
|
||||
return this.upsertQuery('album', options)
|
||||
.distinctOn(['album.id', 'album.updateId'])
|
||||
.leftJoin('album_user as album_users', 'album.id', 'album_users.albumsId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_users.usersId', '=', userId)]))
|
||||
.leftJoin('album_user as album_users', 'album.id', 'album_users.albumId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_users.userId', '=', userId)]))
|
||||
.select([
|
||||
'album.id',
|
||||
'album.ownerId',
|
||||
|
|
@ -190,10 +190,10 @@ class AlbumAssetSync extends BaseSync {
|
|||
@GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true })
|
||||
getBackfill(options: SyncBackfillOptions, albumId: string) {
|
||||
return this.backfillQuery('album_asset', options)
|
||||
.innerJoin('asset', 'asset.id', 'album_asset.assetsId')
|
||||
.innerJoin('asset', 'asset.id', 'album_asset.assetId')
|
||||
.select(columns.syncAsset)
|
||||
.select('album_asset.updateId')
|
||||
.where('album_asset.albumsId', '=', albumId)
|
||||
.where('album_asset.albumId', '=', albumId)
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
@ -201,13 +201,13 @@ class AlbumAssetSync extends BaseSync {
|
|||
getUpdates(options: SyncQueryOptions, albumToAssetAck: SyncAck) {
|
||||
const userId = options.userId;
|
||||
return this.upsertQuery('asset', options)
|
||||
.innerJoin('album_asset', 'album_asset.assetsId', 'asset.id')
|
||||
.innerJoin('album_asset', 'album_asset.assetId', 'asset.id')
|
||||
.select(columns.syncAsset)
|
||||
.select('asset.updateId')
|
||||
.where('album_asset.updateId', '<=', albumToAssetAck.updateId) // Ensure we only send updates for assets that the client already knows about
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumsId')
|
||||
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)]))
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumId')
|
||||
.leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
@ -216,11 +216,11 @@ class AlbumAssetSync extends BaseSync {
|
|||
const userId = options.userId;
|
||||
return this.upsertQuery('album_asset', options)
|
||||
.select('album_asset.updateId')
|
||||
.innerJoin('asset', 'asset.id', 'album_asset.assetsId')
|
||||
.innerJoin('asset', 'asset.id', 'album_asset.assetId')
|
||||
.select(columns.syncAsset)
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumsId')
|
||||
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)]))
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumId')
|
||||
.leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
|
||||
.stream();
|
||||
}
|
||||
}
|
||||
|
|
@ -229,10 +229,10 @@ class AlbumAssetExifSync extends BaseSync {
|
|||
@GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true })
|
||||
getBackfill(options: SyncBackfillOptions, albumId: string) {
|
||||
return this.backfillQuery('album_asset', options)
|
||||
.innerJoin('asset_exif', 'asset_exif.assetId', 'album_asset.assetsId')
|
||||
.innerJoin('asset_exif', 'asset_exif.assetId', 'album_asset.assetId')
|
||||
.select(columns.syncAssetExif)
|
||||
.select('album_asset.updateId')
|
||||
.where('album_asset.albumsId', '=', albumId)
|
||||
.where('album_asset.albumId', '=', albumId)
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
@ -240,13 +240,13 @@ class AlbumAssetExifSync extends BaseSync {
|
|||
getUpdates(options: SyncQueryOptions, albumToAssetAck: SyncAck) {
|
||||
const userId = options.userId;
|
||||
return this.upsertQuery('asset_exif', options)
|
||||
.innerJoin('album_asset', 'album_asset.assetsId', 'asset_exif.assetId')
|
||||
.innerJoin('album_asset', 'album_asset.assetId', 'asset_exif.assetId')
|
||||
.select(columns.syncAssetExif)
|
||||
.select('asset_exif.updateId')
|
||||
.where('album_asset.updateId', '<=', albumToAssetAck.updateId) // Ensure we only send exif updates for assets that the client already knows about
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumsId')
|
||||
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)]))
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumId')
|
||||
.leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
@ -255,11 +255,11 @@ class AlbumAssetExifSync extends BaseSync {
|
|||
const userId = options.userId;
|
||||
return this.upsertQuery('album_asset', options)
|
||||
.select('album_asset.updateId')
|
||||
.innerJoin('asset_exif', 'asset_exif.assetId', 'album_asset.assetsId')
|
||||
.innerJoin('asset_exif', 'asset_exif.assetId', 'album_asset.assetId')
|
||||
.select(columns.syncAssetExif)
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumsId')
|
||||
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)]))
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumId')
|
||||
.leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
|
||||
.stream();
|
||||
}
|
||||
}
|
||||
|
|
@ -268,8 +268,8 @@ class AlbumToAssetSync extends BaseSync {
|
|||
@GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true })
|
||||
getBackfill(options: SyncBackfillOptions, albumId: string) {
|
||||
return this.backfillQuery('album_asset', options)
|
||||
.select(['album_asset.assetsId as assetId', 'album_asset.albumsId as albumId', 'album_asset.updateId'])
|
||||
.where('album_asset.albumsId', '=', albumId)
|
||||
.select(['album_asset.assetId as assetId', 'album_asset.albumId as albumId', 'album_asset.updateId'])
|
||||
.where('album_asset.albumId', '=', albumId)
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
@ -290,8 +290,8 @@ class AlbumToAssetSync extends BaseSync {
|
|||
eb.parens(
|
||||
eb
|
||||
.selectFrom('album_user')
|
||||
.select(['album_user.albumsId as id'])
|
||||
.where('album_user.usersId', '=', userId),
|
||||
.select(['album_user.albumId as id'])
|
||||
.where('album_user.userId', '=', userId),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -307,10 +307,10 @@ class AlbumToAssetSync extends BaseSync {
|
|||
getUpserts(options: SyncQueryOptions) {
|
||||
const userId = options.userId;
|
||||
return this.upsertQuery('album_asset', options)
|
||||
.select(['album_asset.assetsId as assetId', 'album_asset.albumsId as albumId', 'album_asset.updateId'])
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumsId')
|
||||
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)]))
|
||||
.select(['album_asset.assetId as assetId', 'album_asset.albumId as albumId', 'album_asset.updateId'])
|
||||
.innerJoin('album', 'album.id', 'album_asset.albumId')
|
||||
.leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
|
||||
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
|
||||
.stream();
|
||||
}
|
||||
}
|
||||
|
|
@ -321,7 +321,7 @@ class AlbumUserSync extends BaseSync {
|
|||
return this.backfillQuery('album_user', options)
|
||||
.select(columns.syncAlbumUser)
|
||||
.select('album_user.updateId')
|
||||
.where('albumsId', '=', albumId)
|
||||
.where('albumId', '=', albumId)
|
||||
.stream();
|
||||
}
|
||||
|
||||
|
|
@ -342,8 +342,8 @@ class AlbumUserSync extends BaseSync {
|
|||
eb.parens(
|
||||
eb
|
||||
.selectFrom('album_user')
|
||||
.select(['album_user.albumsId as id'])
|
||||
.where('album_user.usersId', '=', userId),
|
||||
.select(['album_user.albumId as id'])
|
||||
.where('album_user.userId', '=', userId),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -363,7 +363,7 @@ class AlbumUserSync extends BaseSync {
|
|||
.select('album_user.updateId')
|
||||
.where((eb) =>
|
||||
eb(
|
||||
'album_user.albumsId',
|
||||
'album_user.albumId',
|
||||
'in',
|
||||
eb
|
||||
.selectFrom('album')
|
||||
|
|
@ -373,8 +373,8 @@ class AlbumUserSync extends BaseSync {
|
|||
eb.parens(
|
||||
eb
|
||||
.selectFrom('album_user as albumUsers')
|
||||
.select(['albumUsers.albumsId as id'])
|
||||
.where('albumUsers.usersId', '=', userId),
|
||||
.select(['albumUsers.albumId as id'])
|
||||
.where('albumUsers.userId', '=', userId),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -550,7 +550,7 @@ class MemoryToAssetSync extends BaseSync {
|
|||
@GenerateSql({ params: [dummyQueryOptions], stream: true })
|
||||
getUpserts(options: SyncQueryOptions) {
|
||||
return this.upsertQuery('memory_asset', options)
|
||||
.select(['memoriesId as memoryId', 'assetsId as assetId'])
|
||||
.select(['memoriesId as memoryId', 'assetId as assetId'])
|
||||
.select('updateId')
|
||||
.where('memoriesId', 'in', (eb) => eb.selectFrom('memory').select('id').where('ownerId', '=', options.userId))
|
||||
.stream();
|
||||
|
|
|
|||
|
|
@ -97,9 +97,9 @@ export class TagRepository {
|
|||
|
||||
const results = await this.db
|
||||
.selectFrom('tag_asset')
|
||||
.select(['assetsId as assetId'])
|
||||
.where('tagsId', '=', tagId)
|
||||
.where('assetsId', 'in', assetIds)
|
||||
.select(['assetId as assetId'])
|
||||
.where('tagId', '=', tagId)
|
||||
.where('assetId', 'in', assetIds)
|
||||
.execute();
|
||||
|
||||
return new Set(results.map(({ assetId }) => assetId));
|
||||
|
|
@ -114,7 +114,7 @@ export class TagRepository {
|
|||
|
||||
await this.db
|
||||
.insertInto('tag_asset')
|
||||
.values(assetIds.map((assetId) => ({ tagsId: tagId, assetsId: assetId })))
|
||||
.values(assetIds.map((assetId) => ({ tagId, assetId })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ export class TagRepository {
|
|||
return;
|
||||
}
|
||||
|
||||
await this.db.deleteFrom('tag_asset').where('tagsId', '=', tagId).where('assetsId', 'in', assetIds).execute();
|
||||
await this.db.deleteFrom('tag_asset').where('tagId', '=', tagId).where('assetId', 'in', assetIds).execute();
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [[{ assetId: DummyValue.UUID, tagsIds: [DummyValue.UUID] }]] })
|
||||
|
|
@ -147,7 +147,7 @@ export class TagRepository {
|
|||
@Chunked({ paramIndex: 1 })
|
||||
replaceAssetTags(assetId: string, tagIds: string[]) {
|
||||
return this.db.transaction().execute(async (tx) => {
|
||||
await tx.deleteFrom('tag_asset').where('assetsId', '=', assetId).execute();
|
||||
await tx.deleteFrom('tag_asset').where('assetId', '=', assetId).execute();
|
||||
|
||||
if (tagIds.length === 0) {
|
||||
return;
|
||||
|
|
@ -155,7 +155,7 @@ export class TagRepository {
|
|||
|
||||
return tx
|
||||
.insertInto('tag_asset')
|
||||
.values(tagIds.map((tagId) => ({ tagsId: tagId, assetsId: assetId })))
|
||||
.values(tagIds.map((tagId) => ({ tagId, assetId })))
|
||||
.onConflict((oc) => oc.doNothing())
|
||||
.returningAll()
|
||||
.execute();
|
||||
|
|
@ -170,7 +170,7 @@ export class TagRepository {
|
|||
exists(
|
||||
selectFrom('tag_closure')
|
||||
.whereRef('tag.id', '=', 'tag_closure.id_ancestor')
|
||||
.innerJoin('tag_asset', 'tag_closure.id_descendant', 'tag_asset.tagsId'),
|
||||
.innerJoin('tag_asset', 'tag_closure.id_descendant', 'tag_asset.tagId'),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export const album_user_after_insert = registerFunction({
|
|||
body: `
|
||||
BEGIN
|
||||
UPDATE album SET "updatedAt" = clock_timestamp(), "updateId" = immich_uuid_v7(clock_timestamp())
|
||||
WHERE "id" IN (SELECT DISTINCT "albumsId" FROM inserted_rows);
|
||||
WHERE "id" IN (SELECT DISTINCT "albumId" FROM inserted_rows);
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
|
@ -139,8 +139,8 @@ export const album_asset_delete_audit = registerFunction({
|
|||
body: `
|
||||
BEGIN
|
||||
INSERT INTO album_asset_audit ("albumId", "assetId")
|
||||
SELECT "albumsId", "assetsId" FROM OLD
|
||||
WHERE "albumsId" IN (SELECT "id" FROM album WHERE "id" IN (SELECT "albumsId" FROM OLD));
|
||||
SELECT "albumId", "assetId" FROM OLD
|
||||
WHERE "albumId" IN (SELECT "id" FROM album WHERE "id" IN (SELECT "albumId" FROM OLD));
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
|
@ -152,12 +152,12 @@ export const album_user_delete_audit = registerFunction({
|
|||
body: `
|
||||
BEGIN
|
||||
INSERT INTO album_audit ("albumId", "userId")
|
||||
SELECT "albumsId", "usersId"
|
||||
SELECT "albumId", "userId"
|
||||
FROM OLD;
|
||||
|
||||
IF pg_trigger_depth() = 1 THEN
|
||||
INSERT INTO album_user_audit ("albumId", "userId")
|
||||
SELECT "albumsId", "usersId"
|
||||
SELECT "albumId", "userId"
|
||||
FROM OLD;
|
||||
END IF;
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ export const memory_asset_delete_audit = registerFunction({
|
|||
body: `
|
||||
BEGIN
|
||||
INSERT INTO memory_asset_audit ("memoryId", "assetId")
|
||||
SELECT "memoriesId", "assetsId" FROM OLD
|
||||
SELECT "memoriesId", "assetId" FROM OLD
|
||||
WHERE "memoriesId" IN (SELECT "id" FROM memory WHERE "id" IN (SELECT "memoriesId" FROM OLD));
|
||||
RETURN NULL;
|
||||
END`,
|
||||
|
|
|
|||
99
server/src/schema/migrations/1761755618862-FixColumnNames.ts
Normal file
99
server/src/schema/migrations/1761755618862-FixColumnNames.ts
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import { Kysely, sql } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
// rename columns
|
||||
await sql`ALTER TABLE "album_asset" RENAME COLUMN "albumsId" TO "albumId";`.execute(db);
|
||||
await sql`ALTER TABLE "album_asset" RENAME COLUMN "assetsId" TO "assetId";`.execute(db);
|
||||
await sql`ALTER TABLE "album_user" RENAME COLUMN "albumsId" TO "albumId";`.execute(db);
|
||||
await sql`ALTER TABLE "album_user" RENAME COLUMN "usersId" TO "userId";`.execute(db);
|
||||
await sql`ALTER TABLE "memory_asset" RENAME COLUMN "assetsId" TO "assetId";`.execute(db);
|
||||
await sql`ALTER TABLE "shared_link_asset" RENAME COLUMN "assetsId" TO "assetId";`.execute(db);
|
||||
await sql`ALTER TABLE "shared_link_asset" RENAME COLUMN "sharedLinksId" TO "sharedLinkId";`.execute(db);
|
||||
await sql`ALTER TABLE "tag_asset" RENAME COLUMN "assetsId" TO "assetId";`.execute(db);
|
||||
await sql`ALTER TABLE "tag_asset" RENAME COLUMN "tagsId" TO "tagId";`.execute(db);
|
||||
|
||||
// rename constraints
|
||||
await sql`ALTER TABLE "album_asset" RENAME CONSTRAINT "album_asset_albumsId_fkey" TO "album_asset_albumId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "album_asset" RENAME CONSTRAINT "album_asset_assetsId_fkey" TO "album_asset_assetId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "album_user" RENAME CONSTRAINT "album_user_albumsId_fkey" TO "album_user_albumId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "album_user" RENAME CONSTRAINT "album_user_usersId_fkey" TO "album_user_userId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "memory_asset" RENAME CONSTRAINT "memory_asset_assetsId_fkey" TO "memory_asset_assetId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "shared_link_asset" RENAME CONSTRAINT "shared_link_asset_assetsId_fkey" TO "shared_link_asset_assetId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "shared_link_asset" RENAME CONSTRAINT "shared_link_asset_sharedLinksId_fkey" TO "shared_link_asset_sharedLinkId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "tag_asset" RENAME CONSTRAINT "tag_asset_assetsId_fkey" TO "tag_asset_assetId_fkey";`.execute(db);
|
||||
await sql`ALTER TABLE "tag_asset" RENAME CONSTRAINT "tag_asset_tagsId_fkey" TO "tag_asset_tagId_fkey";`.execute(db);
|
||||
|
||||
// rename indexes
|
||||
await sql`ALTER INDEX "album_asset_albumsId_idx" RENAME TO "album_asset_albumId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "album_asset_assetsId_idx" RENAME TO "album_asset_assetId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "album_user_usersId_idx" RENAME TO "album_user_userId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "album_user_albumsId_idx" RENAME TO "album_user_albumId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "memory_asset_assetsId_idx" RENAME TO "memory_asset_assetId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "shared_link_asset_sharedLinksId_idx" RENAME TO "shared_link_asset_sharedLinkId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "shared_link_asset_assetsId_idx" RENAME TO "shared_link_asset_assetId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "tag_asset_assetsId_idx" RENAME TO "tag_asset_assetId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "tag_asset_tagsId_idx" RENAME TO "tag_asset_tagId_idx";`.execute(db);
|
||||
await sql`ALTER INDEX "tag_asset_assetsId_tagsId_idx" RENAME TO "tag_asset_assetId_tagId_idx";`.execute(db);
|
||||
|
||||
// update triggers and functions
|
||||
await sql`CREATE OR REPLACE FUNCTION album_user_after_insert()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE PLPGSQL
|
||||
AS $$
|
||||
BEGIN
|
||||
UPDATE album SET "updatedAt" = clock_timestamp(), "updateId" = immich_uuid_v7(clock_timestamp())
|
||||
WHERE "id" IN (SELECT DISTINCT "albumId" FROM inserted_rows);
|
||||
RETURN NULL;
|
||||
END
|
||||
$$;`.execute(db);
|
||||
await sql`CREATE OR REPLACE FUNCTION album_asset_delete_audit()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE PLPGSQL
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO album_asset_audit ("albumId", "assetId")
|
||||
SELECT "albumId", "assetId" FROM OLD
|
||||
WHERE "albumId" IN (SELECT "id" FROM album WHERE "id" IN (SELECT "albumId" FROM OLD));
|
||||
RETURN NULL;
|
||||
END
|
||||
$$;`.execute(db);
|
||||
await sql`CREATE OR REPLACE FUNCTION album_user_delete_audit()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE PLPGSQL
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO album_audit ("albumId", "userId")
|
||||
SELECT "albumId", "userId"
|
||||
FROM OLD;
|
||||
|
||||
IF pg_trigger_depth() = 1 THEN
|
||||
INSERT INTO album_user_audit ("albumId", "userId")
|
||||
SELECT "albumId", "userId"
|
||||
FROM OLD;
|
||||
END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END
|
||||
$$;`.execute(db);
|
||||
await sql`CREATE OR REPLACE FUNCTION memory_asset_delete_audit()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE PLPGSQL
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO memory_asset_audit ("memoryId", "assetId")
|
||||
SELECT "memoriesId", "assetId" FROM OLD
|
||||
WHERE "memoriesId" IN (SELECT "id" FROM memory WHERE "id" IN (SELECT "memoriesId" FROM OLD));
|
||||
RETURN NULL;
|
||||
END
|
||||
$$;`.execute(db);
|
||||
|
||||
// update overrides
|
||||
await sql`UPDATE "migration_overrides" SET "value" = '{"type":"function","name":"album_user_after_insert","sql":"CREATE OR REPLACE FUNCTION album_user_after_insert()\\n RETURNS TRIGGER\\n LANGUAGE PLPGSQL\\n AS $$\\n BEGIN\\n UPDATE album SET \\"updatedAt\\" = clock_timestamp(), \\"updateId\\" = immich_uuid_v7(clock_timestamp())\\n WHERE \\"id\\" IN (SELECT DISTINCT \\"albumId\\" FROM inserted_rows);\\n RETURN NULL;\\n END\\n $$;"}'::jsonb WHERE "name" = 'function_album_user_after_insert';`.execute(db);
|
||||
await sql`UPDATE "migration_overrides" SET "value" = '{"type":"function","name":"album_asset_delete_audit","sql":"CREATE OR REPLACE FUNCTION album_asset_delete_audit()\\n RETURNS TRIGGER\\n LANGUAGE PLPGSQL\\n AS $$\\n BEGIN\\n INSERT INTO album_asset_audit (\\"albumId\\", \\"assetId\\")\\n SELECT \\"albumId\\", \\"assetId\\" FROM OLD\\n WHERE \\"albumId\\" IN (SELECT \\"id\\" FROM album WHERE \\"id\\" IN (SELECT \\"albumId\\" FROM OLD));\\n RETURN NULL;\\n END\\n $$;"}'::jsonb WHERE "name" = 'function_album_asset_delete_audit';`.execute(db);
|
||||
await sql`UPDATE "migration_overrides" SET "value" = '{"type":"function","name":"album_user_delete_audit","sql":"CREATE OR REPLACE FUNCTION album_user_delete_audit()\\n RETURNS TRIGGER\\n LANGUAGE PLPGSQL\\n AS $$\\n BEGIN\\n INSERT INTO album_audit (\\"albumId\\", \\"userId\\")\\n SELECT \\"albumId\\", \\"userId\\"\\n FROM OLD;\\n\\n IF pg_trigger_depth() = 1 THEN\\n INSERT INTO album_user_audit (\\"albumId\\", \\"userId\\")\\n SELECT \\"albumId\\", \\"userId\\"\\n FROM OLD;\\n END IF;\\n\\n RETURN NULL;\\n END\\n $$;"}'::jsonb WHERE "name" = 'function_album_user_delete_audit';`.execute(db);
|
||||
await sql`UPDATE "migration_overrides" SET "value" = '{"type":"function","name":"memory_asset_delete_audit","sql":"CREATE OR REPLACE FUNCTION memory_asset_delete_audit()\\n RETURNS TRIGGER\\n LANGUAGE PLPGSQL\\n AS $$\\n BEGIN\\n INSERT INTO memory_asset_audit (\\"memoryId\\", \\"assetId\\")\\n SELECT \\"memoriesId\\", \\"assetId\\" FROM OLD\\n WHERE \\"memoriesId\\" IN (SELECT \\"id\\" FROM memory WHERE \\"id\\" IN (SELECT \\"memoriesId\\" FROM OLD));\\n RETURN NULL;\\n END\\n $$;"}'::jsonb WHERE "name" = 'function_memory_asset_delete_audit';`.execute(db);
|
||||
}
|
||||
|
||||
export function down() {
|
||||
// not implemented
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ import {
|
|||
@ForeignKeyConstraint({
|
||||
columns: ['albumId', 'assetId'],
|
||||
referenceTable: () => AlbumAssetTable,
|
||||
referenceColumns: ['albumsId', 'assetsId'],
|
||||
referenceColumns: ['albumId', 'assetId'],
|
||||
onUpdate: 'NO ACTION',
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ import {
|
|||
})
|
||||
export class AlbumAssetTable {
|
||||
@ForeignKeyColumn(() => AlbumTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false, primary: true })
|
||||
albumsId!: string;
|
||||
albumId!: string;
|
||||
|
||||
@ForeignKeyColumn(() => AssetTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false, primary: true })
|
||||
assetsId!: string;
|
||||
assetId!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Generated<Timestamp>;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ export class AlbumUserTable {
|
|||
nullable: false,
|
||||
primary: true,
|
||||
})
|
||||
albumsId!: string;
|
||||
albumId!: string;
|
||||
|
||||
@ForeignKeyColumn(() => UserTable, {
|
||||
onDelete: 'CASCADE',
|
||||
|
|
@ -45,7 +45,7 @@ export class AlbumUserTable {
|
|||
nullable: false,
|
||||
primary: true,
|
||||
})
|
||||
usersId!: string;
|
||||
userId!: string;
|
||||
|
||||
@Column({ type: 'character varying', default: AlbumUserRole.Editor })
|
||||
role!: Generated<AlbumUserRole>;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export class MemoryAssetTable {
|
|||
memoriesId!: string;
|
||||
|
||||
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
|
||||
assetsId!: string;
|
||||
assetId!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Generated<Timestamp>;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import { ForeignKeyColumn, Table } from 'src/sql-tools';
|
|||
@Table('shared_link_asset')
|
||||
export class SharedLinkAssetTable {
|
||||
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
|
||||
assetsId!: string;
|
||||
assetId!: string;
|
||||
|
||||
@ForeignKeyColumn(() => SharedLinkTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
|
||||
sharedLinksId!: string;
|
||||
sharedLinkId!: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import { AssetTable } from 'src/schema/tables/asset.table';
|
|||
import { TagTable } from 'src/schema/tables/tag.table';
|
||||
import { ForeignKeyColumn, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Index({ columns: ['assetsId', 'tagsId'] })
|
||||
@Index({ columns: ['assetId', 'tagId'] })
|
||||
@Table('tag_asset')
|
||||
export class TagAssetTable {
|
||||
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true })
|
||||
assetsId!: string;
|
||||
assetId!: string;
|
||||
|
||||
@ForeignKeyColumn(() => TagTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true })
|
||||
tagsId!: string;
|
||||
tagId!: string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -402,16 +402,16 @@ describe(AlbumService.name, () => {
|
|||
mocks.album.update.mockResolvedValue(albumStub.sharedWithAdmin);
|
||||
mocks.user.get.mockResolvedValue(userStub.user2);
|
||||
mocks.albumUser.create.mockResolvedValue({
|
||||
usersId: userStub.user2.id,
|
||||
albumsId: albumStub.sharedWithAdmin.id,
|
||||
userId: userStub.user2.id,
|
||||
albumId: albumStub.sharedWithAdmin.id,
|
||||
role: AlbumUserRole.Editor,
|
||||
});
|
||||
await sut.addUsers(authStub.user1, albumStub.sharedWithAdmin.id, {
|
||||
albumUsers: [{ userId: authStub.user2.user.id }],
|
||||
});
|
||||
expect(mocks.albumUser.create).toHaveBeenCalledWith({
|
||||
usersId: authStub.user2.user.id,
|
||||
albumsId: albumStub.sharedWithAdmin.id,
|
||||
userId: authStub.user2.user.id,
|
||||
albumId: albumStub.sharedWithAdmin.id,
|
||||
});
|
||||
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', {
|
||||
id: albumStub.sharedWithAdmin.id,
|
||||
|
|
@ -439,8 +439,8 @@ describe(AlbumService.name, () => {
|
|||
|
||||
expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.albumUser.delete).toHaveBeenCalledWith({
|
||||
albumsId: albumStub.sharedWithUser.id,
|
||||
usersId: userStub.user1.id,
|
||||
albumId: albumStub.sharedWithUser.id,
|
||||
userId: userStub.user1.id,
|
||||
});
|
||||
expect(mocks.album.getById).toHaveBeenCalledWith(albumStub.sharedWithUser.id, { withAssets: false });
|
||||
});
|
||||
|
|
@ -467,8 +467,8 @@ describe(AlbumService.name, () => {
|
|||
|
||||
expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.albumUser.delete).toHaveBeenCalledWith({
|
||||
albumsId: albumStub.sharedWithUser.id,
|
||||
usersId: authStub.user1.user.id,
|
||||
albumId: albumStub.sharedWithUser.id,
|
||||
userId: authStub.user1.user.id,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -480,8 +480,8 @@ describe(AlbumService.name, () => {
|
|||
|
||||
expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.albumUser.delete).toHaveBeenCalledWith({
|
||||
albumsId: albumStub.sharedWithUser.id,
|
||||
usersId: authStub.user1.user.id,
|
||||
albumId: albumStub.sharedWithUser.id,
|
||||
userId: authStub.user1.user.id,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -515,7 +515,7 @@ describe(AlbumService.name, () => {
|
|||
role: AlbumUserRole.Editor,
|
||||
});
|
||||
expect(mocks.albumUser.update).toHaveBeenCalledWith(
|
||||
{ albumsId: albumStub.sharedWithAdmin.id, usersId: userStub.admin.id },
|
||||
{ albumId: albumStub.sharedWithAdmin.id, userId: userStub.admin.id },
|
||||
{ role: AlbumUserRole.Editor },
|
||||
);
|
||||
});
|
||||
|
|
@ -804,12 +804,12 @@ describe(AlbumService.name, () => {
|
|||
albumThumbnailAssetId: 'asset-1',
|
||||
});
|
||||
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
||||
{ albumsId: 'album-123', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-3' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-3' },
|
||||
{ albumId: 'album-123', assetId: 'asset-1' },
|
||||
{ albumId: 'album-123', assetId: 'asset-2' },
|
||||
{ albumId: 'album-123', assetId: 'asset-3' },
|
||||
{ albumId: 'album-321', assetId: 'asset-1' },
|
||||
{ albumId: 'album-321', assetId: 'asset-2' },
|
||||
{ albumId: 'album-321', assetId: 'asset-3' },
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
@ -840,12 +840,12 @@ describe(AlbumService.name, () => {
|
|||
albumThumbnailAssetId: 'asset-id',
|
||||
});
|
||||
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
||||
{ albumsId: 'album-123', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-3' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-3' },
|
||||
{ albumId: 'album-123', assetId: 'asset-1' },
|
||||
{ albumId: 'album-123', assetId: 'asset-2' },
|
||||
{ albumId: 'album-123', assetId: 'asset-3' },
|
||||
{ albumId: 'album-321', assetId: 'asset-1' },
|
||||
{ albumId: 'album-321', assetId: 'asset-2' },
|
||||
{ albumId: 'album-321', assetId: 'asset-3' },
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
@ -876,12 +876,12 @@ describe(AlbumService.name, () => {
|
|||
albumThumbnailAssetId: 'asset-1',
|
||||
});
|
||||
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
||||
{ albumsId: 'album-123', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-3' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-3' },
|
||||
{ albumId: 'album-123', assetId: 'asset-1' },
|
||||
{ albumId: 'album-123', assetId: 'asset-2' },
|
||||
{ albumId: 'album-123', assetId: 'asset-3' },
|
||||
{ albumId: 'album-321', assetId: 'asset-1' },
|
||||
{ albumId: 'album-321', assetId: 'asset-2' },
|
||||
{ albumId: 'album-321', assetId: 'asset-3' },
|
||||
]);
|
||||
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
|
||||
id: 'album-123',
|
||||
|
|
@ -936,9 +936,9 @@ describe(AlbumService.name, () => {
|
|||
albumThumbnailAssetId: 'asset-1',
|
||||
});
|
||||
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
||||
{ albumsId: 'album-123', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-3' },
|
||||
{ albumId: 'album-123', assetId: 'asset-1' },
|
||||
{ albumId: 'album-123', assetId: 'asset-2' },
|
||||
{ albumId: 'album-123', assetId: 'asset-3' },
|
||||
]);
|
||||
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
|
||||
id: 'album-123',
|
||||
|
|
@ -977,12 +977,12 @@ describe(AlbumService.name, () => {
|
|||
albumThumbnailAssetId: 'asset-1',
|
||||
});
|
||||
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
||||
{ albumsId: 'album-123', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-123', assetsId: 'asset-3' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-3' },
|
||||
{ albumId: 'album-123', assetId: 'asset-1' },
|
||||
{ albumId: 'album-123', assetId: 'asset-2' },
|
||||
{ albumId: 'album-123', assetId: 'asset-3' },
|
||||
{ albumId: 'album-321', assetId: 'asset-1' },
|
||||
{ albumId: 'album-321', assetId: 'asset-2' },
|
||||
{ albumId: 'album-321', assetId: 'asset-3' },
|
||||
]);
|
||||
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(
|
||||
authStub.admin.user.id,
|
||||
|
|
@ -1014,9 +1014,9 @@ describe(AlbumService.name, () => {
|
|||
albumThumbnailAssetId: 'asset-1',
|
||||
});
|
||||
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
|
||||
{ albumsId: 'album-321', assetsId: 'asset-1' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-2' },
|
||||
{ albumsId: 'album-321', assetsId: 'asset-3' },
|
||||
{ albumId: 'album-321', assetId: 'asset-1' },
|
||||
{ albumId: 'album-321', assetId: 'asset-2' },
|
||||
{ albumId: 'album-321', assetId: 'asset-3' },
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ export class AlbumService extends BaseService {
|
|||
return results;
|
||||
}
|
||||
|
||||
const albumAssetValues: { albumsId: string; assetsId: string }[] = [];
|
||||
const albumAssetValues: { albumId: string; assetId: string }[] = [];
|
||||
const events: { id: string; recipients: string[] }[] = [];
|
||||
for (const albumId of allowedAlbumIds) {
|
||||
const existingAssetIds = await this.albumRepository.getAssetIds(albumId, [...allowedAssetIds]);
|
||||
|
|
@ -228,7 +228,7 @@ export class AlbumService extends BaseService {
|
|||
results.success = true;
|
||||
|
||||
for (const assetId of notPresentAssetIds) {
|
||||
albumAssetValues.push({ albumsId: albumId, assetsId: assetId });
|
||||
albumAssetValues.push({ albumId, assetId });
|
||||
}
|
||||
await this.albumRepository.update(albumId, {
|
||||
id: albumId,
|
||||
|
|
@ -289,7 +289,7 @@ export class AlbumService extends BaseService {
|
|||
throw new BadRequestException('User not found');
|
||||
}
|
||||
|
||||
await this.albumUserRepository.create({ usersId: userId, albumsId: id, role });
|
||||
await this.albumUserRepository.create({ userId, albumId: id, role });
|
||||
await this.eventRepository.emit('AlbumInvite', { id, userId });
|
||||
}
|
||||
|
||||
|
|
@ -317,12 +317,12 @@ export class AlbumService extends BaseService {
|
|||
await this.requireAccess({ auth, permission: Permission.AlbumShare, ids: [id] });
|
||||
}
|
||||
|
||||
await this.albumUserRepository.delete({ albumsId: id, usersId: userId });
|
||||
await this.albumUserRepository.delete({ albumId: id, userId });
|
||||
}
|
||||
|
||||
async updateUser(auth: AuthDto, id: string, userId: string, dto: UpdateAlbumUserDto): Promise<void> {
|
||||
await this.requireAccess({ auth, permission: Permission.AlbumShare, ids: [id] });
|
||||
await this.albumUserRepository.update({ albumsId: id, usersId: userId }, { role: dto.role });
|
||||
await this.albumUserRepository.update({ albumId: id, userId }, { role: dto.role });
|
||||
}
|
||||
|
||||
private async findOrFail(id: string, options: AlbumInfoOptions) {
|
||||
|
|
|
|||
|
|
@ -192,12 +192,12 @@ describe(TagService.name, () => {
|
|||
mocks.access.tag.checkOwnerAccess.mockResolvedValue(new Set(['tag-1', 'tag-2']));
|
||||
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1', 'asset-2', 'asset-3']));
|
||||
mocks.tag.upsertAssetIds.mockResolvedValue([
|
||||
{ tagsId: 'tag-1', assetsId: 'asset-1' },
|
||||
{ tagsId: 'tag-1', assetsId: 'asset-2' },
|
||||
{ tagsId: 'tag-1', assetsId: 'asset-3' },
|
||||
{ tagsId: 'tag-2', assetsId: 'asset-1' },
|
||||
{ tagsId: 'tag-2', assetsId: 'asset-2' },
|
||||
{ tagsId: 'tag-2', assetsId: 'asset-3' },
|
||||
{ tagId: 'tag-1', assetId: 'asset-1' },
|
||||
{ tagId: 'tag-1', assetId: 'asset-2' },
|
||||
{ tagId: 'tag-1', assetId: 'asset-3' },
|
||||
{ tagId: 'tag-2', assetId: 'asset-1' },
|
||||
{ tagId: 'tag-2', assetId: 'asset-2' },
|
||||
{ tagId: 'tag-2', assetId: 'asset-3' },
|
||||
]);
|
||||
await expect(
|
||||
sut.bulkTagAssets(authStub.admin, { tagIds: ['tag-1', 'tag-2'], assetIds: ['asset-1', 'asset-2', 'asset-3'] }),
|
||||
|
|
@ -205,12 +205,12 @@ describe(TagService.name, () => {
|
|||
count: 6,
|
||||
});
|
||||
expect(mocks.tag.upsertAssetIds).toHaveBeenCalledWith([
|
||||
{ tagsId: 'tag-1', assetsId: 'asset-1' },
|
||||
{ tagsId: 'tag-1', assetsId: 'asset-2' },
|
||||
{ tagsId: 'tag-1', assetsId: 'asset-3' },
|
||||
{ tagsId: 'tag-2', assetsId: 'asset-1' },
|
||||
{ tagsId: 'tag-2', assetsId: 'asset-2' },
|
||||
{ tagsId: 'tag-2', assetsId: 'asset-3' },
|
||||
{ tagId: 'tag-1', assetId: 'asset-1' },
|
||||
{ tagId: 'tag-1', assetId: 'asset-2' },
|
||||
{ tagId: 'tag-1', assetId: 'asset-3' },
|
||||
{ tagId: 'tag-2', assetId: 'asset-1' },
|
||||
{ tagId: 'tag-2', assetId: 'asset-2' },
|
||||
{ tagId: 'tag-2', assetId: 'asset-3' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,14 +82,14 @@ export class TagService extends BaseService {
|
|||
]);
|
||||
|
||||
const items: Insertable<TagAssetTable>[] = [];
|
||||
for (const tagsId of tagIds) {
|
||||
for (const assetsId of assetIds) {
|
||||
items.push({ tagsId, assetsId });
|
||||
for (const tagId of tagIds) {
|
||||
for (const assetId of assetIds) {
|
||||
items.push({ tagId, assetId });
|
||||
}
|
||||
}
|
||||
|
||||
const results = await this.tagRepository.upsertAssetIds(items);
|
||||
for (const assetId of new Set(results.map((item) => item.assetsId))) {
|
||||
for (const assetId of new Set(results.map((item) => item.assetId))) {
|
||||
await this.eventRepository.emit('AssetTag', { assetId });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -244,12 +244,12 @@ export function inAlbums<O>(qb: SelectQueryBuilder<DB, 'asset', O>, albumIds: st
|
|||
(eb) =>
|
||||
eb
|
||||
.selectFrom('album_asset')
|
||||
.select('assetsId')
|
||||
.where('albumsId', '=', anyUuid(albumIds!))
|
||||
.groupBy('assetsId')
|
||||
.having((eb) => eb.fn.count('albumsId').distinct(), '=', albumIds.length)
|
||||
.select('assetId')
|
||||
.where('albumId', '=', anyUuid(albumIds!))
|
||||
.groupBy('assetId')
|
||||
.having((eb) => eb.fn.count('albumId').distinct(), '=', albumIds.length)
|
||||
.as('has_album'),
|
||||
(join) => join.onRef('has_album.assetsId', '=', 'asset.id'),
|
||||
(join) => join.onRef('has_album.assetId', '=', 'asset.id'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -258,13 +258,13 @@ export function hasTags<O>(qb: SelectQueryBuilder<DB, 'asset', O>, tagIds: strin
|
|||
(eb) =>
|
||||
eb
|
||||
.selectFrom('tag_asset')
|
||||
.select('assetsId')
|
||||
.innerJoin('tag_closure', 'tag_asset.tagsId', 'tag_closure.id_descendant')
|
||||
.select('assetId')
|
||||
.innerJoin('tag_closure', 'tag_asset.tagId', 'tag_closure.id_descendant')
|
||||
.where('tag_closure.id_ancestor', '=', anyUuid(tagIds))
|
||||
.groupBy('assetsId')
|
||||
.groupBy('assetId')
|
||||
.having((eb) => eb.fn.count('tag_closure.id_ancestor').distinct(), '>=', tagIds.length)
|
||||
.as('has_tags'),
|
||||
(join) => join.onRef('has_tags.assetsId', '=', 'asset.id'),
|
||||
(join) => join.onRef('has_tags.assetId', '=', 'asset.id'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -285,8 +285,8 @@ export function withTags(eb: ExpressionBuilder<DB, 'asset'>) {
|
|||
eb
|
||||
.selectFrom('tag')
|
||||
.select(columns.tag)
|
||||
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagsId')
|
||||
.whereRef('asset.id', '=', 'tag_asset.assetsId'),
|
||||
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagId')
|
||||
.whereRef('asset.id', '=', 'tag_asset.assetId'),
|
||||
).as('tags');
|
||||
}
|
||||
|
||||
|
|
@ -299,8 +299,8 @@ export function withTagId<O>(qb: SelectQueryBuilder<DB, 'asset', O>, tagId: stri
|
|||
eb.exists(
|
||||
eb
|
||||
.selectFrom('tag_closure')
|
||||
.innerJoin('tag_asset', 'tag_asset.tagsId', 'tag_closure.id_descendant')
|
||||
.whereRef('tag_asset.assetsId', '=', 'asset.id')
|
||||
.innerJoin('tag_asset', 'tag_asset.tagId', 'tag_closure.id_descendant')
|
||||
.whereRef('tag_asset.assetId', '=', 'asset.id')
|
||||
.where('tag_closure.id_ancestor', '=', tagId),
|
||||
),
|
||||
);
|
||||
|
|
@ -320,7 +320,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
|
|||
.$if(!!options.albumIds && options.albumIds.length > 0, (qb) => inAlbums(qb, options.albumIds!))
|
||||
.$if(!!options.tagIds && options.tagIds.length > 0, (qb) => hasTags(qb, options.tagIds!))
|
||||
.$if(options.tagIds === null, (qb) =>
|
||||
qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('tag_asset').whereRef('assetsId', '=', 'asset.id')))),
|
||||
qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('tag_asset').whereRef('assetId', '=', 'asset.id')))),
|
||||
)
|
||||
.$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!))
|
||||
.$if(!!options.createdBefore, (qb) => qb.where('asset.createdAt', '<=', options.createdBefore!))
|
||||
|
|
@ -403,7 +403,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
|
|||
qb.where('asset.livePhotoVideoId', options.isMotion ? 'is not' : 'is', null),
|
||||
)
|
||||
.$if(!!options.isNotInAlbum && (!options.albumIds || options.albumIds.length === 0), (qb) =>
|
||||
qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('album_asset').whereRef('assetsId', '=', 'asset.id')))),
|
||||
qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('album_asset').whereRef('assetId', '=', 'asset.id')))),
|
||||
)
|
||||
.$if(!!options.withExif, withExifInner)
|
||||
.$if(!!(options.withFaces || options.withPeople || options.personIds), (qb) => qb.select(withFacesAndPeople))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue