feat: rename schema (#19891)

This commit is contained in:
Jason Rasmussen
2025-07-14 10:13:06 -04:00
committed by GitHub
parent 33c29e4305
commit c699df002a
103 changed files with 4378 additions and 3224 deletions

View File

@@ -1,7 +1,7 @@
-- NOTE: This file is auto generated by ./sql-generator
-- AssetRepository.updateAllExif
update "exif"
update "asset_exif"
set
"model" = $1
where
@@ -23,42 +23,42 @@ with
min(("localDateTime" at time zone 'UTC')::date)
)::int
from
assets
asset
),
date_part('year', current_date)::int - 1
) as "year"
)
select
"a".*,
to_json("exif") as "exifInfo"
to_json("asset_exif") as "exifInfo"
from
"today"
inner join lateral (
select
"assets".*
"asset".*
from
"assets"
inner join "asset_job_status" on "assets"."id" = "asset_job_status"."assetId"
"asset"
inner join "asset_job_status" on "asset"."id" = "asset_job_status"."assetId"
where
"asset_job_status"."previewAt" is not null
and (assets."localDateTime" at time zone 'UTC')::date = today.date
and "assets"."ownerId" = any ($3::uuid[])
and "assets"."visibility" = $4
and (asset."localDateTime" at time zone 'UTC')::date = today.date
and "asset"."ownerId" = any ($3::uuid[])
and "asset"."visibility" = $4
and exists (
select
from
"asset_files"
"asset_file"
where
"assetId" = "assets"."id"
and "asset_files"."type" = $5
"assetId" = "asset"."id"
and "asset_file"."type" = $5
)
and "assets"."deletedAt" is null
and "asset"."deletedAt" is null
order by
(assets."localDateTime" at time zone 'UTC')::date desc
(asset."localDateTime" at time zone 'UTC')::date desc
limit
$6
) as "a" on true
inner join "exif" on "a"."id" = "exif"."assetId"
inner join "asset_exif" on "a"."id" = "asset_exif"."assetId"
)
select
date_part(
@@ -75,36 +75,36 @@ order by
-- AssetRepository.getByIds
select
"assets".*
"asset".*
from
"assets"
"asset"
where
"assets"."id" = any ($1::uuid[])
"asset"."id" = any ($1::uuid[])
-- AssetRepository.getByIdsWithAllRelationsButStacks
select
"assets".*,
"asset".*,
(
select
coalesce(json_agg(agg), '[]')
from
(
select
"asset_faces".*,
"asset_face".*,
"person" as "person"
from
"asset_faces"
"asset_face"
left join lateral (
select
"person".*
from
"person"
where
"asset_faces"."personId" = "person"."id"
"asset_face"."personId" = "person"."id"
) as "person" on true
where
"asset_faces"."assetId" = "assets"."id"
and "asset_faces"."deletedAt" is null
"asset_face"."assetId" = "asset"."id"
and "asset_face"."deletedAt" is null
) as agg
) as "faces",
(
@@ -113,36 +113,36 @@ select
from
(
select
"tags"."id",
"tags"."value",
"tags"."createdAt",
"tags"."updatedAt",
"tags"."color",
"tags"."parentId"
"tag"."id",
"tag"."value",
"tag"."createdAt",
"tag"."updatedAt",
"tag"."color",
"tag"."parentId"
from
"tags"
inner join "tag_asset" on "tags"."id" = "tag_asset"."tagsId"
"tag"
inner join "tag_asset" on "tag"."id" = "tag_asset"."tagsId"
where
"assets"."id" = "tag_asset"."assetsId"
"asset"."id" = "tag_asset"."assetsId"
) as agg
) as "tags",
to_json("exif") as "exifInfo"
to_json("asset_exif") as "exifInfo"
from
"assets"
left join "exif" on "assets"."id" = "exif"."assetId"
"asset"
left join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
where
"assets"."id" = any ($1::uuid[])
"asset"."id" = any ($1::uuid[])
-- AssetRepository.deleteAll
delete from "assets"
delete from "asset"
where
"ownerId" = $1
-- AssetRepository.getByLibraryIdAndOriginalPath
select
"assets".*
"asset".*
from
"assets"
"asset"
where
"libraryId" = $1::uuid
and "originalPath" = $2
@@ -153,7 +153,7 @@ limit
select
"deviceAssetId"
from
"assets"
"asset"
where
"ownerId" = $1::uuid
and "deviceId" = $2
@@ -164,22 +164,22 @@ where
select
count(*) as "count"
from
"assets"
"asset"
where
"livePhotoVideoId" = $1::uuid
-- AssetRepository.getById
select
"assets".*
"asset".*
from
"assets"
"asset"
where
"assets"."id" = $1::uuid
"asset"."id" = $1::uuid
limit
$2
-- AssetRepository.updateAll
update "assets"
update "asset"
set
"deviceId" = $1
where
@@ -187,9 +187,9 @@ where
-- AssetRepository.getByChecksum
select
"assets".*
"asset".*
from
"assets"
"asset"
where
"ownerId" = $1::uuid
and "checksum" = $2
@@ -203,7 +203,7 @@ select
"checksum",
"deletedAt"
from
"assets"
"asset"
where
"ownerId" = $1::uuid
and "checksum" in ($2)
@@ -212,7 +212,7 @@ where
select
"id"
from
"assets"
"asset"
where
"ownerId" = $1::uuid
and "checksum" = $2
@@ -222,20 +222,20 @@ limit
-- AssetRepository.getTimeBuckets
with
"assets" as (
"asset" as (
select
date_trunc('MONTH', "localDateTime" AT TIME ZONE 'UTC') AT TIME ZONE 'UTC' as "timeBucket"
from
"assets"
"asset"
where
"assets"."deletedAt" is null
and "assets"."visibility" in ('archive', 'timeline')
"asset"."deletedAt" is null
and "asset"."visibility" in ('archive', 'timeline')
)
select
("timeBucket" AT TIME ZONE 'UTC')::date::text as "timeBucket",
count(*) as "count"
from
"assets"
"asset"
group by
"timeBucket"
order by
@@ -245,37 +245,37 @@ order by
with
"cte" as (
select
"assets"."duration",
"assets"."id",
"assets"."visibility",
"assets"."isFavorite",
assets.type = 'IMAGE' as "isImage",
assets."deletedAt" is not null as "isTrashed",
"assets"."livePhotoVideoId",
"asset"."duration",
"asset"."id",
"asset"."visibility",
"asset"."isFavorite",
asset.type = 'IMAGE' as "isImage",
asset."deletedAt" is not null as "isTrashed",
"asset"."livePhotoVideoId",
extract(
epoch
from
(
assets."localDateTime" - assets."fileCreatedAt" at time zone 'UTC'
asset."localDateTime" - asset."fileCreatedAt" at time zone 'UTC'
)
)::real / 3600 as "localOffsetHours",
"assets"."ownerId",
"assets"."status",
assets."fileCreatedAt" at time zone 'utc' as "fileCreatedAt",
encode("assets"."thumbhash", 'base64') as "thumbhash",
"exif"."city",
"exif"."country",
"exif"."projectionType",
"asset"."ownerId",
"asset"."status",
asset."fileCreatedAt" at time zone 'utc' as "fileCreatedAt",
encode("asset"."thumbhash", 'base64') as "thumbhash",
"asset_exif"."city",
"asset_exif"."country",
"asset_exif"."projectionType",
coalesce(
case
when exif."exifImageHeight" = 0
or exif."exifImageWidth" = 0 then 1
when "exif"."orientation" in ('5', '6', '7', '8', '-90', '90') then round(
exif."exifImageHeight"::numeric / exif."exifImageWidth"::numeric,
when asset_exif."exifImageHeight" = 0
or asset_exif."exifImageWidth" = 0 then 1
when "asset_exif"."orientation" in ('5', '6', '7', '8', '-90', '90') then round(
asset_exif."exifImageHeight"::numeric / asset_exif."exifImageWidth"::numeric,
3
)
else round(
exif."exifImageWidth"::numeric / exif."exifImageHeight"::numeric,
asset_exif."exifImageWidth"::numeric / asset_exif."exifImageHeight"::numeric,
3
)
end,
@@ -283,34 +283,34 @@ with
) as "ratio",
"stack"
from
"assets"
inner join "exif" on "assets"."id" = "exif"."assetId"
"asset"
inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
left join lateral (
select
array[stacked."stackId"::text, count('stacked')::text] as "stack"
from
"assets" as "stacked"
"asset" as "stacked"
where
"stacked"."stackId" = "assets"."stackId"
"stacked"."stackId" = "asset"."stackId"
and "stacked"."deletedAt" is null
and "stacked"."visibility" = $1
group by
"stacked"."stackId"
) as "stacked_assets" on true
where
"assets"."deletedAt" is null
and "assets"."visibility" in ('archive', 'timeline')
"asset"."deletedAt" is null
and "asset"."visibility" in ('archive', 'timeline')
and date_trunc('MONTH', "localDateTime" AT TIME ZONE 'UTC') AT TIME ZONE 'UTC' = $2
and not exists (
select
from
"asset_stack"
"stack"
where
"asset_stack"."id" = "assets"."stackId"
and "asset_stack"."primaryAssetId" != "assets"."id"
"stack"."id" = "asset"."stackId"
and "stack"."primaryAssetId" != "asset"."id"
)
order by
"assets"."fileCreatedAt" desc
"asset"."fileCreatedAt" desc
),
"agg" as (
select
@@ -345,7 +345,7 @@ with
select
"city"
from
"exif"
"asset_exif"
where
"city" is not null
group by
@@ -354,12 +354,12 @@ with
count("assetId") >= $1
)
select distinct
on ("exif"."city") "assetId" as "data",
"exif"."city" as "value"
on ("asset_exif"."city") "assetId" as "data",
"asset_exif"."city" as "value"
from
"assets"
inner join "exif" on "assets"."id" = "exif"."assetId"
inner join "cities" on "exif"."city" = "cities"."city"
"asset"
inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
inner join "cities" on "asset_exif"."city" = "cities"."city"
where
"ownerId" = $2::uuid
and "visibility" = $3
@@ -370,63 +370,63 @@ limit
-- AssetRepository.getAllForUserFullSync
select
"assets".*,
to_json("exif") as "exifInfo",
"asset".*,
to_json("asset_exif") as "exifInfo",
to_json("stacked_assets") as "stack"
from
"assets"
left join "exif" on "assets"."id" = "exif"."assetId"
left join "asset_stack" on "asset_stack"."id" = "assets"."stackId"
"asset"
left join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
left join "stack" on "stack"."id" = "asset"."stackId"
left join lateral (
select
"asset_stack".*,
"stack".*,
count("stacked") as "assetCount"
from
"assets" as "stacked"
"asset" as "stacked"
where
"stacked"."stackId" = "asset_stack"."id"
"stacked"."stackId" = "stack"."id"
group by
"asset_stack"."id"
) as "stacked_assets" on "asset_stack"."id" is not null
"stack"."id"
) as "stacked_assets" on "stack"."id" is not null
where
"assets"."ownerId" = $1::uuid
and "assets"."visibility" != $2
and "assets"."updatedAt" <= $3
and "assets"."id" > $4
"asset"."ownerId" = $1::uuid
and "asset"."visibility" != $2
and "asset"."updatedAt" <= $3
and "asset"."id" > $4
order by
"assets"."id"
"asset"."id"
limit
$5
-- AssetRepository.getChangedDeltaSync
select
"assets".*,
to_json("exif") as "exifInfo",
"asset".*,
to_json("asset_exif") as "exifInfo",
to_json("stacked_assets") as "stack"
from
"assets"
left join "exif" on "assets"."id" = "exif"."assetId"
left join "asset_stack" on "asset_stack"."id" = "assets"."stackId"
"asset"
left join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
left join "stack" on "stack"."id" = "asset"."stackId"
left join lateral (
select
"asset_stack".*,
"stack".*,
count("stacked") as "assetCount"
from
"assets" as "stacked"
"asset" as "stacked"
where
"stacked"."stackId" = "asset_stack"."id"
"stacked"."stackId" = "stack"."id"
group by
"asset_stack"."id"
) as "stacked_assets" on "asset_stack"."id" is not null
"stack"."id"
) as "stacked_assets" on "stack"."id" is not null
where
"assets"."ownerId" = any ($1::uuid[])
and "assets"."visibility" != $2
and "assets"."updatedAt" > $3
"asset"."ownerId" = any ($1::uuid[])
and "asset"."visibility" != $2
and "asset"."updatedAt" > $3
limit
$4
-- AssetRepository.detectOfflineExternalAssets
update "assets"
update "asset"
set
"isOffline" = $1,
"deletedAt" = $2
@@ -449,9 +449,9 @@ where
select
"originalPath"
from
"assets"
"asset"
where
"assets"."originalPath" = "path"
"asset"."originalPath" = "path"
and "libraryId" = $2::uuid
and "isExternal" = $3
)