refactor: database column names (#23356)

This commit is contained in:
Jason Rasmussen 2025-11-04 16:03:21 -05:00 committed by GitHub
parent 0df70365d7
commit 29c14a3f58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 467 additions and 368 deletions

View file

@ -106,14 +106,14 @@ SELECT "user"."email", "asset"."type", COUNT(*) FROM "asset"
```sql title="Count by tag" ```sql title="Count by tag"
SELECT "t"."value" AS "tag_name", COUNT(*) AS "number_assets" FROM "tag" "t" SELECT "t"."value" AS "tag_name", COUNT(*) AS "number_assets" FROM "tag" "t"
JOIN "tag_asset" "ta" ON "t"."id" = "ta"."tagsId" JOIN "asset" "a" ON "ta"."assetsId" = "a"."id" JOIN "tag_asset" "ta" ON "t"."id" = "ta"."tagId" JOIN "asset" "a" ON "ta"."assetId" = "a"."id"
WHERE "a"."visibility" != 'hidden' WHERE "a"."visibility" != 'hidden'
GROUP BY "t"."value" ORDER BY "number_assets" DESC; GROUP BY "t"."value" ORDER BY "number_assets" DESC;
``` ```
```sql title="Count by tag (per user)" ```sql title="Count by tag (per user)"
SELECT "t"."value" AS "tag_name", "u"."email" as "user_email", COUNT(*) AS "number_assets" FROM "tag" "t" SELECT "t"."value" AS "tag_name", "u"."email" as "user_email", COUNT(*) AS "number_assets" FROM "tag" "t"
JOIN "tag_asset" "ta" ON "t"."id" = "ta"."tagsId" JOIN "asset" "a" ON "ta"."assetsId" = "a"."id" JOIN "user" "u" ON "a"."ownerId" = "u"."id" JOIN "tag_asset" "ta" ON "t"."id" = "ta"."tagId" JOIN "asset" "a" ON "ta"."assetId" = "a"."id" JOIN "user" "u" ON "a"."ownerId" = "u"."id"
WHERE "a"."visibility" != 'hidden' WHERE "a"."visibility" != 'hidden'
GROUP BY "t"."value", "u"."email" ORDER BY "number_assets" DESC; GROUP BY "t"."value", "u"."email" ORDER BY "number_assets" DESC;
``` ```

View file

@ -356,7 +356,7 @@ export const columns = {
'asset.stackId', 'asset.stackId',
'asset.libraryId', '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'], syncStack: ['stack.id', 'stack.createdAt', 'stack.updatedAt', 'stack.primaryAssetId', 'stack.ownerId'],
syncUser: ['id', 'name', 'email', 'avatarColor', 'deletedAt', 'updateId', 'profileImagePath', 'profileChangedAt'], syncUser: ['id', 'name', 'email', 'avatarColor', 'deletedAt', 'updateId', 'profileImagePath', 'profileChangedAt'],
stack: ['stack.id', 'stack.primaryAssetId', 'ownerId'], stack: ['stack.id', 'stack.primaryAssetId', 'ownerId'],

View file

@ -25,8 +25,8 @@ select
"album"."id" "album"."id"
from from
"album" "album"
left join "album_user" as "albumUsers" on "albumUsers"."albumsId" = "album"."id" left join "album_user" as "albumUsers" on "albumUsers"."albumId" = "album"."id"
left join "user" on "user"."id" = "albumUsers"."usersId" left join "user" on "user"."id" = "albumUsers"."userId"
and "user"."deletedAt" is null and "user"."deletedAt" is null
where where
"album"."id" in ($1) "album"."id" in ($1)
@ -52,8 +52,8 @@ select
"album"."id" "album"."id"
from from
"album" "album"
left join "album_user" on "album_user"."albumsId" = "album"."id" left join "album_user" on "album_user"."albumId" = "album"."id"
left join "user" on "user"."id" = "album_user"."usersId" left join "user" on "user"."id" = "album_user"."userId"
and "user"."deletedAt" is null and "user"."deletedAt" is null
where where
"album"."id" in ($1) "album"."id" in ($1)
@ -81,11 +81,11 @@ select
"asset"."livePhotoVideoId" "asset"."livePhotoVideoId"
from from
"album" "album"
inner join "album_asset" as "albumAssets" on "album"."id" = "albumAssets"."albumsId" inner join "album_asset" as "albumAssets" on "album"."id" = "albumAssets"."albumId"
inner join "asset" on "asset"."id" = "albumAssets"."assetsId" inner join "asset" on "asset"."id" = "albumAssets"."assetId"
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
left join "album_user" as "albumUsers" on "albumUsers"."albumsId" = "album"."id" left join "album_user" as "albumUsers" on "albumUsers"."albumId" = "album"."id"
left join "user" on "user"."id" = "albumUsers"."usersId" left join "user" on "user"."id" = "albumUsers"."userId"
and "user"."deletedAt" is null and "user"."deletedAt" is null
cross join "target" cross join "target"
where where
@ -136,11 +136,11 @@ from
"shared_link" "shared_link"
left join "album" on "album"."id" = "shared_link"."albumId" left join "album" on "album"."id" = "shared_link"."albumId"
and "album"."deletedAt" is null and "album"."deletedAt" is null
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 "asset" on "asset"."id" = "shared_link_asset"."assetsId" left join "asset" on "asset"."id" = "shared_link_asset"."assetId"
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
left join "album_asset" on "album_asset"."albumsId" = "album"."id" left join "album_asset" on "album_asset"."albumId" = "album"."id"
left join "asset" as "albumAssets" on "albumAssets"."id" = "album_asset"."assetsId" left join "asset" as "albumAssets" on "albumAssets"."id" = "album_asset"."assetId"
and "albumAssets"."deletedAt" is null and "albumAssets"."deletedAt" is null
where where
"shared_link"."id" = $1 "shared_link"."id" = $1

View file

@ -43,13 +43,13 @@ select
from from
"user" "user"
where where
"user"."id" = "album_user"."usersId" "user"."id" = "album_user"."userId"
) as obj ) as obj
) as "user" ) as "user"
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
) as agg ) as agg
) as "albumUsers", ) as "albumUsers",
( (
@ -76,9 +76,9 @@ select
from from
"asset" "asset"
left join "asset_exif" on "asset"."id" = "asset_exif"."assetId" 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 where
"album_asset"."albumsId" = "album"."id" "album_asset"."albumId" = "album"."id"
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
and "asset"."visibility" in ('archive', 'timeline') and "asset"."visibility" in ('archive', 'timeline')
order by order by
@ -134,18 +134,18 @@ select
from from
"user" "user"
where where
"user"."id" = "album_user"."usersId" "user"."id" = "album_user"."userId"
) as obj ) as obj
) as "user" ) as "user"
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
) as agg ) as agg
) as "albumUsers" ) as "albumUsers"
from from
"album" "album"
inner join "album_asset" on "album_asset"."albumsId" = "album"."id" inner join "album_asset" on "album_asset"."albumId" = "album"."id"
where where
( (
"album"."ownerId" = $1 "album"."ownerId" = $1
@ -154,11 +154,11 @@ where
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
and "album_user"."usersId" = $2 and "album_user"."userId" = $2
) )
) )
and "album_asset"."assetsId" = $3 and "album_asset"."assetId" = $3
and "album"."deletedAt" is null and "album"."deletedAt" is null
order by order by
"album"."createdAt" desc, "album"."createdAt" desc,
@ -166,7 +166,7 @@ order by
-- AlbumRepository.getMetadataForIds -- AlbumRepository.getMetadataForIds
select select
"album_asset"."albumsId" as "albumId", "album_asset"."albumId" as "albumId",
min( min(
("asset"."localDateTime" AT TIME ZONE 'UTC'::text)::date ("asset"."localDateTime" AT TIME ZONE 'UTC'::text)::date
) as "startDate", ) as "startDate",
@ -177,13 +177,13 @@ select
count("asset"."id")::int as "assetCount" count("asset"."id")::int as "assetCount"
from from
"asset" "asset"
inner join "album_asset" on "album_asset"."assetsId" = "asset"."id" inner join "album_asset" on "album_asset"."assetId" = "asset"."id"
where where
"asset"."visibility" in ('archive', 'timeline') "asset"."visibility" in ('archive', 'timeline')
and "album_asset"."albumsId" in ($1) and "album_asset"."albumId" in ($1)
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
group by group by
"album_asset"."albumsId" "album_asset"."albumId"
-- AlbumRepository.getOwned -- AlbumRepository.getOwned
select select
@ -228,13 +228,13 @@ select
from from
"user" "user"
where where
"user"."id" = "album_user"."usersId" "user"."id" = "album_user"."userId"
) as obj ) as obj
) as "user" ) as "user"
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
) as agg ) as agg
) as "albumUsers", ) as "albumUsers",
( (
@ -283,13 +283,13 @@ select
from from
"user" "user"
where where
"user"."id" = "album_user"."usersId" "user"."id" = "album_user"."userId"
) as obj ) as obj
) as "user" ) as "user"
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
) as agg ) as agg
) as "albumUsers", ) as "albumUsers",
( (
@ -332,10 +332,10 @@ where
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
and ( and (
"album"."ownerId" = $1 "album"."ownerId" = $1
or "album_user"."usersId" = $2 or "album_user"."userId" = $2
) )
) )
or exists ( or exists (
@ -382,7 +382,7 @@ where
from from
"album_user" "album_user"
where where
"album_user"."albumsId" = "album"."id" "album_user"."albumId" = "album"."id"
) )
and not exists ( and not exists (
select select
@ -397,7 +397,7 @@ order by
-- AlbumRepository.removeAssetsFromAll -- AlbumRepository.removeAssetsFromAll
delete from "album_asset" delete from "album_asset"
where where
"album_asset"."assetsId" in ($1) "album_asset"."assetId" in ($1)
-- AlbumRepository.getAssetIds -- AlbumRepository.getAssetIds
select select
@ -405,8 +405,8 @@ select
from from
"album_asset" "album_asset"
where where
"album_asset"."albumsId" = $1 "album_asset"."albumId" = $1
and "album_asset"."assetsId" in ($2) and "album_asset"."assetId" in ($2)
-- AlbumRepository.getContributorCounts -- AlbumRepository.getContributorCounts
select select
@ -414,10 +414,10 @@ select
count(*) as "assetCount" count(*) as "assetCount"
from from
"album_asset" "album_asset"
inner join "asset" on "asset"."id" = "assetsId" inner join "asset" on "asset"."id" = "assetId"
where where
"asset"."deletedAt" is null "asset"."deletedAt" is null
and "album_asset"."albumsId" = $1 and "album_asset"."albumId" = $1
group by group by
"asset"."ownerId" "asset"."ownerId"
order by order by
@ -427,10 +427,10 @@ order by
insert into insert into
"album_asset" "album_asset"
select select
"album_asset"."albumsId", "album_asset"."albumId",
$1 as "assetsId" $1 as "assetId"
from from
"album_asset" "album_asset"
where where
"album_asset"."assetsId" = $2 "album_asset"."assetId" = $2
on conflict do nothing on conflict do nothing

View file

@ -2,12 +2,12 @@
-- AlbumUserRepository.create -- AlbumUserRepository.create
insert into insert into
"album_user" ("usersId", "albumsId") "album_user" ("userId", "albumId")
values values
($1, $2) ($1, $2)
returning returning
"usersId", "userId",
"albumsId", "albumId",
"role" "role"
-- AlbumUserRepository.update -- AlbumUserRepository.update
@ -15,13 +15,13 @@ update "album_user"
set set
"role" = $1 "role" = $1
where where
"usersId" = $2 "userId" = $2
and "albumsId" = $3 and "albumId" = $3
returning returning
* *
-- AlbumUserRepository.delete -- AlbumUserRepository.delete
delete from "album_user" delete from "album_user"
where where
"usersId" = $1 "userId" = $1
and "albumsId" = $2 and "albumId" = $2

View file

@ -31,9 +31,9 @@ select
"tag"."value" "tag"."value"
from from
"tag" "tag"
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId" inner join "tag_asset" on "tag"."id" = "tag_asset"."tagId"
where where
"asset"."id" = "tag_asset"."assetsId" "asset"."id" = "tag_asset"."assetId"
) as agg ) as agg
) as "tags" ) as "tags"
from from

View file

@ -160,9 +160,9 @@ select
"tag"."parentId" "tag"."parentId"
from from
"tag" "tag"
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId" inner join "tag_asset" on "tag"."id" = "tag_asset"."tagId"
where where
"asset"."id" = "tag_asset"."assetsId" "asset"."id" = "tag_asset"."assetId"
) as agg ) as agg
) as "tags", ) as "tags",
to_json("asset_exif") as "exifInfo" to_json("asset_exif") as "exifInfo"

View file

@ -23,8 +23,8 @@ where
from from
"album_asset" "album_asset"
where where
"asset"."id" = "album_asset"."assetsId" "asset"."id" = "album_asset"."assetId"
and "album_asset"."albumsId" in ($3) and "album_asset"."albumId" in ($3)
) )
) )
order by order by

View file

@ -37,7 +37,7 @@ select
"asset".* "asset".*
from from
"asset" "asset"
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId" inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
where where
"memory_asset"."memoriesId" = "memory"."id" "memory_asset"."memoriesId" = "memory"."id"
and "asset"."visibility" = 'timeline' and "asset"."visibility" = 'timeline'
@ -66,7 +66,7 @@ select
"asset".* "asset".*
from from
"asset" "asset"
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId" inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
where where
"memory_asset"."memoriesId" = "memory"."id" "memory_asset"."memoriesId" = "memory"."id"
and "asset"."visibility" = 'timeline' and "asset"."visibility" = 'timeline'
@ -104,7 +104,7 @@ select
"asset".* "asset".*
from from
"asset" "asset"
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId" inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
where where
"memory_asset"."memoriesId" = "memory"."id" "memory_asset"."memoriesId" = "memory"."id"
and "asset"."visibility" = 'timeline' and "asset"."visibility" = 'timeline'
@ -137,7 +137,7 @@ select
"asset".* "asset".*
from from
"asset" "asset"
inner join "memory_asset" on "asset"."id" = "memory_asset"."assetsId" inner join "memory_asset" on "asset"."id" = "memory_asset"."assetId"
where where
"memory_asset"."memoriesId" = "memory"."id" "memory_asset"."memoriesId" = "memory"."id"
and "asset"."visibility" = 'timeline' and "asset"."visibility" = 'timeline'
@ -159,15 +159,15 @@ where
-- MemoryRepository.getAssetIds -- MemoryRepository.getAssetIds
select select
"assetsId" "assetId"
from from
"memory_asset" "memory_asset"
where where
"memoriesId" = $1 "memoriesId" = $1
and "assetsId" in ($2) and "assetId" in ($2)
-- MemoryRepository.addAssetIds -- MemoryRepository.addAssetIds
insert into insert into
"memory_asset" ("memoriesId", "assetsId") "memory_asset" ("memoriesId", "assetId")
values values
($1, $2) ($1, $2)

View file

@ -4,10 +4,10 @@
insert into insert into
"shared_link_asset" "shared_link_asset"
select select
$1 as "assetsId", $1 as "assetId",
"shared_link_asset"."sharedLinksId" "shared_link_asset"."sharedLinkId"
from from
"shared_link_asset" "shared_link_asset"
where where
"shared_link_asset"."assetsId" = $2 "shared_link_asset"."assetId" = $2
on conflict do nothing on conflict do nothing

View file

@ -19,7 +19,7 @@ from
to_json("exifInfo") as "exifInfo" to_json("exifInfo") as "exifInfo"
from from
"shared_link_asset" "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 ( inner join lateral (
select select
"asset_exif".* "asset_exif".*
@ -29,7 +29,7 @@ from
"asset_exif"."assetId" = "asset"."id" "asset_exif"."assetId" = "asset"."id"
) as "exifInfo" on true ) as "exifInfo" on true
where where
"shared_link"."id" = "shared_link_asset"."sharedLinksId" "shared_link"."id" = "shared_link_asset"."sharedLinkId"
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
order by order by
"asset"."fileCreatedAt" asc "asset"."fileCreatedAt" asc
@ -51,7 +51,7 @@ from
to_json("owner") as "owner" to_json("owner") as "owner"
from from
"album" "album"
left join "album_asset" on "album_asset"."albumsId" = "album"."id" left join "album_asset" on "album_asset"."albumId" = "album"."id"
left join lateral ( left join lateral (
select select
"asset".*, "asset".*,
@ -67,7 +67,7 @@ from
"asset_exif"."assetId" = "asset"."id" "asset_exif"."assetId" = "asset"."id"
) as "exifInfo" on true ) as "exifInfo" on true
where where
"album_asset"."assetsId" = "asset"."id" "album_asset"."assetId" = "asset"."id"
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
order by order by
"asset"."fileCreatedAt" asc "asset"."fileCreatedAt" asc
@ -108,14 +108,14 @@ select distinct
to_json("album") as "album" to_json("album") as "album"
from from
"shared_link" "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 ( left join lateral (
select select
json_agg("asset") as "assets" json_agg("asset") as "assets"
from from
"asset" "asset"
where where
"asset"."id" = "shared_link_asset"."assetsId" "asset"."id" = "shared_link_asset"."assetId"
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
) as "assets" on true ) as "assets" on true
left join lateral ( left join lateral (

View file

@ -89,9 +89,9 @@ select
"tag"."parentId" "tag"."parentId"
from from
"tag" "tag"
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId" inner join "tag_asset" on "tag"."id" = "tag_asset"."tagId"
where where
"tag_asset"."assetsId" = "asset"."id" "tag_asset"."assetId" = "asset"."id"
) as agg ) as agg
) as "tags", ) as "tags",
to_json("exifInfo") as "exifInfo" to_json("exifInfo") as "exifInfo"

View file

@ -2,12 +2,12 @@
-- SyncRepository.album.getCreatedAfter -- SyncRepository.album.getCreatedAfter
select select
"albumsId" as "id", "albumId" as "id",
"createId" "createId"
from from
"album_user" "album_user"
where where
"usersId" = $1 "userId" = $1
and "createId" >= $2 and "createId" >= $2
and "createId" < $3 and "createId" < $3
order by order by
@ -40,13 +40,13 @@ select distinct
"album"."updateId" "album"."updateId"
from from
"album" as "album" "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 where
"album"."updateId" < $1 "album"."updateId" < $1
and "album"."updateId" > $2 and "album"."updateId" > $2
and ( and (
"album"."ownerId" = $3 "album"."ownerId" = $3
or "album_users"."usersId" = $4 or "album_users"."userId" = $4
) )
order by order by
"album"."updateId" asc "album"."updateId" asc
@ -72,12 +72,12 @@ select
"album_asset"."updateId" "album_asset"."updateId"
from from
"album_asset" as "album_asset" "album_asset" as "album_asset"
inner join "asset" on "asset"."id" = "album_asset"."assetsId" inner join "asset" on "asset"."id" = "album_asset"."assetId"
where where
"album_asset"."updateId" < $1 "album_asset"."updateId" < $1
and "album_asset"."updateId" <= $2 and "album_asset"."updateId" <= $2
and "album_asset"."updateId" >= $3 and "album_asset"."updateId" >= $3
and "album_asset"."albumsId" = $4 and "album_asset"."albumId" = $4
order by order by
"album_asset"."updateId" asc "album_asset"."updateId" asc
@ -102,16 +102,16 @@ select
"asset"."updateId" "asset"."updateId"
from from
"asset" as "asset" "asset" as "asset"
inner join "album_asset" on "album_asset"."assetsId" = "asset"."id" inner join "album_asset" on "album_asset"."assetId" = "asset"."id"
inner join "album" on "album"."id" = "album_asset"."albumsId" inner join "album" on "album"."id" = "album_asset"."albumId"
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId" left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where where
"asset"."updateId" < $1 "asset"."updateId" < $1
and "asset"."updateId" > $2 and "asset"."updateId" > $2
and "album_asset"."updateId" <= $3 and "album_asset"."updateId" <= $3
and ( and (
"album"."ownerId" = $4 "album"."ownerId" = $4
or "album_user"."usersId" = $5 or "album_user"."userId" = $5
) )
order by order by
"asset"."updateId" asc "asset"."updateId" asc
@ -137,15 +137,15 @@ select
"asset"."libraryId" "asset"."libraryId"
from from
"album_asset" as "album_asset" "album_asset" as "album_asset"
inner join "asset" on "asset"."id" = "album_asset"."assetsId" inner join "asset" on "asset"."id" = "album_asset"."assetId"
inner join "album" on "album"."id" = "album_asset"."albumsId" inner join "album" on "album"."id" = "album_asset"."albumId"
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId" left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where where
"album_asset"."updateId" < $1 "album_asset"."updateId" < $1
and "album_asset"."updateId" > $2 and "album_asset"."updateId" > $2
and ( and (
"album"."ownerId" = $3 "album"."ownerId" = $3
or "album_user"."usersId" = $4 or "album_user"."userId" = $4
) )
order by order by
"album_asset"."updateId" asc "album_asset"."updateId" asc
@ -180,12 +180,12 @@ select
"album_asset"."updateId" "album_asset"."updateId"
from from
"album_asset" as "album_asset" "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 where
"album_asset"."updateId" < $1 "album_asset"."updateId" < $1
and "album_asset"."updateId" <= $2 and "album_asset"."updateId" <= $2
and "album_asset"."updateId" >= $3 and "album_asset"."updateId" >= $3
and "album_asset"."albumsId" = $4 and "album_asset"."albumId" = $4
order by order by
"album_asset"."updateId" asc "album_asset"."updateId" asc
@ -219,16 +219,16 @@ select
"asset_exif"."updateId" "asset_exif"."updateId"
from from
"asset_exif" as "asset_exif" "asset_exif" as "asset_exif"
inner join "album_asset" on "album_asset"."assetsId" = "asset_exif"."assetId" inner join "album_asset" on "album_asset"."assetId" = "asset_exif"."assetId"
inner join "album" on "album"."id" = "album_asset"."albumsId" inner join "album" on "album"."id" = "album_asset"."albumId"
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId" left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where where
"asset_exif"."updateId" < $1 "asset_exif"."updateId" < $1
and "asset_exif"."updateId" > $2 and "asset_exif"."updateId" > $2
and "album_asset"."updateId" <= $3 and "album_asset"."updateId" <= $3
and ( and (
"album"."ownerId" = $4 "album"."ownerId" = $4
or "album_user"."usersId" = $5 or "album_user"."userId" = $5
) )
order by order by
"asset_exif"."updateId" asc "asset_exif"."updateId" asc
@ -263,23 +263,23 @@ select
"asset_exif"."fps" "asset_exif"."fps"
from from
"album_asset" as "album_asset" "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"
inner join "album" on "album"."id" = "album_asset"."albumsId" inner join "album" on "album"."id" = "album_asset"."albumId"
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId" left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where where
"album_asset"."updateId" < $1 "album_asset"."updateId" < $1
and "album_asset"."updateId" > $2 and "album_asset"."updateId" > $2
and ( and (
"album"."ownerId" = $3 "album"."ownerId" = $3
or "album_user"."usersId" = $4 or "album_user"."userId" = $4
) )
order by order by
"album_asset"."updateId" asc "album_asset"."updateId" asc
-- SyncRepository.albumToAsset.getBackfill -- SyncRepository.albumToAsset.getBackfill
select select
"album_asset"."assetsId" as "assetId", "album_asset"."assetId" as "assetId",
"album_asset"."albumsId" as "albumId", "album_asset"."albumId" as "albumId",
"album_asset"."updateId" "album_asset"."updateId"
from from
"album_asset" as "album_asset" "album_asset" as "album_asset"
@ -287,7 +287,7 @@ where
"album_asset"."updateId" < $1 "album_asset"."updateId" < $1
and "album_asset"."updateId" <= $2 and "album_asset"."updateId" <= $2
and "album_asset"."updateId" >= $3 and "album_asset"."updateId" >= $3
and "album_asset"."albumsId" = $4 and "album_asset"."albumId" = $4
order by order by
"album_asset"."updateId" asc "album_asset"."updateId" asc
@ -311,11 +311,11 @@ where
union union
( (
select select
"album_user"."albumsId" as "id" "album_user"."albumId" as "id"
from from
"album_user" "album_user"
where where
"album_user"."usersId" = $4 "album_user"."userId" = $4
) )
) )
order by order by
@ -323,27 +323,27 @@ order by
-- SyncRepository.albumToAsset.getUpserts -- SyncRepository.albumToAsset.getUpserts
select select
"album_asset"."assetsId" as "assetId", "album_asset"."assetId" as "assetId",
"album_asset"."albumsId" as "albumId", "album_asset"."albumId" as "albumId",
"album_asset"."updateId" "album_asset"."updateId"
from from
"album_asset" as "album_asset" "album_asset" as "album_asset"
inner join "album" on "album"."id" = "album_asset"."albumsId" inner join "album" on "album"."id" = "album_asset"."albumId"
left join "album_user" on "album_user"."albumsId" = "album_asset"."albumsId" left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where where
"album_asset"."updateId" < $1 "album_asset"."updateId" < $1
and "album_asset"."updateId" > $2 and "album_asset"."updateId" > $2
and ( and (
"album"."ownerId" = $3 "album"."ownerId" = $3
or "album_user"."usersId" = $4 or "album_user"."userId" = $4
) )
order by order by
"album_asset"."updateId" asc "album_asset"."updateId" asc
-- SyncRepository.albumUser.getBackfill -- SyncRepository.albumUser.getBackfill
select select
"album_user"."albumsId" as "albumId", "album_user"."albumId" as "albumId",
"album_user"."usersId" as "userId", "album_user"."userId" as "userId",
"album_user"."role", "album_user"."role",
"album_user"."updateId" "album_user"."updateId"
from from
@ -352,7 +352,7 @@ where
"album_user"."updateId" < $1 "album_user"."updateId" < $1
and "album_user"."updateId" <= $2 and "album_user"."updateId" <= $2
and "album_user"."updateId" >= $3 and "album_user"."updateId" >= $3
and "albumsId" = $4 and "albumId" = $4
order by order by
"album_user"."updateId" asc "album_user"."updateId" asc
@ -376,11 +376,11 @@ where
union union
( (
select select
"album_user"."albumsId" as "id" "album_user"."albumId" as "id"
from from
"album_user" "album_user"
where where
"album_user"."usersId" = $4 "album_user"."userId" = $4
) )
) )
order by order by
@ -388,8 +388,8 @@ order by
-- SyncRepository.albumUser.getUpserts -- SyncRepository.albumUser.getUpserts
select select
"album_user"."albumsId" as "albumId", "album_user"."albumId" as "albumId",
"album_user"."usersId" as "userId", "album_user"."userId" as "userId",
"album_user"."role", "album_user"."role",
"album_user"."updateId" "album_user"."updateId"
from from
@ -397,7 +397,7 @@ from
where where
"album_user"."updateId" < $1 "album_user"."updateId" < $1
and "album_user"."updateId" > $2 and "album_user"."updateId" > $2
and "album_user"."albumsId" in ( and "album_user"."albumId" in (
select select
"id" "id"
from from
@ -407,11 +407,11 @@ where
union union
( (
select select
"albumUsers"."albumsId" as "id" "albumUsers"."albumId" as "id"
from from
"album_user" as "albumUsers" "album_user" as "albumUsers"
where where
"albumUsers"."usersId" = $4 "albumUsers"."userId" = $4
) )
) )
order by order by
@ -656,7 +656,7 @@ order by
-- SyncRepository.memoryToAsset.getUpserts -- SyncRepository.memoryToAsset.getUpserts
select select
"memoriesId" as "memoryId", "memoriesId" as "memoryId",
"assetsId" as "assetId", "assetId" as "assetId",
"updateId" "updateId"
from from
"memory_asset" as "memory_asset" "memory_asset" as "memory_asset"

View file

@ -84,15 +84,15 @@ where
-- TagRepository.addAssetIds -- TagRepository.addAssetIds
insert into insert into
"tag_asset" ("tagsId", "assetsId") "tag_asset" ("tagId", "assetId")
values values
($1, $2) ($1, $2)
-- TagRepository.removeAssetIds -- TagRepository.removeAssetIds
delete from "tag_asset" delete from "tag_asset"
where where
"tagsId" = $1 "tagId" = $1
and "assetsId" in ($2) and "assetId" in ($2)
-- TagRepository.upsertAssetIds -- TagRepository.upsertAssetIds
insert into insert into
@ -107,9 +107,9 @@ returning
begin begin
delete from "tag_asset" delete from "tag_asset"
where where
"assetsId" = $1 "assetId" = $1
insert into insert into
"tag_asset" ("tagsId", "assetsId") "tag_asset" ("tagId", "assetId")
values values
($1, $2) ($1, $2)
on conflict do nothing on conflict do nothing

View file

@ -52,8 +52,8 @@ class ActivityAccess {
return this.db return this.db
.selectFrom('album') .selectFrom('album')
.select('album.id') .select('album.id')
.leftJoin('album_user as albumUsers', 'albumUsers.albumsId', 'album.id') .leftJoin('album_user as albumUsers', 'albumUsers.albumId', 'album.id')
.leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.usersId').on('user.deletedAt', 'is', null)) .leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.userId').on('user.deletedAt', 'is', null))
.where('album.id', 'in', [...albumIds]) .where('album.id', 'in', [...albumIds])
.where('album.isActivityEnabled', '=', true) .where('album.isActivityEnabled', '=', true)
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('user.id', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('user.id', '=', userId)]))
@ -96,8 +96,8 @@ class AlbumAccess {
return this.db return this.db
.selectFrom('album') .selectFrom('album')
.select('album.id') .select('album.id')
.leftJoin('album_user', 'album_user.albumsId', 'album.id') .leftJoin('album_user', 'album_user.albumId', 'album.id')
.leftJoin('user', (join) => join.onRef('user.id', '=', 'album_user.usersId').on('user.deletedAt', 'is', null)) .leftJoin('user', (join) => join.onRef('user.id', '=', 'album_user.userId').on('user.deletedAt', 'is', null))
.where('album.id', 'in', [...albumIds]) .where('album.id', 'in', [...albumIds])
.where('album.deletedAt', 'is', null) .where('album.deletedAt', 'is', null)
.where('user.id', '=', userId) .where('user.id', '=', userId)
@ -138,12 +138,12 @@ class AssetAccess {
return this.db return this.db
.with('target', (qb) => qb.selectNoFrom(sql`array[${sql.join([...assetIds])}]::uuid[]`.as('ids'))) .with('target', (qb) => qb.selectNoFrom(sql`array[${sql.join([...assetIds])}]::uuid[]`.as('ids')))
.selectFrom('album') .selectFrom('album')
.innerJoin('album_asset as albumAssets', 'album.id', 'albumAssets.albumsId') .innerJoin('album_asset as albumAssets', 'album.id', 'albumAssets.albumId')
.innerJoin('asset', (join) => .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('album_user as albumUsers', 'albumUsers.albumId', 'album.id')
.leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.usersId').on('user.deletedAt', 'is', null)) .leftJoin('user', (join) => join.onRef('user.id', '=', 'albumUsers.userId').on('user.deletedAt', 'is', null))
.crossJoin('target') .crossJoin('target')
.select(['asset.id', 'asset.livePhotoVideoId']) .select(['asset.id', 'asset.livePhotoVideoId'])
.where((eb) => .where((eb) =>
@ -223,13 +223,13 @@ class AssetAccess {
return this.db return this.db
.selectFrom('shared_link') .selectFrom('shared_link')
.leftJoin('album', (join) => join.onRef('album.id', '=', 'shared_link.albumId').on('album.deletedAt', 'is', null)) .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) => .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) => .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([ .select([
'asset.id as assetId', 'asset.id as assetId',

View file

@ -7,36 +7,36 @@ import { DB } from 'src/schema';
import { AlbumUserTable } from 'src/schema/tables/album-user.table'; import { AlbumUserTable } from 'src/schema/tables/album-user.table';
export type AlbumPermissionId = { export type AlbumPermissionId = {
albumsId: string; albumId: string;
usersId: string; userId: string;
}; };
@Injectable() @Injectable()
export class AlbumUserRepository { export class AlbumUserRepository {
constructor(@InjectKysely() private db: Kysely<DB>) {} 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>) { create(albumUser: Insertable<AlbumUserTable>) {
return this.db return this.db
.insertInto('album_user') .insertInto('album_user')
.values(albumUser) .values(albumUser)
.returning(['usersId', 'albumsId', 'role']) .returning(['userId', 'albumId', 'role'])
.executeTakeFirstOrThrow(); .executeTakeFirstOrThrow();
} }
@GenerateSql({ params: [{ usersId: DummyValue.UUID, albumsId: DummyValue.UUID }, { role: AlbumUserRole.Viewer }] }) @GenerateSql({ params: [{ userId: DummyValue.UUID, albumId: DummyValue.UUID }, { role: AlbumUserRole.Viewer }] })
update({ usersId, albumsId }: AlbumPermissionId, dto: Updateable<AlbumUserTable>) { update({ userId, albumId }: AlbumPermissionId, dto: Updateable<AlbumUserTable>) {
return this.db return this.db
.updateTable('album_user') .updateTable('album_user')
.set(dto) .set(dto)
.where('usersId', '=', usersId) .where('userId', '=', userId)
.where('albumsId', '=', albumsId) .where('albumId', '=', albumId)
.returningAll() .returningAll()
.executeTakeFirstOrThrow(); .executeTakeFirstOrThrow();
} }
@GenerateSql({ params: [{ usersId: DummyValue.UUID, albumsId: DummyValue.UUID }] }) @GenerateSql({ params: [{ userId: DummyValue.UUID, albumId: DummyValue.UUID }] })
async delete({ usersId, albumsId }: AlbumPermissionId): Promise<void> { async delete({ userId, albumId }: AlbumPermissionId): Promise<void> {
await this.db.deleteFrom('album_user').where('usersId', '=', usersId).where('albumsId', '=', albumsId).execute(); await this.db.deleteFrom('album_user').where('userId', '=', userId).where('albumId', '=', albumId).execute();
} }
} }

View file

@ -33,11 +33,11 @@ const withAlbumUsers = (eb: ExpressionBuilder<DB, 'album'>) => {
.selectFrom('album_user') .selectFrom('album_user')
.select('album_user.role') .select('album_user.role')
.select((eb) => .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() .$notNull()
.as('user'), .as('user'),
) )
.whereRef('album_user.albumsId', '=', 'album.id'), .whereRef('album_user.albumId', '=', 'album.id'),
) )
.$notNull() .$notNull()
.as('albumUsers'); .as('albumUsers');
@ -57,8 +57,8 @@ const withAssets = (eb: ExpressionBuilder<DB, 'album'>) => {
.selectAll('asset') .selectAll('asset')
.leftJoin('asset_exif', 'asset.id', 'asset_exif.assetId') .leftJoin('asset_exif', 'asset.id', 'asset_exif.assetId')
.select((eb) => eb.table('asset_exif').$castTo<Exif>().as('exifInfo')) .select((eb) => eb.table('asset_exif').$castTo<Exif>().as('exifInfo'))
.innerJoin('album_asset', 'album_asset.assetsId', 'asset.id') .innerJoin('album_asset', 'album_asset.assetId', 'asset.id')
.whereRef('album_asset.albumsId', '=', 'album.id') .whereRef('album_asset.albumId', '=', 'album.id')
.where('asset.deletedAt', 'is', null) .where('asset.deletedAt', 'is', null)
.$call(withDefaultVisibility) .$call(withDefaultVisibility)
.orderBy('asset.fileCreatedAt', 'desc') .orderBy('asset.fileCreatedAt', 'desc')
@ -92,19 +92,19 @@ export class AlbumRepository {
return this.db return this.db
.selectFrom('album') .selectFrom('album')
.selectAll('album') .selectAll('album')
.innerJoin('album_asset', 'album_asset.albumsId', 'album.id') .innerJoin('album_asset', 'album_asset.albumId', 'album.id')
.where((eb) => .where((eb) =>
eb.or([ eb.or([
eb('album.ownerId', '=', ownerId), eb('album.ownerId', '=', ownerId),
eb.exists( eb.exists(
eb eb
.selectFrom('album_user') .selectFrom('album_user')
.whereRef('album_user.albumsId', '=', 'album.id') .whereRef('album_user.albumId', '=', 'album.id')
.where('album_user.usersId', '=', ownerId), .where('album_user.userId', '=', ownerId),
), ),
]), ]),
) )
.where('album_asset.assetsId', '=', assetId) .where('album_asset.assetId', '=', assetId)
.where('album.deletedAt', 'is', null) .where('album.deletedAt', 'is', null)
.orderBy('album.createdAt', 'desc') .orderBy('album.createdAt', 'desc')
.select(withOwner) .select(withOwner)
@ -125,16 +125,16 @@ export class AlbumRepository {
this.db this.db
.selectFrom('asset') .selectFrom('asset')
.$call(withDefaultVisibility) .$call(withDefaultVisibility)
.innerJoin('album_asset', 'album_asset.assetsId', 'asset.id') .innerJoin('album_asset', 'album_asset.assetId', 'asset.id')
.select('album_asset.albumsId as albumId') .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.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')) .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 // lastModifiedAssetTimestamp is only used in mobile app, please remove if not need
.select((eb) => eb.fn.max('asset.updatedAt').as('lastModifiedAssetTimestamp')) .select((eb) => eb.fn.max('asset.updatedAt').as('lastModifiedAssetTimestamp'))
.select((eb) => sql<number>`${eb.fn.count('asset.id')}::int`.as('assetCount')) .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) .where('asset.deletedAt', 'is', null)
.groupBy('album_asset.albumsId') .groupBy('album_asset.albumId')
.execute() .execute()
); );
} }
@ -166,8 +166,8 @@ export class AlbumRepository {
eb.exists( eb.exists(
eb eb
.selectFrom('album_user') .selectFrom('album_user')
.whereRef('album_user.albumsId', '=', 'album.id') .whereRef('album_user.albumId', '=', 'album.id')
.where((eb) => eb.or([eb('album.ownerId', '=', ownerId), eb('album_user.usersId', '=', ownerId)])), .where((eb) => eb.or([eb('album.ownerId', '=', ownerId), eb('album_user.userId', '=', ownerId)])),
), ),
eb.exists( eb.exists(
eb eb
@ -195,7 +195,7 @@ export class AlbumRepository {
.selectAll('album') .selectAll('album')
.where('album.ownerId', '=', ownerId) .where('album.ownerId', '=', ownerId)
.where('album.deletedAt', 'is', null) .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')))) .where((eb) => eb.not(eb.exists(eb.selectFrom('shared_link').whereRef('shared_link.albumId', '=', 'album.id'))))
.select(withOwner) .select(withOwner)
.orderBy('album.createdAt', 'desc') .orderBy('album.createdAt', 'desc')
@ -217,7 +217,7 @@ export class AlbumRepository {
@GenerateSql({ params: [[DummyValue.UUID]] }) @GenerateSql({ params: [[DummyValue.UUID]] })
@Chunked() @Chunked()
async removeAssetsFromAll(assetIds: string[]): Promise<void> { 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 }) @Chunked({ paramIndex: 1 })
@ -228,8 +228,8 @@ export class AlbumRepository {
await this.db await this.db
.deleteFrom('album_asset') .deleteFrom('album_asset')
.where('album_asset.albumsId', '=', albumId) .where('album_asset.albumId', '=', albumId)
.where('album_asset.assetsId', 'in', assetIds) .where('album_asset.assetId', 'in', assetIds)
.execute(); .execute();
} }
@ -250,10 +250,10 @@ export class AlbumRepository {
return this.db return this.db
.selectFrom('album_asset') .selectFrom('album_asset')
.selectAll() .selectAll()
.where('album_asset.albumsId', '=', albumId) .where('album_asset.albumId', '=', albumId)
.where('album_asset.assetsId', 'in', assetIds) .where('album_asset.assetId', 'in', assetIds)
.execute() .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> { async addAssetIds(albumId: string, assetIds: string[]): Promise<void> {
@ -276,7 +276,7 @@ export class AlbumRepository {
await tx await tx
.insertInto('album_user') .insertInto('album_user')
.values( .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(); .execute();
} }
@ -317,12 +317,12 @@ export class AlbumRepository {
await db await db
.insertInto('album_asset') .insertInto('album_asset')
.values(assetIds.map((assetId) => ({ albumsId: albumId, assetsId: assetId }))) .values(assetIds.map((assetId) => ({ albumId, assetId })))
.execute(); .execute();
} }
@Chunked({ chunkSize: 30_000 }) @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) { if (values.length === 0) {
return; return;
} }
@ -344,7 +344,7 @@ export class AlbumRepository {
.updateTable('album') .updateTable('album')
.set((eb) => ({ .set((eb) => ({
albumThumbnailAssetId: this.updateThumbnailBuilder(eb) albumThumbnailAssetId: this.updateThumbnailBuilder(eb)
.select('album_asset.assetsId') .select('album_asset.assetId')
.orderBy('asset.fileCreatedAt', 'desc') .orderBy('asset.fileCreatedAt', 'desc')
.limit(1), .limit(1),
})) }))
@ -360,7 +360,7 @@ export class AlbumRepository {
eb.exists( eb.exists(
this.updateThumbnailBuilder(eb) this.updateThumbnailBuilder(eb)
.select(sql`1`.as('1')) .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 return eb
.selectFrom('album_asset') .selectFrom('album_asset')
.innerJoin('asset', (join) => .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) { getContributorCounts(id: string) {
return this.db return this.db
.selectFrom('album_asset') .selectFrom('album_asset')
.innerJoin('asset', 'asset.id', 'assetsId') .innerJoin('asset', 'asset.id', 'assetId')
.where('asset.deletedAt', 'is', sql.lit(null)) .where('asset.deletedAt', 'is', sql.lit(null))
.where('album_asset.albumsId', '=', id) .where('album_asset.albumId', '=', id)
.select('asset.ownerId as userId') .select('asset.ownerId as userId')
.select((eb) => eb.fn.countAll<number>().as('assetCount')) .select((eb) => eb.fn.countAll<number>().as('assetCount'))
.groupBy('asset.ownerId') .groupBy('asset.ownerId')
@ -405,8 +405,8 @@ export class AlbumRepository {
.expression((eb) => .expression((eb) =>
eb eb
.selectFrom('album_asset') .selectFrom('album_asset')
.select((eb) => ['album_asset.albumsId', eb.val(targetAssetId).as('assetsId')]) .select((eb) => ['album_asset.albumId', eb.val(targetAssetId).as('assetId')])
.where('album_asset.assetsId', '=', sourceAssetId), .where('album_asset.assetId', '=', sourceAssetId),
) )
.onConflict((oc) => oc.doNothing()) .onConflict((oc) => oc.doNothing())
.execute(); .execute();

View file

@ -46,8 +46,8 @@ export class AssetJobRepository {
eb eb
.selectFrom('tag') .selectFrom('tag')
.select(['tag.value']) .select(['tag.value'])
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagsId') .innerJoin('tag_asset', 'tag.id', 'tag_asset.tagId')
.whereRef('asset.id', '=', 'tag_asset.assetsId'), .whereRef('asset.id', '=', 'tag_asset.assetId'),
).as('tags'), ).as('tags'),
) )
.limit(1) .limit(1)

View file

@ -563,8 +563,8 @@ export class AssetRepository {
.$if(!!options.visibility, (qb) => qb.where('asset.visibility', '=', options.visibility!)) .$if(!!options.visibility, (qb) => qb.where('asset.visibility', '=', options.visibility!))
.$if(!!options.albumId, (qb) => .$if(!!options.albumId, (qb) =>
qb qb
.innerJoin('album_asset', 'asset.id', 'album_asset.assetsId') .innerJoin('album_asset', 'asset.id', 'album_asset.assetId')
.where('album_asset.albumsId', '=', asUuid(options.albumId!)), .where('album_asset.albumId', '=', asUuid(options.albumId!)),
) )
.$if(!!options.personId, (qb) => hasPeople(qb, [options.personId!])) .$if(!!options.personId, (qb) => hasPeople(qb, [options.personId!]))
.$if(!!options.withStacked, (qb) => .$if(!!options.withStacked, (qb) =>
@ -641,8 +641,8 @@ export class AssetRepository {
eb.exists( eb.exists(
eb eb
.selectFrom('album_asset') .selectFrom('album_asset')
.whereRef('album_asset.assetsId', '=', 'asset.id') .whereRef('album_asset.assetId', '=', 'asset.id')
.where('album_asset.albumsId', '=', asUuid(options.albumId!)), .where('album_asset.albumId', '=', asUuid(options.albumId!)),
), ),
), ),
) )

View file

@ -26,8 +26,8 @@ export class DownloadRepository {
downloadAlbumId(albumId: string) { downloadAlbumId(albumId: string) {
return builder(this.db) return builder(this.db)
.innerJoin('album_asset', 'asset.id', 'album_asset.assetsId') .innerJoin('album_asset', 'asset.id', 'album_asset.assetId')
.where('album_asset.albumsId', '=', albumId) .where('album_asset.albumId', '=', albumId)
.stream(); .stream();
} }

View file

@ -126,8 +126,8 @@ export class MapRepository {
eb.exists((eb) => eb.exists((eb) =>
eb eb
.selectFrom('album_asset') .selectFrom('album_asset')
.whereRef('asset.id', '=', 'album_asset.assetsId') .whereRef('asset.id', '=', 'album_asset.assetId')
.where('album_asset.albumsId', 'in', albumIds), .where('album_asset.albumId', 'in', albumIds),
), ),
); );
} }

View file

@ -18,7 +18,7 @@ export class MemoryRepository implements IBulkAsset {
await this.db await this.db
.deleteFrom('memory_asset') .deleteFrom('memory_asset')
.using('asset') .using('asset')
.whereRef('memory_asset.assetsId', '=', 'asset.id') .whereRef('memory_asset.assetId', '=', 'asset.id')
.where('asset.visibility', '!=', AssetVisibility.Timeline) .where('asset.visibility', '!=', AssetVisibility.Timeline)
.execute(); .execute();
@ -64,7 +64,7 @@ export class MemoryRepository implements IBulkAsset {
eb eb
.selectFrom('asset') .selectFrom('asset')
.selectAll('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') .whereRef('memory_asset.memoriesId', '=', 'memory.id')
.orderBy('asset.fileCreatedAt', 'asc') .orderBy('asset.fileCreatedAt', 'asc')
.where('asset.visibility', '=', sql.lit(AssetVisibility.Timeline)) .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(); const { id } = await tx.insertInto('memory').values(memory).returning('id').executeTakeFirstOrThrow();
if (assetIds.size > 0) { 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(); await tx.insertInto('memory_asset').values(values).execute();
} }
@ -116,12 +116,12 @@ export class MemoryRepository implements IBulkAsset {
const results = await this.db const results = await this.db
.selectFrom('memory_asset') .selectFrom('memory_asset')
.select(['assetsId']) .select(['assetId'])
.where('memoriesId', '=', id) .where('memoriesId', '=', id)
.where('assetsId', 'in', assetIds) .where('assetId', 'in', assetIds)
.execute(); .execute();
return new Set(results.map(({ assetsId }) => assetsId)); return new Set(results.map(({ assetId }) => assetId));
} }
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] }) @GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
@ -132,7 +132,7 @@ export class MemoryRepository implements IBulkAsset {
await this.db await this.db
.insertInto('memory_asset') .insertInto('memory_asset')
.values(assetIds.map((assetId) => ({ memoriesId: id, assetsId: assetId }))) .values(assetIds.map((assetId) => ({ memoriesId: id, assetId })))
.execute(); .execute();
} }
@ -143,7 +143,7 @@ export class MemoryRepository implements IBulkAsset {
return; 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) { private getByIdBuilder(id: string) {
@ -155,7 +155,7 @@ export class MemoryRepository implements IBulkAsset {
eb eb
.selectFrom('asset') .selectFrom('asset')
.selectAll('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') .whereRef('memory_asset.memoriesId', '=', 'memory.id')
.orderBy('asset.fileCreatedAt', 'asc') .orderBy('asset.fileCreatedAt', 'asc')
.where('asset.visibility', '=', sql.lit(AssetVisibility.Timeline)) .where('asset.visibility', '=', sql.lit(AssetVisibility.Timeline))

View file

@ -6,15 +6,15 @@ import { DB } from 'src/schema';
export class SharedLinkAssetRepository { export class SharedLinkAssetRepository {
constructor(@InjectKysely() private db: Kysely<DB>) {} constructor(@InjectKysely() private db: Kysely<DB>) {}
async remove(sharedLinkId: string, assetsId: string[]) { async remove(sharedLinkId: string, assetId: string[]) {
const deleted = await this.db const deleted = await this.db
.deleteFrom('shared_link_asset') .deleteFrom('shared_link_asset')
.where('shared_link_asset.sharedLinksId', '=', sharedLinkId) .where('shared_link_asset.sharedLinkId', '=', sharedLinkId)
.where('shared_link_asset.assetsId', 'in', assetsId) .where('shared_link_asset.assetId', 'in', assetId)
.returning('assetsId') .returning('assetId')
.execute(); .execute();
return deleted.map((row) => row.assetsId); return deleted.map((row) => row.assetId);
} }
@GenerateSql({ params: [{ sourceAssetId: DummyValue.UUID, targetAssetId: DummyValue.UUID }] }) @GenerateSql({ params: [{ sourceAssetId: DummyValue.UUID, targetAssetId: DummyValue.UUID }] })
@ -24,8 +24,8 @@ export class SharedLinkAssetRepository {
.expression((eb) => .expression((eb) =>
eb eb
.selectFrom('shared_link_asset') .selectFrom('shared_link_asset')
.select((eb) => [eb.val(targetAssetId).as('assetsId'), 'shared_link_asset.sharedLinksId']) .select((eb) => [eb.val(targetAssetId).as('assetId'), 'shared_link_asset.sharedLinkId'])
.where('shared_link_asset.assetsId', '=', sourceAssetId), .where('shared_link_asset.assetId', '=', sourceAssetId),
) )
.onConflict((oc) => oc.doNothing()) .onConflict((oc) => oc.doNothing())
.execute(); .execute();

View file

@ -28,8 +28,8 @@ export class SharedLinkRepository {
(eb) => (eb) =>
eb eb
.selectFrom('shared_link_asset') .selectFrom('shared_link_asset')
.whereRef('shared_link.id', '=', 'shared_link_asset.sharedLinksId') .whereRef('shared_link.id', '=', 'shared_link_asset.sharedLinkId')
.innerJoin('asset', 'asset.id', 'shared_link_asset.assetsId') .innerJoin('asset', 'asset.id', 'shared_link_asset.assetId')
.where('asset.deletedAt', 'is', null) .where('asset.deletedAt', 'is', null)
.selectAll('asset') .selectAll('asset')
.innerJoinLateral( .innerJoinLateral(
@ -53,13 +53,13 @@ export class SharedLinkRepository {
.selectAll('album') .selectAll('album')
.whereRef('album.id', '=', 'shared_link.albumId') .whereRef('album.id', '=', 'shared_link.albumId')
.where('album.deletedAt', 'is', null) .where('album.deletedAt', 'is', null)
.leftJoin('album_asset', 'album_asset.albumsId', 'album.id') .leftJoin('album_asset', 'album_asset.albumId', 'album.id')
.leftJoinLateral( .leftJoinLateral(
(eb) => (eb) =>
eb eb
.selectFrom('asset') .selectFrom('asset')
.selectAll('asset') .selectAll('asset')
.whereRef('album_asset.assetsId', '=', 'asset.id') .whereRef('album_asset.assetId', '=', 'asset.id')
.where('asset.deletedAt', 'is', null) .where('asset.deletedAt', 'is', null)
.innerJoinLateral( .innerJoinLateral(
(eb) => (eb) =>
@ -123,13 +123,13 @@ export class SharedLinkRepository {
.selectFrom('shared_link') .selectFrom('shared_link')
.selectAll('shared_link') .selectAll('shared_link')
.where('shared_link.userId', '=', userId) .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( .leftJoinLateral(
(eb) => (eb) =>
eb eb
.selectFrom('asset') .selectFrom('asset')
.select((eb) => eb.fn.jsonAgg('asset').as('assets')) .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) .where('asset.deletedAt', 'is', null)
.as('assets'), .as('assets'),
(join) => join.onTrue(), (join) => join.onTrue(),
@ -215,7 +215,7 @@ export class SharedLinkRepository {
if (entity.assetIds && entity.assetIds.length > 0) { if (entity.assetIds && entity.assetIds.length > 0) {
await this.db await this.db
.insertInto('shared_link_asset') .insertInto('shared_link_asset')
.values(entity.assetIds!.map((assetsId) => ({ assetsId, sharedLinksId: id }))) .values(entity.assetIds!.map((assetId) => ({ assetId, sharedLinkId: id })))
.execute(); .execute();
} }
@ -233,7 +233,7 @@ export class SharedLinkRepository {
if (entity.assetIds && entity.assetIds.length > 0) { if (entity.assetIds && entity.assetIds.length > 0) {
await this.db await this.db
.insertInto('shared_link_asset') .insertInto('shared_link_asset')
.values(entity.assetIds!.map((assetsId) => ({ assetsId, sharedLinksId: id }))) .values(entity.assetIds!.map((assetId) => ({ assetId, sharedLinkId: id })))
.execute(); .execute();
} }
@ -249,12 +249,12 @@ export class SharedLinkRepository {
.selectFrom('shared_link') .selectFrom('shared_link')
.selectAll('shared_link') .selectAll('shared_link')
.where('shared_link.id', '=', id) .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( .leftJoinLateral(
(eb) => (eb) =>
eb eb
.selectFrom('asset') .selectFrom('asset')
.whereRef('asset.id', '=', 'shared_link_asset.assetsId') .whereRef('asset.id', '=', 'shared_link_asset.assetId')
.selectAll('asset') .selectAll('asset')
.innerJoinLateral( .innerJoinLateral(
(eb) => (eb) =>

View file

@ -33,8 +33,8 @@ const withAssets = (eb: ExpressionBuilder<DB, 'stack'>, withTags = false) => {
eb eb
.selectFrom('tag') .selectFrom('tag')
.select(columns.tag) .select(columns.tag)
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagsId') .innerJoin('tag_asset', 'tag.id', 'tag_asset.tagId')
.whereRef('tag_asset.assetsId', '=', 'asset.id'), .whereRef('tag_asset.assetId', '=', 'asset.id'),
).as('tags'), ).as('tags'),
), ),
) )

View file

@ -143,8 +143,8 @@ class AlbumSync extends BaseSync {
getCreatedAfter({ nowId, userId, afterCreateId }: SyncCreatedAfterOptions) { getCreatedAfter({ nowId, userId, afterCreateId }: SyncCreatedAfterOptions) {
return this.db return this.db
.selectFrom('album_user') .selectFrom('album_user')
.select(['albumsId as id', 'createId']) .select(['albumId as id', 'createId'])
.where('usersId', '=', userId) .where('userId', '=', userId)
.$if(!!afterCreateId, (qb) => qb.where('createId', '>=', afterCreateId!)) .$if(!!afterCreateId, (qb) => qb.where('createId', '>=', afterCreateId!))
.where('createId', '<', nowId) .where('createId', '<', nowId)
.orderBy('createId', 'asc') .orderBy('createId', 'asc')
@ -168,8 +168,8 @@ class AlbumSync extends BaseSync {
const userId = options.userId; const userId = options.userId;
return this.upsertQuery('album', options) return this.upsertQuery('album', options)
.distinctOn(['album.id', 'album.updateId']) .distinctOn(['album.id', 'album.updateId'])
.leftJoin('album_user as album_users', 'album.id', 'album_users.albumsId') .leftJoin('album_user as album_users', 'album.id', 'album_users.albumId')
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_users.usersId', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_users.userId', '=', userId)]))
.select([ .select([
'album.id', 'album.id',
'album.ownerId', 'album.ownerId',
@ -190,10 +190,10 @@ class AlbumAssetSync extends BaseSync {
@GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true }) @GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true })
getBackfill(options: SyncBackfillOptions, albumId: string) { getBackfill(options: SyncBackfillOptions, albumId: string) {
return this.backfillQuery('album_asset', options) return this.backfillQuery('album_asset', options)
.innerJoin('asset', 'asset.id', 'album_asset.assetsId') .innerJoin('asset', 'asset.id', 'album_asset.assetId')
.select(columns.syncAsset) .select(columns.syncAsset)
.select('album_asset.updateId') .select('album_asset.updateId')
.where('album_asset.albumsId', '=', albumId) .where('album_asset.albumId', '=', albumId)
.stream(); .stream();
} }
@ -201,13 +201,13 @@ class AlbumAssetSync extends BaseSync {
getUpdates(options: SyncQueryOptions, albumToAssetAck: SyncAck) { getUpdates(options: SyncQueryOptions, albumToAssetAck: SyncAck) {
const userId = options.userId; const userId = options.userId;
return this.upsertQuery('asset', options) 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(columns.syncAsset)
.select('asset.updateId') .select('asset.updateId')
.where('album_asset.updateId', '<=', albumToAssetAck.updateId) // Ensure we only send updates for assets that the client already knows about .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') .innerJoin('album', 'album.id', 'album_asset.albumId')
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId') .leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
.stream(); .stream();
} }
@ -216,11 +216,11 @@ class AlbumAssetSync extends BaseSync {
const userId = options.userId; const userId = options.userId;
return this.upsertQuery('album_asset', options) return this.upsertQuery('album_asset', options)
.select('album_asset.updateId') .select('album_asset.updateId')
.innerJoin('asset', 'asset.id', 'album_asset.assetsId') .innerJoin('asset', 'asset.id', 'album_asset.assetId')
.select(columns.syncAsset) .select(columns.syncAsset)
.innerJoin('album', 'album.id', 'album_asset.albumsId') .innerJoin('album', 'album.id', 'album_asset.albumId')
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId') .leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
.stream(); .stream();
} }
} }
@ -229,10 +229,10 @@ class AlbumAssetExifSync extends BaseSync {
@GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true }) @GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true })
getBackfill(options: SyncBackfillOptions, albumId: string) { getBackfill(options: SyncBackfillOptions, albumId: string) {
return this.backfillQuery('album_asset', options) 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(columns.syncAssetExif)
.select('album_asset.updateId') .select('album_asset.updateId')
.where('album_asset.albumsId', '=', albumId) .where('album_asset.albumId', '=', albumId)
.stream(); .stream();
} }
@ -240,13 +240,13 @@ class AlbumAssetExifSync extends BaseSync {
getUpdates(options: SyncQueryOptions, albumToAssetAck: SyncAck) { getUpdates(options: SyncQueryOptions, albumToAssetAck: SyncAck) {
const userId = options.userId; const userId = options.userId;
return this.upsertQuery('asset_exif', options) 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(columns.syncAssetExif)
.select('asset_exif.updateId') .select('asset_exif.updateId')
.where('album_asset.updateId', '<=', albumToAssetAck.updateId) // Ensure we only send exif updates for assets that the client already knows about .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') .innerJoin('album', 'album.id', 'album_asset.albumId')
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId') .leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
.stream(); .stream();
} }
@ -255,11 +255,11 @@ class AlbumAssetExifSync extends BaseSync {
const userId = options.userId; const userId = options.userId;
return this.upsertQuery('album_asset', options) return this.upsertQuery('album_asset', options)
.select('album_asset.updateId') .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) .select(columns.syncAssetExif)
.innerJoin('album', 'album.id', 'album_asset.albumsId') .innerJoin('album', 'album.id', 'album_asset.albumId')
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId') .leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
.stream(); .stream();
} }
} }
@ -268,8 +268,8 @@ class AlbumToAssetSync extends BaseSync {
@GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true }) @GenerateSql({ params: [dummyBackfillOptions, DummyValue.UUID], stream: true })
getBackfill(options: SyncBackfillOptions, albumId: string) { getBackfill(options: SyncBackfillOptions, albumId: string) {
return this.backfillQuery('album_asset', options) return this.backfillQuery('album_asset', options)
.select(['album_asset.assetsId as assetId', 'album_asset.albumsId as albumId', 'album_asset.updateId']) .select(['album_asset.assetId as assetId', 'album_asset.albumId as albumId', 'album_asset.updateId'])
.where('album_asset.albumsId', '=', albumId) .where('album_asset.albumId', '=', albumId)
.stream(); .stream();
} }
@ -290,8 +290,8 @@ class AlbumToAssetSync extends BaseSync {
eb.parens( eb.parens(
eb eb
.selectFrom('album_user') .selectFrom('album_user')
.select(['album_user.albumsId as id']) .select(['album_user.albumId as id'])
.where('album_user.usersId', '=', userId), .where('album_user.userId', '=', userId),
), ),
), ),
), ),
@ -307,10 +307,10 @@ class AlbumToAssetSync extends BaseSync {
getUpserts(options: SyncQueryOptions) { getUpserts(options: SyncQueryOptions) {
const userId = options.userId; const userId = options.userId;
return this.upsertQuery('album_asset', options) return this.upsertQuery('album_asset', options)
.select(['album_asset.assetsId as assetId', 'album_asset.albumsId as albumId', 'album_asset.updateId']) .select(['album_asset.assetId as assetId', 'album_asset.albumId as albumId', 'album_asset.updateId'])
.innerJoin('album', 'album.id', 'album_asset.albumsId') .innerJoin('album', 'album.id', 'album_asset.albumId')
.leftJoin('album_user', 'album_user.albumsId', 'album_asset.albumsId') .leftJoin('album_user', 'album_user.albumId', 'album_asset.albumId')
.where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.usersId', '=', userId)])) .where((eb) => eb.or([eb('album.ownerId', '=', userId), eb('album_user.userId', '=', userId)]))
.stream(); .stream();
} }
} }
@ -321,7 +321,7 @@ class AlbumUserSync extends BaseSync {
return this.backfillQuery('album_user', options) return this.backfillQuery('album_user', options)
.select(columns.syncAlbumUser) .select(columns.syncAlbumUser)
.select('album_user.updateId') .select('album_user.updateId')
.where('albumsId', '=', albumId) .where('albumId', '=', albumId)
.stream(); .stream();
} }
@ -342,8 +342,8 @@ class AlbumUserSync extends BaseSync {
eb.parens( eb.parens(
eb eb
.selectFrom('album_user') .selectFrom('album_user')
.select(['album_user.albumsId as id']) .select(['album_user.albumId as id'])
.where('album_user.usersId', '=', userId), .where('album_user.userId', '=', userId),
), ),
), ),
), ),
@ -363,7 +363,7 @@ class AlbumUserSync extends BaseSync {
.select('album_user.updateId') .select('album_user.updateId')
.where((eb) => .where((eb) =>
eb( eb(
'album_user.albumsId', 'album_user.albumId',
'in', 'in',
eb eb
.selectFrom('album') .selectFrom('album')
@ -373,8 +373,8 @@ class AlbumUserSync extends BaseSync {
eb.parens( eb.parens(
eb eb
.selectFrom('album_user as albumUsers') .selectFrom('album_user as albumUsers')
.select(['albumUsers.albumsId as id']) .select(['albumUsers.albumId as id'])
.where('albumUsers.usersId', '=', userId), .where('albumUsers.userId', '=', userId),
), ),
), ),
), ),
@ -550,7 +550,7 @@ class MemoryToAssetSync extends BaseSync {
@GenerateSql({ params: [dummyQueryOptions], stream: true }) @GenerateSql({ params: [dummyQueryOptions], stream: true })
getUpserts(options: SyncQueryOptions) { getUpserts(options: SyncQueryOptions) {
return this.upsertQuery('memory_asset', options) return this.upsertQuery('memory_asset', options)
.select(['memoriesId as memoryId', 'assetsId as assetId']) .select(['memoriesId as memoryId', 'assetId as assetId'])
.select('updateId') .select('updateId')
.where('memoriesId', 'in', (eb) => eb.selectFrom('memory').select('id').where('ownerId', '=', options.userId)) .where('memoriesId', 'in', (eb) => eb.selectFrom('memory').select('id').where('ownerId', '=', options.userId))
.stream(); .stream();

View file

@ -97,9 +97,9 @@ export class TagRepository {
const results = await this.db const results = await this.db
.selectFrom('tag_asset') .selectFrom('tag_asset')
.select(['assetsId as assetId']) .select(['assetId as assetId'])
.where('tagsId', '=', tagId) .where('tagId', '=', tagId)
.where('assetsId', 'in', assetIds) .where('assetId', 'in', assetIds)
.execute(); .execute();
return new Set(results.map(({ assetId }) => assetId)); return new Set(results.map(({ assetId }) => assetId));
@ -114,7 +114,7 @@ export class TagRepository {
await this.db await this.db
.insertInto('tag_asset') .insertInto('tag_asset')
.values(assetIds.map((assetId) => ({ tagsId: tagId, assetsId: assetId }))) .values(assetIds.map((assetId) => ({ tagId, assetId })))
.execute(); .execute();
} }
@ -125,7 +125,7 @@ export class TagRepository {
return; 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] }]] }) @GenerateSql({ params: [[{ assetId: DummyValue.UUID, tagsIds: [DummyValue.UUID] }]] })
@ -147,7 +147,7 @@ export class TagRepository {
@Chunked({ paramIndex: 1 }) @Chunked({ paramIndex: 1 })
replaceAssetTags(assetId: string, tagIds: string[]) { replaceAssetTags(assetId: string, tagIds: string[]) {
return this.db.transaction().execute(async (tx) => { 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) { if (tagIds.length === 0) {
return; return;
@ -155,7 +155,7 @@ export class TagRepository {
return tx return tx
.insertInto('tag_asset') .insertInto('tag_asset')
.values(tagIds.map((tagId) => ({ tagsId: tagId, assetsId: assetId }))) .values(tagIds.map((tagId) => ({ tagId, assetId })))
.onConflict((oc) => oc.doNothing()) .onConflict((oc) => oc.doNothing())
.returningAll() .returningAll()
.execute(); .execute();
@ -170,7 +170,7 @@ export class TagRepository {
exists( exists(
selectFrom('tag_closure') selectFrom('tag_closure')
.whereRef('tag.id', '=', 'tag_closure.id_ancestor') .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'),
), ),
), ),
) )

View file

@ -29,7 +29,7 @@ export const album_user_after_insert = registerFunction({
body: ` body: `
BEGIN BEGIN
UPDATE album SET "updatedAt" = clock_timestamp(), "updateId" = immich_uuid_v7(clock_timestamp()) 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; RETURN NULL;
END`, END`,
}); });
@ -139,8 +139,8 @@ export const album_asset_delete_audit = registerFunction({
body: ` body: `
BEGIN BEGIN
INSERT INTO album_asset_audit ("albumId", "assetId") INSERT INTO album_asset_audit ("albumId", "assetId")
SELECT "albumsId", "assetsId" FROM OLD SELECT "albumId", "assetId" FROM OLD
WHERE "albumsId" IN (SELECT "id" FROM album WHERE "id" IN (SELECT "albumsId" FROM OLD)); WHERE "albumId" IN (SELECT "id" FROM album WHERE "id" IN (SELECT "albumId" FROM OLD));
RETURN NULL; RETURN NULL;
END`, END`,
}); });
@ -152,12 +152,12 @@ export const album_user_delete_audit = registerFunction({
body: ` body: `
BEGIN BEGIN
INSERT INTO album_audit ("albumId", "userId") INSERT INTO album_audit ("albumId", "userId")
SELECT "albumsId", "usersId" SELECT "albumId", "userId"
FROM OLD; FROM OLD;
IF pg_trigger_depth() = 1 THEN IF pg_trigger_depth() = 1 THEN
INSERT INTO album_user_audit ("albumId", "userId") INSERT INTO album_user_audit ("albumId", "userId")
SELECT "albumsId", "usersId" SELECT "albumId", "userId"
FROM OLD; FROM OLD;
END IF; END IF;
@ -185,7 +185,7 @@ export const memory_asset_delete_audit = registerFunction({
body: ` body: `
BEGIN BEGIN
INSERT INTO memory_asset_audit ("memoryId", "assetId") 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)); WHERE "memoriesId" IN (SELECT "id" FROM memory WHERE "id" IN (SELECT "memoriesId" FROM OLD));
RETURN NULL; RETURN NULL;
END`, END`,

View 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
}

View file

@ -32,7 +32,7 @@ import {
@ForeignKeyConstraint({ @ForeignKeyConstraint({
columns: ['albumId', 'assetId'], columns: ['albumId', 'assetId'],
referenceTable: () => AlbumAssetTable, referenceTable: () => AlbumAssetTable,
referenceColumns: ['albumsId', 'assetsId'], referenceColumns: ['albumId', 'assetId'],
onUpdate: 'NO ACTION', onUpdate: 'NO ACTION',
onDelete: 'CASCADE', onDelete: 'CASCADE',
}) })

View file

@ -22,10 +22,10 @@ import {
}) })
export class AlbumAssetTable { export class AlbumAssetTable {
@ForeignKeyColumn(() => AlbumTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false, primary: true }) @ForeignKeyColumn(() => AlbumTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false, primary: true })
albumsId!: string; albumId!: string;
@ForeignKeyColumn(() => AssetTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false, primary: true }) @ForeignKeyColumn(() => AssetTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: false, primary: true })
assetsId!: string; assetId!: string;
@CreateDateColumn() @CreateDateColumn()
createdAt!: Generated<Timestamp>; createdAt!: Generated<Timestamp>;

View file

@ -37,7 +37,7 @@ export class AlbumUserTable {
nullable: false, nullable: false,
primary: true, primary: true,
}) })
albumsId!: string; albumId!: string;
@ForeignKeyColumn(() => UserTable, { @ForeignKeyColumn(() => UserTable, {
onDelete: 'CASCADE', onDelete: 'CASCADE',
@ -45,7 +45,7 @@ export class AlbumUserTable {
nullable: false, nullable: false,
primary: true, primary: true,
}) })
usersId!: string; userId!: string;
@Column({ type: 'character varying', default: AlbumUserRole.Editor }) @Column({ type: 'character varying', default: AlbumUserRole.Editor })
role!: Generated<AlbumUserRole>; role!: Generated<AlbumUserRole>;

View file

@ -25,7 +25,7 @@ export class MemoryAssetTable {
memoriesId!: string; memoriesId!: string;
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true }) @ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
assetsId!: string; assetId!: string;
@CreateDateColumn() @CreateDateColumn()
createdAt!: Generated<Timestamp>; createdAt!: Generated<Timestamp>;

View file

@ -5,8 +5,8 @@ import { ForeignKeyColumn, Table } from 'src/sql-tools';
@Table('shared_link_asset') @Table('shared_link_asset')
export class SharedLinkAssetTable { export class SharedLinkAssetTable {
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true }) @ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
assetsId!: string; assetId!: string;
@ForeignKeyColumn(() => SharedLinkTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true }) @ForeignKeyColumn(() => SharedLinkTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
sharedLinksId!: string; sharedLinkId!: string;
} }

View file

@ -2,12 +2,12 @@ import { AssetTable } from 'src/schema/tables/asset.table';
import { TagTable } from 'src/schema/tables/tag.table'; import { TagTable } from 'src/schema/tables/tag.table';
import { ForeignKeyColumn, Index, Table } from 'src/sql-tools'; import { ForeignKeyColumn, Index, Table } from 'src/sql-tools';
@Index({ columns: ['assetsId', 'tagsId'] }) @Index({ columns: ['assetId', 'tagId'] })
@Table('tag_asset') @Table('tag_asset')
export class TagAssetTable { export class TagAssetTable {
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true }) @ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true })
assetsId!: string; assetId!: string;
@ForeignKeyColumn(() => TagTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true }) @ForeignKeyColumn(() => TagTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true })
tagsId!: string; tagId!: string;
} }

View file

@ -402,16 +402,16 @@ describe(AlbumService.name, () => {
mocks.album.update.mockResolvedValue(albumStub.sharedWithAdmin); mocks.album.update.mockResolvedValue(albumStub.sharedWithAdmin);
mocks.user.get.mockResolvedValue(userStub.user2); mocks.user.get.mockResolvedValue(userStub.user2);
mocks.albumUser.create.mockResolvedValue({ mocks.albumUser.create.mockResolvedValue({
usersId: userStub.user2.id, userId: userStub.user2.id,
albumsId: albumStub.sharedWithAdmin.id, albumId: albumStub.sharedWithAdmin.id,
role: AlbumUserRole.Editor, role: AlbumUserRole.Editor,
}); });
await sut.addUsers(authStub.user1, albumStub.sharedWithAdmin.id, { await sut.addUsers(authStub.user1, albumStub.sharedWithAdmin.id, {
albumUsers: [{ userId: authStub.user2.user.id }], albumUsers: [{ userId: authStub.user2.user.id }],
}); });
expect(mocks.albumUser.create).toHaveBeenCalledWith({ expect(mocks.albumUser.create).toHaveBeenCalledWith({
usersId: authStub.user2.user.id, userId: authStub.user2.user.id,
albumsId: albumStub.sharedWithAdmin.id, albumId: albumStub.sharedWithAdmin.id,
}); });
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', { expect(mocks.event.emit).toHaveBeenCalledWith('AlbumInvite', {
id: albumStub.sharedWithAdmin.id, id: albumStub.sharedWithAdmin.id,
@ -439,8 +439,8 @@ describe(AlbumService.name, () => {
expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1); expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1);
expect(mocks.albumUser.delete).toHaveBeenCalledWith({ expect(mocks.albumUser.delete).toHaveBeenCalledWith({
albumsId: albumStub.sharedWithUser.id, albumId: albumStub.sharedWithUser.id,
usersId: userStub.user1.id, userId: userStub.user1.id,
}); });
expect(mocks.album.getById).toHaveBeenCalledWith(albumStub.sharedWithUser.id, { withAssets: false }); 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).toHaveBeenCalledTimes(1);
expect(mocks.albumUser.delete).toHaveBeenCalledWith({ expect(mocks.albumUser.delete).toHaveBeenCalledWith({
albumsId: albumStub.sharedWithUser.id, albumId: albumStub.sharedWithUser.id,
usersId: authStub.user1.user.id, userId: authStub.user1.user.id,
}); });
}); });
@ -480,8 +480,8 @@ describe(AlbumService.name, () => {
expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1); expect(mocks.albumUser.delete).toHaveBeenCalledTimes(1);
expect(mocks.albumUser.delete).toHaveBeenCalledWith({ expect(mocks.albumUser.delete).toHaveBeenCalledWith({
albumsId: albumStub.sharedWithUser.id, albumId: albumStub.sharedWithUser.id,
usersId: authStub.user1.user.id, userId: authStub.user1.user.id,
}); });
}); });
@ -515,7 +515,7 @@ describe(AlbumService.name, () => {
role: AlbumUserRole.Editor, role: AlbumUserRole.Editor,
}); });
expect(mocks.albumUser.update).toHaveBeenCalledWith( expect(mocks.albumUser.update).toHaveBeenCalledWith(
{ albumsId: albumStub.sharedWithAdmin.id, usersId: userStub.admin.id }, { albumId: albumStub.sharedWithAdmin.id, userId: userStub.admin.id },
{ role: AlbumUserRole.Editor }, { role: AlbumUserRole.Editor },
); );
}); });
@ -804,12 +804,12 @@ describe(AlbumService.name, () => {
albumThumbnailAssetId: 'asset-1', albumThumbnailAssetId: 'asset-1',
}); });
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([ expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
{ albumsId: 'album-123', assetsId: 'asset-1' }, { albumId: 'album-123', assetId: 'asset-1' },
{ albumsId: 'album-123', assetsId: 'asset-2' }, { albumId: 'album-123', assetId: 'asset-2' },
{ albumsId: 'album-123', assetsId: 'asset-3' }, { albumId: 'album-123', assetId: 'asset-3' },
{ albumsId: 'album-321', assetsId: 'asset-1' }, { albumId: 'album-321', assetId: 'asset-1' },
{ albumsId: 'album-321', assetsId: 'asset-2' }, { albumId: 'album-321', assetId: 'asset-2' },
{ albumsId: 'album-321', assetsId: 'asset-3' }, { albumId: 'album-321', assetId: 'asset-3' },
]); ]);
}); });
@ -840,12 +840,12 @@ describe(AlbumService.name, () => {
albumThumbnailAssetId: 'asset-id', albumThumbnailAssetId: 'asset-id',
}); });
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([ expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
{ albumsId: 'album-123', assetsId: 'asset-1' }, { albumId: 'album-123', assetId: 'asset-1' },
{ albumsId: 'album-123', assetsId: 'asset-2' }, { albumId: 'album-123', assetId: 'asset-2' },
{ albumsId: 'album-123', assetsId: 'asset-3' }, { albumId: 'album-123', assetId: 'asset-3' },
{ albumsId: 'album-321', assetsId: 'asset-1' }, { albumId: 'album-321', assetId: 'asset-1' },
{ albumsId: 'album-321', assetsId: 'asset-2' }, { albumId: 'album-321', assetId: 'asset-2' },
{ albumsId: 'album-321', assetsId: 'asset-3' }, { albumId: 'album-321', assetId: 'asset-3' },
]); ]);
}); });
@ -876,12 +876,12 @@ describe(AlbumService.name, () => {
albumThumbnailAssetId: 'asset-1', albumThumbnailAssetId: 'asset-1',
}); });
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([ expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
{ albumsId: 'album-123', assetsId: 'asset-1' }, { albumId: 'album-123', assetId: 'asset-1' },
{ albumsId: 'album-123', assetsId: 'asset-2' }, { albumId: 'album-123', assetId: 'asset-2' },
{ albumsId: 'album-123', assetsId: 'asset-3' }, { albumId: 'album-123', assetId: 'asset-3' },
{ albumsId: 'album-321', assetsId: 'asset-1' }, { albumId: 'album-321', assetId: 'asset-1' },
{ albumsId: 'album-321', assetsId: 'asset-2' }, { albumId: 'album-321', assetId: 'asset-2' },
{ albumsId: 'album-321', assetsId: 'asset-3' }, { albumId: 'album-321', assetId: 'asset-3' },
]); ]);
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', { expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
id: 'album-123', id: 'album-123',
@ -936,9 +936,9 @@ describe(AlbumService.name, () => {
albumThumbnailAssetId: 'asset-1', albumThumbnailAssetId: 'asset-1',
}); });
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([ expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
{ albumsId: 'album-123', assetsId: 'asset-1' }, { albumId: 'album-123', assetId: 'asset-1' },
{ albumsId: 'album-123', assetsId: 'asset-2' }, { albumId: 'album-123', assetId: 'asset-2' },
{ albumsId: 'album-123', assetsId: 'asset-3' }, { albumId: 'album-123', assetId: 'asset-3' },
]); ]);
expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', { expect(mocks.event.emit).toHaveBeenCalledWith('AlbumUpdate', {
id: 'album-123', id: 'album-123',
@ -977,12 +977,12 @@ describe(AlbumService.name, () => {
albumThumbnailAssetId: 'asset-1', albumThumbnailAssetId: 'asset-1',
}); });
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([ expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
{ albumsId: 'album-123', assetsId: 'asset-1' }, { albumId: 'album-123', assetId: 'asset-1' },
{ albumsId: 'album-123', assetsId: 'asset-2' }, { albumId: 'album-123', assetId: 'asset-2' },
{ albumsId: 'album-123', assetsId: 'asset-3' }, { albumId: 'album-123', assetId: 'asset-3' },
{ albumsId: 'album-321', assetsId: 'asset-1' }, { albumId: 'album-321', assetId: 'asset-1' },
{ albumsId: 'album-321', assetsId: 'asset-2' }, { albumId: 'album-321', assetId: 'asset-2' },
{ albumsId: 'album-321', assetsId: 'asset-3' }, { albumId: 'album-321', assetId: 'asset-3' },
]); ]);
expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith( expect(mocks.access.asset.checkPartnerAccess).toHaveBeenCalledWith(
authStub.admin.user.id, authStub.admin.user.id,
@ -1014,9 +1014,9 @@ describe(AlbumService.name, () => {
albumThumbnailAssetId: 'asset-1', albumThumbnailAssetId: 'asset-1',
}); });
expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([ expect(mocks.album.addAssetIdsToAlbums).toHaveBeenCalledWith([
{ albumsId: 'album-321', assetsId: 'asset-1' }, { albumId: 'album-321', assetId: 'asset-1' },
{ albumsId: 'album-321', assetsId: 'asset-2' }, { albumId: 'album-321', assetId: 'asset-2' },
{ albumsId: 'album-321', assetsId: 'asset-3' }, { albumId: 'album-321', assetId: 'asset-3' },
]); ]);
}); });

View file

@ -215,7 +215,7 @@ export class AlbumService extends BaseService {
return results; return results;
} }
const albumAssetValues: { albumsId: string; assetsId: string }[] = []; const albumAssetValues: { albumId: string; assetId: string }[] = [];
const events: { id: string; recipients: string[] }[] = []; const events: { id: string; recipients: string[] }[] = [];
for (const albumId of allowedAlbumIds) { for (const albumId of allowedAlbumIds) {
const existingAssetIds = await this.albumRepository.getAssetIds(albumId, [...allowedAssetIds]); const existingAssetIds = await this.albumRepository.getAssetIds(albumId, [...allowedAssetIds]);
@ -228,7 +228,7 @@ export class AlbumService extends BaseService {
results.success = true; results.success = true;
for (const assetId of notPresentAssetIds) { for (const assetId of notPresentAssetIds) {
albumAssetValues.push({ albumsId: albumId, assetsId: assetId }); albumAssetValues.push({ albumId, assetId });
} }
await this.albumRepository.update(albumId, { await this.albumRepository.update(albumId, {
id: albumId, id: albumId,
@ -289,7 +289,7 @@ export class AlbumService extends BaseService {
throw new BadRequestException('User not found'); 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 }); 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.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> { async updateUser(auth: AuthDto, id: string, userId: string, dto: UpdateAlbumUserDto): Promise<void> {
await this.requireAccess({ auth, permission: Permission.AlbumShare, ids: [id] }); 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) { private async findOrFail(id: string, options: AlbumInfoOptions) {

View file

@ -192,12 +192,12 @@ describe(TagService.name, () => {
mocks.access.tag.checkOwnerAccess.mockResolvedValue(new Set(['tag-1', 'tag-2'])); 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.access.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1', 'asset-2', 'asset-3']));
mocks.tag.upsertAssetIds.mockResolvedValue([ mocks.tag.upsertAssetIds.mockResolvedValue([
{ tagsId: 'tag-1', assetsId: 'asset-1' }, { tagId: 'tag-1', assetId: 'asset-1' },
{ tagsId: 'tag-1', assetsId: 'asset-2' }, { tagId: 'tag-1', assetId: 'asset-2' },
{ tagsId: 'tag-1', assetsId: 'asset-3' }, { tagId: 'tag-1', assetId: 'asset-3' },
{ tagsId: 'tag-2', assetsId: 'asset-1' }, { tagId: 'tag-2', assetId: 'asset-1' },
{ tagsId: 'tag-2', assetsId: 'asset-2' }, { tagId: 'tag-2', assetId: 'asset-2' },
{ tagsId: 'tag-2', assetsId: 'asset-3' }, { tagId: 'tag-2', assetId: 'asset-3' },
]); ]);
await expect( await expect(
sut.bulkTagAssets(authStub.admin, { tagIds: ['tag-1', 'tag-2'], assetIds: ['asset-1', 'asset-2', 'asset-3'] }), 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, count: 6,
}); });
expect(mocks.tag.upsertAssetIds).toHaveBeenCalledWith([ expect(mocks.tag.upsertAssetIds).toHaveBeenCalledWith([
{ tagsId: 'tag-1', assetsId: 'asset-1' }, { tagId: 'tag-1', assetId: 'asset-1' },
{ tagsId: 'tag-1', assetsId: 'asset-2' }, { tagId: 'tag-1', assetId: 'asset-2' },
{ tagsId: 'tag-1', assetsId: 'asset-3' }, { tagId: 'tag-1', assetId: 'asset-3' },
{ tagsId: 'tag-2', assetsId: 'asset-1' }, { tagId: 'tag-2', assetId: 'asset-1' },
{ tagsId: 'tag-2', assetsId: 'asset-2' }, { tagId: 'tag-2', assetId: 'asset-2' },
{ tagsId: 'tag-2', assetsId: 'asset-3' }, { tagId: 'tag-2', assetId: 'asset-3' },
]); ]);
}); });
}); });

View file

@ -82,14 +82,14 @@ export class TagService extends BaseService {
]); ]);
const items: Insertable<TagAssetTable>[] = []; const items: Insertable<TagAssetTable>[] = [];
for (const tagsId of tagIds) { for (const tagId of tagIds) {
for (const assetsId of assetIds) { for (const assetId of assetIds) {
items.push({ tagsId, assetsId }); items.push({ tagId, assetId });
} }
} }
const results = await this.tagRepository.upsertAssetIds(items); 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 }); await this.eventRepository.emit('AssetTag', { assetId });
} }

View file

@ -244,12 +244,12 @@ export function inAlbums<O>(qb: SelectQueryBuilder<DB, 'asset', O>, albumIds: st
(eb) => (eb) =>
eb eb
.selectFrom('album_asset') .selectFrom('album_asset')
.select('assetsId') .select('assetId')
.where('albumsId', '=', anyUuid(albumIds!)) .where('albumId', '=', anyUuid(albumIds!))
.groupBy('assetsId') .groupBy('assetId')
.having((eb) => eb.fn.count('albumsId').distinct(), '=', albumIds.length) .having((eb) => eb.fn.count('albumId').distinct(), '=', albumIds.length)
.as('has_album'), .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) =>
eb eb
.selectFrom('tag_asset') .selectFrom('tag_asset')
.select('assetsId') .select('assetId')
.innerJoin('tag_closure', 'tag_asset.tagsId', 'tag_closure.id_descendant') .innerJoin('tag_closure', 'tag_asset.tagId', 'tag_closure.id_descendant')
.where('tag_closure.id_ancestor', '=', anyUuid(tagIds)) .where('tag_closure.id_ancestor', '=', anyUuid(tagIds))
.groupBy('assetsId') .groupBy('assetId')
.having((eb) => eb.fn.count('tag_closure.id_ancestor').distinct(), '>=', tagIds.length) .having((eb) => eb.fn.count('tag_closure.id_ancestor').distinct(), '>=', tagIds.length)
.as('has_tags'), .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 eb
.selectFrom('tag') .selectFrom('tag')
.select(columns.tag) .select(columns.tag)
.innerJoin('tag_asset', 'tag.id', 'tag_asset.tagsId') .innerJoin('tag_asset', 'tag.id', 'tag_asset.tagId')
.whereRef('asset.id', '=', 'tag_asset.assetsId'), .whereRef('asset.id', '=', 'tag_asset.assetId'),
).as('tags'); ).as('tags');
} }
@ -299,8 +299,8 @@ export function withTagId<O>(qb: SelectQueryBuilder<DB, 'asset', O>, tagId: stri
eb.exists( eb.exists(
eb eb
.selectFrom('tag_closure') .selectFrom('tag_closure')
.innerJoin('tag_asset', 'tag_asset.tagsId', 'tag_closure.id_descendant') .innerJoin('tag_asset', 'tag_asset.tagId', 'tag_closure.id_descendant')
.whereRef('tag_asset.assetsId', '=', 'asset.id') .whereRef('tag_asset.assetId', '=', 'asset.id')
.where('tag_closure.id_ancestor', '=', tagId), .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.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 && options.tagIds.length > 0, (qb) => hasTags(qb, options.tagIds!))
.$if(options.tagIds === null, (qb) => .$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.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!))
.$if(!!options.createdBefore, (qb) => qb.where('asset.createdAt', '<=', options.createdBefore!)) .$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), qb.where('asset.livePhotoVideoId', options.isMotion ? 'is not' : 'is', null),
) )
.$if(!!options.isNotInAlbum && (!options.albumIds || options.albumIds.length === 0), (qb) => .$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.withExif, withExifInner)
.$if(!!(options.withFaces || options.withPeople || options.personIds), (qb) => qb.select(withFacesAndPeople)) .$if(!!(options.withFaces || options.withPeople || options.personIds), (qb) => qb.select(withFacesAndPeople))

View file

@ -217,7 +217,7 @@ export class MediumTestContext<S extends BaseService = BaseService> {
async newAlbumUser(dto: { albumId: string; userId: string; role?: AlbumUserRole }) { async newAlbumUser(dto: { albumId: string; userId: string; role?: AlbumUserRole }) {
const { albumId, userId, role = AlbumUserRole.Editor } = dto; const { albumId, userId, role = AlbumUserRole.Editor } = dto;
const result = await this.get(AlbumUserRepository).create({ albumsId: albumId, usersId: userId, role }); const result = await this.get(AlbumUserRepository).create({ albumId, userId, role });
return { albumUser: { albumId, userId, role }, result }; return { albumUser: { albumId, userId, role }, result };
} }
@ -260,9 +260,9 @@ export class MediumTestContext<S extends BaseService = BaseService> {
async newTagAsset(tagBulkAssets: { tagIds: string[]; assetIds: string[] }) { async newTagAsset(tagBulkAssets: { tagIds: string[]; assetIds: string[] }) {
const tagsAssets: Insertable<TagAssetTable>[] = []; const tagsAssets: Insertable<TagAssetTable>[] = [];
for (const tagsId of tagBulkAssets.tagIds) { for (const tagId of tagBulkAssets.tagIds) {
for (const assetsId of tagBulkAssets.assetIds) { for (const assetId of tagBulkAssets.assetIds) {
tagsAssets.push({ tagsId, assetsId }); tagsAssets.push({ tagId, assetId });
} }
} }

View file

@ -74,7 +74,7 @@ describe(SyncRequestType.AlbumUsersV1, () => {
await ctx.syncAckAll(auth, response); await ctx.syncAckAll(auth, response);
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]); await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]);
await albumUserRepo.update({ albumsId: album.id, usersId: user1.id }, { role: AlbumUserRole.Viewer }); await albumUserRepo.update({ albumId: album.id, userId: user1.id }, { role: AlbumUserRole.Viewer });
const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]); const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]);
expect(newResponse).toEqual([ expect(newResponse).toEqual([
{ {
@ -104,7 +104,7 @@ describe(SyncRequestType.AlbumUsersV1, () => {
await ctx.syncAckAll(auth, response); await ctx.syncAckAll(auth, response);
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]); await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]);
await albumUserRepo.delete({ albumsId: album.id, usersId: user1.id }); await albumUserRepo.delete({ albumId: album.id, userId: user1.id });
const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]); const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]);
expect(newResponse).toEqual([ expect(newResponse).toEqual([
{ {
@ -171,7 +171,7 @@ describe(SyncRequestType.AlbumUsersV1, () => {
await ctx.syncAckAll(auth, response); await ctx.syncAckAll(auth, response);
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]); await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]);
await albumUserRepo.update({ albumsId: album.id, usersId: user.id }, { role: AlbumUserRole.Viewer }); await albumUserRepo.update({ albumId: album.id, userId: user.id }, { role: AlbumUserRole.Viewer });
const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]); const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]);
expect(newResponse).toEqual([ expect(newResponse).toEqual([
{ {
@ -208,7 +208,7 @@ describe(SyncRequestType.AlbumUsersV1, () => {
await ctx.syncAckAll(auth, response); await ctx.syncAckAll(auth, response);
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]); await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumUsersV1]);
await albumUserRepo.delete({ albumsId: album.id, usersId: user.id }); await albumUserRepo.delete({ albumId: album.id, userId: user.id });
const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]); const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumUsersV1]);
expect(newResponse).toEqual([ expect(newResponse).toEqual([

View file

@ -217,7 +217,7 @@ describe(SyncRequestType.AlbumsV1, () => {
await ctx.syncAckAll(auth, response); await ctx.syncAckAll(auth, response);
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumsV1]); await ctx.assertSyncIsComplete(auth, [SyncRequestType.AlbumsV1]);
await albumUserRepo.delete({ albumsId: album.id, usersId: auth.user.id }); await albumUserRepo.delete({ albumId: album.id, userId: auth.user.id });
const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumsV1]); const newResponse = await ctx.syncStream(auth, [SyncRequestType.AlbumsV1]);
expect(newResponse).toEqual([ expect(newResponse).toEqual([
{ {