Skip to content

High performance self-hosted photo and video management solution.

22.1 KB
Raw Blame
-- NOTE: This file is auto generated by ./sql-generator

-- AssetJobRepository.getForSearchDuplicatesJob
select
  "id",
  "type",
  "ownerId",
  "duplicateId",
  "stackId",
  "visibility",
  "smart_search"."embedding"
from
  "asset"
  left join "smart_search" on "asset"."id" = "smart_search"."assetId"
where
  "asset"."id" = $1::uuid
limit
  $2

-- AssetJobRepository.getForSidecarWriteJob
select
  "id",
  "originalPath",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = $1
      ) as agg
  ) as "files",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_exif"."assetId",
          "asset_exif"."autoStackId",
          "asset_exif"."bitsPerSample",
          "asset_exif"."city",
          "asset_exif"."colorspace",
          "asset_exif"."country",
          "asset_exif"."dateTimeOriginal",
          "asset_exif"."description",
          "asset_exif"."exifImageHeight",
          "asset_exif"."exifImageWidth",
          "asset_exif"."exposureTime",
          "asset_exif"."fileSizeInByte",
          "asset_exif"."fNumber",
          "asset_exif"."focalLength",
          "asset_exif"."fps",
          "asset_exif"."iso",
          "asset_exif"."latitude",
          "asset_exif"."lensModel",
          "asset_exif"."livePhotoCID",
          "asset_exif"."longitude",
          "asset_exif"."make",
          "asset_exif"."model",
          "asset_exif"."modifyDate",
          "asset_exif"."orientation",
          "asset_exif"."profileDescription",
          "asset_exif"."projectionType",
          "asset_exif"."rating",
          "asset_exif"."state",
          "asset_exif"."tags",
          "asset_exif"."timeZone"
        from
          "asset_exif"
        where
          "asset_exif"."assetId" = "asset"."id"
      ) as obj
  ) as "exifInfo"
from
  "asset"
  inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
where
  "asset"."id" = $2::uuid
limit
  $3

-- AssetJobRepository.getForSidecarCheckJob
select
  "id",
  "originalPath",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = $1
      ) as agg
  ) as "files"
from
  "asset"
where
  "asset"."id" = $2::uuid
limit
  $3

-- AssetJobRepository.streamForThumbnailJob
select
  "asset"."id",
  "asset"."isEdited"
from
  "asset"
  inner join "asset_job_status" on "asset_job_status"."assetId" = "asset"."id"
where
  "asset"."deletedAt" is null
  and "asset"."visibility" != 'hidden'
  and (
    not exists (
      select
      from
        "asset_file"
      where
        "assetId" = "asset"."id"
        and "type" = 'thumbnail'
    )
    or not exists (
      select
      from
        "asset_file"
      where
        "assetId" = "asset"."id"
        and "type" = 'preview'
    )
    or (
      "asset"."isEdited" = true
      and not exists (
        select
        from
          "asset_file"
        where
          "assetId" = "asset"."id"
          and "type" = 'fullsize'
          and "asset_file"."isEdited" = true
      )
    )
    or "asset"."thumbhash" is null
    or (
      not exists (
        select
        from
          "asset_file"
        where
          "assetId" = "asset"."id"
          and "type" = 'fullsize'
      )
      and f_unaccent (asset."originalFileName") like any (
        array[
          '%.3fr',
          '%.ari',
          '%.arw',
          '%.cap',
          '%.cin',
          '%.cr2',
          '%.cr3',
          '%.crw',
          '%.dcr',
          '%.dng',
          '%.erf',
          '%.fff',
          '%.iiq',
          '%.k25',
          '%.kdc',
          '%.mrw',
          '%.nef',
          '%.nrw',
          '%.orf',
          '%.ori',
          '%.pef',
          '%.psd',
          '%.raf',
          '%.raw',
          '%.rw2',
          '%.rwl',
          '%.sr2',
          '%.srf',
          '%.srw',
          '%.x3f',
          '%.heic',
          '%.heif',
          '%.hif',
          '%.insp',
          '%.jp2',
          '%.jpe',
          '%.jxl',
          '%.mpo',
          '%.svg',
          '%.tif',
          '%.tiff'
        ]::text[]
      )
    )
  )

-- AssetJobRepository.getForMigrationJob
select
  "asset"."id",
  "asset"."ownerId",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
      ) as agg
  ) as "files"
from
  "asset"
where
  "asset"."id" = $1

-- AssetJobRepository.getForGenerateThumbnailJob
select
  "asset"."id",
  "asset"."visibility",
  "asset"."originalFileName",
  "asset"."originalPath",
  "asset"."ownerId",
  "asset"."thumbhash",
  "asset"."type",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited",
          "asset_file"."isProgressive",
          "asset_file"."isTransparent"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" in ($1, $2, $3)
      ) as agg
  ) as "files",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_edit"."action",
          "asset_edit"."parameters"
        from
          "asset_edit"
        where
          "asset_edit"."assetId" = "asset"."id"
      ) as agg
  ) as "edits",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_exif"."assetId",
          "asset_exif"."autoStackId",
          "asset_exif"."bitsPerSample",
          "asset_exif"."city",
          "asset_exif"."colorspace",
          "asset_exif"."country",
          "asset_exif"."dateTimeOriginal",
          "asset_exif"."description",
          "asset_exif"."exifImageHeight",
          "asset_exif"."exifImageWidth",
          "asset_exif"."exposureTime",
          "asset_exif"."fileSizeInByte",
          "asset_exif"."fNumber",
          "asset_exif"."focalLength",
          "asset_exif"."fps",
          "asset_exif"."iso",
          "asset_exif"."latitude",
          "asset_exif"."lensModel",
          "asset_exif"."livePhotoCID",
          "asset_exif"."longitude",
          "asset_exif"."make",
          "asset_exif"."model",
          "asset_exif"."modifyDate",
          "asset_exif"."orientation",
          "asset_exif"."profileDescription",
          "asset_exif"."projectionType",
          "asset_exif"."rating",
          "asset_exif"."state",
          "asset_exif"."tags",
          "asset_exif"."timeZone"
        from
          "asset_exif"
        where
          "asset_exif"."assetId" = "asset"."id"
      ) as obj
  ) as "exifInfo",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_video"."index",
          "asset_video"."codecName",
          "asset_video"."profile",
          "asset_video"."level",
          "asset_video"."bitrate",
          "asset_exif"."exifImageWidth" as "width",
          "asset_exif"."exifImageHeight" as "height",
          "asset_video"."pixelFormat",
          "asset_video"."frameCount",
          "asset_exif"."fps" as "frameRate",
          "asset_video"."timeBase",
          case
            when "asset_exif"."orientation" = '6' then -90
            when "asset_exif"."orientation" = '8' then 90
            when "asset_exif"."orientation" = '3' then 180
            else 0
          end as "rotation",
          "asset_video"."colorPrimaries",
          "asset_video"."colorMatrix",
          "asset_video"."colorTransfer",
          "asset_video"."dvProfile",
          "asset_video"."dvLevel",
          "asset_video"."dvBlSignalCompatibilityId"
        from
          (
            select
              1
          ) as "dummy"
        where
          "asset_video"."assetId" is not null
      ) as obj
  ) as "videoStream",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_video"."formatName",
          "asset_video"."formatLongName",
          "asset"."duration",
          "asset_video"."bitrate"
        from
          (
            select
              1
          ) as "dummy"
        where
          "asset_video"."assetId" is not null
      ) as obj
  ) as "format"
from
  "asset"
  inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
  left join "asset_video" on "asset_video"."assetId" = "asset"."id"
where
  "asset"."id" = $4

-- AssetJobRepository.getForMetadataExtraction
select
  "asset"."id",
  "asset"."checksum",
  "asset"."checksumAlgorithm",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."isExternal",
  "asset"."visibility",
  "asset"."libraryId",
  "asset"."livePhotoVideoId",
  "asset"."localDateTime",
  "asset"."originalFileName",
  "asset"."originalPath",
  "asset"."ownerId",
  "asset"."type",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_face".*
        from
          "asset_face"
        where
          "asset_face"."assetId" = "asset"."id"
          and "asset_face"."deletedAt" is null
          and "asset_face"."isVisible" = $1
      ) as agg
  ) as "faces",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = $2
      ) as agg
  ) as "files",
  "user"."clusterGroupId"
from
  "asset"
  inner join "user" on "user"."id" = "asset"."ownerId"
where
  "asset"."id" = $3

-- AssetJobRepository.getLockedPropertiesForMetadataExtraction
select
  "asset_exif"."lockedProperties"
from
  "asset_exif"
where
  "asset_exif"."assetId" = $1

-- AssetJobRepository.getAlbumThumbnailFiles
select
  "asset_file"."id",
  "asset_file"."path",
  "asset_file"."type",
  "asset_file"."isEdited"
from
  "asset_file"
where
  "asset_file"."assetId" = $1
  and "asset_file"."type" = $2

-- AssetJobRepository.streamForSearchDuplicates
select
  "asset"."id"
from
  "asset"
  inner join "smart_search" on "asset"."id" = "smart_search"."assetId"
  inner join "asset_job_status" as "job_status" on "job_status"."assetId" = "asset"."id"
where
  "asset"."deletedAt" is null
  and "asset"."visibility" in ('archive', 'timeline')
  and "job_status"."duplicatesDetectedAt" is null

-- AssetJobRepository.streamForEncodeClip
select
  "asset"."id"
from
  "asset"
  inner join "asset_job_status" as "job_status" on "assetId" = "asset"."id"
where
  "asset"."visibility" != $1
  and "asset"."deletedAt" is null
  and exists (
    select
    from
      "asset_file"
    where
      "assetId" = "asset"."id"
      and "asset_file"."type" = $2
  )
  and not exists (
    select
    from
      "smart_search"
    where
      "assetId" = "asset"."id"
  )

-- AssetJobRepository.getForClipEncoding
select
  "asset"."id",
  "asset"."visibility",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = $1
      ) as agg
  ) as "files"
from
  "asset"
where
  "asset"."id" = $2

-- AssetJobRepository.getForDetectFacesJob
select
  "asset"."id",
  "asset"."visibility",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_exif"."assetId",
          "asset_exif"."autoStackId",
          "asset_exif"."bitsPerSample",
          "asset_exif"."city",
          "asset_exif"."colorspace",
          "asset_exif"."country",
          "asset_exif"."dateTimeOriginal",
          "asset_exif"."description",
          "asset_exif"."exifImageHeight",
          "asset_exif"."exifImageWidth",
          "asset_exif"."exposureTime",
          "asset_exif"."fileSizeInByte",
          "asset_exif"."fNumber",
          "asset_exif"."focalLength",
          "asset_exif"."fps",
          "asset_exif"."iso",
          "asset_exif"."latitude",
          "asset_exif"."lensModel",
          "asset_exif"."livePhotoCID",
          "asset_exif"."longitude",
          "asset_exif"."make",
          "asset_exif"."model",
          "asset_exif"."modifyDate",
          "asset_exif"."orientation",
          "asset_exif"."profileDescription",
          "asset_exif"."projectionType",
          "asset_exif"."rating",
          "asset_exif"."state",
          "asset_exif"."tags",
          "asset_exif"."timeZone"
        from
          "asset_exif"
        where
          "asset_exif"."assetId" = "asset"."id"
      ) as obj
  ) as "exifInfo",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_face".*
        from
          "asset_face"
        where
          "asset_face"."assetId" = "asset"."id"
      ) as agg
  ) as "faces",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = 'preview'
        order by
          "asset_file"."isEdited" desc
        limit
          1
      ) as obj
  ) as "previewFile"
from
  "asset"
  inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
where
  "asset"."id" = $1

-- AssetJobRepository.getForOcr
select
  "asset"."ownerId",
  "asset"."visibility",
  (
    select
      "asset_file"."path"
    from
      "asset_file"
    where
      "asset_file"."assetId" = "asset"."id"
      and "asset_file"."type" = 'preview'
      and "asset_file"."isEdited" = false
  ) as "previewFile"
from
  "asset"
where
  "asset"."id" = $1

-- AssetJobRepository.getForSyncAssets
select
  "asset"."id",
  "asset"."isOffline",
  "asset"."libraryId",
  "asset"."originalPath",
  "asset"."status",
  "asset"."fileModifiedAt"
from
  "asset"
where
  "asset"."id" = any ($1::uuid[])

-- AssetJobRepository.getForAssetDeletion
select
  "asset"."id",
  "asset"."visibility",
  "asset"."libraryId",
  "asset"."ownerId",
  "asset"."livePhotoVideoId",
  "asset"."originalPath",
  "asset"."isOffline",
  to_json("asset_exif") as "exifInfo",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
      ) as agg
  ) as "files",
  to_json("stack_result") as "stack"
from
  "asset"
  left join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
  left join lateral (
    select
      "stack"."id",
      "stack"."primaryAssetId",
      (
        select
          coalesce(json_agg(agg), '[]')
        from
          (
            select
              "stack_asset"."id"
            from
              "asset" as "stack_asset"
            where
              "stack_asset"."stackId" = "stack"."id"
              and "stack_asset"."id" != "stack"."primaryAssetId"
              and "stack_asset"."visibility" = $1
              and "stack_asset"."status" != $2
          ) as agg
      ) as "assets"
    from
      "stack"
    where
      "stack"."id" = "asset"."stackId"
  ) as "stack_result" on true
where
  "asset"."id" = $3

-- AssetJobRepository.streamForVideoConversion
select
  "asset"."id"
from
  "asset"
where
  "asset"."type" = 'VIDEO'
  and not exists (
    select
      "asset_file"."id"
    from
      "asset_file"
    where
      "asset_file"."assetId" = "asset"."id"
      and "asset_file"."type" = 'encoded_video'
  )
  and "asset"."deletedAt" is null

-- AssetJobRepository.getForVideoConversion
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalPath",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
      ) as agg
  ) as "files",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_audio"."index",
          "asset_audio"."codecName",
          "asset_audio"."profile",
          "asset_audio"."bitrate"
        from
          (
            select
              1
          ) as "dummy"
        where
          "asset_audio"."assetId" is not null
      ) as obj
  ) as "audioStream",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_video"."index",
          "asset_video"."codecName",
          "asset_video"."profile",
          "asset_video"."level",
          "asset_video"."bitrate",
          "asset_exif"."exifImageWidth" as "width",
          "asset_exif"."exifImageHeight" as "height",
          "asset_video"."pixelFormat",
          "asset_video"."frameCount",
          "asset_exif"."fps" as "frameRate",
          "asset_video"."timeBase",
          case
            when "asset_exif"."orientation" = '6' then -90
            when "asset_exif"."orientation" = '8' then 90
            when "asset_exif"."orientation" = '3' then 180
            else 0
          end as "rotation",
          "asset_video"."colorPrimaries",
          "asset_video"."colorMatrix",
          "asset_video"."colorTransfer",
          "asset_video"."dvProfile",
          "asset_video"."dvLevel",
          "asset_video"."dvBlSignalCompatibilityId"
        from
          (
            select
              1
          ) as "dummy"
        where
          "asset_video"."assetId" is not null
      ) as obj
  ) as "videoStream",
  (
    select
      to_json(obj)
    from
      (
        select
          "asset_video"."formatName",
          "asset_video"."formatLongName",
          "asset"."duration",
          "asset_video"."bitrate"
        from
          (
            select
              1
          ) as "dummy"
        where
          "asset_video"."assetId" is not null
      ) as obj
  ) as "format"
from
  "asset"
  inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
  inner join "asset_video" on "asset_video"."assetId" = "asset"."id"
  left join "asset_audio" on "asset_audio"."assetId" = "asset"."id"
where
  "asset"."id" = $1
  and "asset"."type" = 'VIDEO'

-- AssetJobRepository.streamForMetadataExtraction
select
  "asset"."id"
from
  "asset"
  left join "asset_job_status" on "asset_job_status"."assetId" = "asset"."id"
where
  (
    "asset_job_status"."metadataExtractedAt" is null
    or "asset_job_status"."assetId" is null
  )
  and "asset"."deletedAt" is null

-- AssetJobRepository.getForStorageTemplateJob
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."type",
  "asset"."checksum",
  "asset"."originalPath",
  "asset"."isExternal",
  "asset"."visibility",
  "asset"."originalFileName",
  "asset"."livePhotoVideoId",
  "asset"."fileCreatedAt",
  "asset_exif"."timeZone",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = $1
      ) as agg
  ) as "files"
from
  "asset"
  inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
where
  "asset"."deletedAt" is null
  and "asset"."id" = $2
  and "asset"."visibility" != $3

-- AssetJobRepository.streamForStorageTemplateJob
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."type",
  "asset"."checksum",
  "asset"."originalPath",
  "asset"."isExternal",
  "asset"."visibility",
  "asset"."originalFileName",
  "asset"."livePhotoVideoId",
  "asset"."fileCreatedAt",
  "asset_exif"."timeZone",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  (
    select
      coalesce(json_agg(agg), '[]')
    from
      (
        select
          "asset_file"."id",
          "asset_file"."path",
          "asset_file"."type",
          "asset_file"."isEdited"
        from
          "asset_file"
        where
          "asset_file"."assetId" = "asset"."id"
          and "asset_file"."type" = $1
      ) as agg
  ) as "files"
from
  "asset"
  inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId"
where
  "asset"."deletedAt" is null
  and "asset"."visibility" != $2

-- AssetJobRepository.streamForDeletedJob
select
  "id"
from
  "asset"
where
  "asset"."deletedAt" <= $1

-- AssetJobRepository.streamForSidecar
select
  "asset"."id"
from
  "asset"
where
  not exists (
    select
      "asset_file"."id"
    from
      "asset_file"
    where
      "asset_file"."assetId" = "asset"."id"
      and "asset_file"."type" = $1
  )

-- AssetJobRepository.streamForDetectFacesJob
select
  "asset"."id"
from
  "asset"
  inner join "asset_job_status" as "job_status" on "assetId" = "asset"."id"
where
  "asset"."visibility" != $1
  and "asset"."deletedAt" is null
  and exists (
    select
    from
      "asset_file"
    where
      "assetId" = "asset"."id"
      and "asset_file"."type" = $2
  )
order by
  "asset"."fileCreatedAt" desc

-- AssetJobRepository.streamForOcrJob
select
  "asset"."id"
from
  "asset"
  inner join "asset_job_status" on "asset_job_status"."assetId" = "asset"."id"
where
  "asset_job_status"."ocrAt" is null
  and "asset"."deletedAt" is null
  and "asset"."visibility" != $1

-- AssetJobRepository.streamForMigrationJob
select
  "id"
from
  "asset"
where
  "asset"."deletedAt" is null