-- NOTE: This file is auto generated by ./sql-generator

-- SyncRepository.album.getCreatedAfter
select
  "albumId" as "id",
  "createId"
from
  "album_user"
where
  "userId" = $1
  and "createId" >= $2
  and "createId" < $3
order by
  "createId" asc

-- SyncRepository.album.getDeletes
select
  "id",
  "albumId"
from
  "album_audit" as "album_audit"
where
  "album_audit"."id" < $1
  and "album_audit"."id" > $2
  and "userId" = $3
order by
  "album_audit"."id" asc

-- SyncRepository.album.getUpserts
select distinct
  on ("album"."id", "album"."updateId") "album"."id",
  "album"."ownerId",
  "album"."albumName" as "name",
  "album"."description",
  "album"."createdAt",
  "album"."updatedAt",
  "album"."albumThumbnailAssetId" as "thumbnailAssetId",
  "album"."isActivityEnabled",
  "album"."order",
  "album"."updateId"
from
  "album" as "album"
  left join "album_user" as "album_users" on "album"."id" = "album_users"."albumId"
where
  "album"."updateId" < $1
  and "album"."updateId" > $2
  and (
    "album"."ownerId" = $3
    or "album_users"."userId" = $4
  )
order by
  "album"."updateId" asc

-- SyncRepository.albumAsset.getBackfill
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalFileName",
  "asset"."thumbhash",
  "asset"."checksum",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."localDateTime",
  "asset"."type",
  "asset"."deletedAt",
  "asset"."isFavorite",
  "asset"."visibility",
  "asset"."duration",
  "asset"."livePhotoVideoId",
  "asset"."stackId",
  "asset"."libraryId",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited",
  "album_asset"."updateId"
from
  "album_asset" as "album_asset"
  inner join "asset" on "asset"."id" = "album_asset"."assetId"
where
  "album_asset"."updateId" < $1
  and "album_asset"."updateId" <= $2
  and "album_asset"."updateId" >= $3
  and "album_asset"."albumId" = $4
order by
  "album_asset"."updateId" asc

-- SyncRepository.albumAsset.getUpdates
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalFileName",
  "asset"."thumbhash",
  "asset"."checksum",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."localDateTime",
  "asset"."type",
  "asset"."deletedAt",
  "asset"."isFavorite",
  "asset"."visibility",
  "asset"."duration",
  "asset"."livePhotoVideoId",
  "asset"."stackId",
  "asset"."libraryId",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited",
  "asset"."updateId"
from
  "asset" as "asset"
  inner join "album_asset" on "album_asset"."assetId" = "asset"."id"
  inner join "album" on "album"."id" = "album_asset"."albumId"
  left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where
  "asset"."updateId" < $1
  and "asset"."updateId" > $2
  and "album_asset"."updateId" <= $3
  and (
    "album"."ownerId" = $4
    or "album_user"."userId" = $5
  )
order by
  "asset"."updateId" asc

-- SyncRepository.albumAsset.getCreates
select
  "album_asset"."updateId",
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalFileName",
  "asset"."thumbhash",
  "asset"."checksum",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."localDateTime",
  "asset"."type",
  "asset"."deletedAt",
  "asset"."isFavorite",
  "asset"."visibility",
  "asset"."duration",
  "asset"."livePhotoVideoId",
  "asset"."stackId",
  "asset"."libraryId",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited"
from
  "album_asset" as "album_asset"
  inner join "asset" on "asset"."id" = "album_asset"."assetId"
  inner join "album" on "album"."id" = "album_asset"."albumId"
  left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where
  "album_asset"."updateId" < $1
  and "album_asset"."updateId" > $2
  and (
    "album"."ownerId" = $3
    or "album_user"."userId" = $4
  )
order by
  "album_asset"."updateId" asc

-- SyncRepository.albumAssetExif.getBackfill
select
  "asset_exif"."assetId",
  "asset_exif"."description",
  "asset_exif"."exifImageWidth",
  "asset_exif"."exifImageHeight",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."orientation",
  "asset_exif"."dateTimeOriginal",
  "asset_exif"."modifyDate",
  "asset_exif"."timeZone",
  "asset_exif"."latitude",
  "asset_exif"."longitude",
  "asset_exif"."projectionType",
  "asset_exif"."city",
  "asset_exif"."state",
  "asset_exif"."country",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  "asset_exif"."fNumber",
  "asset_exif"."focalLength",
  "asset_exif"."iso",
  "asset_exif"."exposureTime",
  "asset_exif"."profileDescription",
  "asset_exif"."rating",
  "asset_exif"."fps",
  "album_asset"."updateId"
from
  "album_asset" as "album_asset"
  inner join "asset_exif" on "asset_exif"."assetId" = "album_asset"."assetId"
where
  "album_asset"."updateId" < $1
  and "album_asset"."updateId" <= $2
  and "album_asset"."updateId" >= $3
  and "album_asset"."albumId" = $4
order by
  "album_asset"."updateId" asc

-- SyncRepository.albumAssetExif.getUpdates
select
  "asset_exif"."assetId",
  "asset_exif"."description",
  "asset_exif"."exifImageWidth",
  "asset_exif"."exifImageHeight",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."orientation",
  "asset_exif"."dateTimeOriginal",
  "asset_exif"."modifyDate",
  "asset_exif"."timeZone",
  "asset_exif"."latitude",
  "asset_exif"."longitude",
  "asset_exif"."projectionType",
  "asset_exif"."city",
  "asset_exif"."state",
  "asset_exif"."country",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  "asset_exif"."fNumber",
  "asset_exif"."focalLength",
  "asset_exif"."iso",
  "asset_exif"."exposureTime",
  "asset_exif"."profileDescription",
  "asset_exif"."rating",
  "asset_exif"."fps",
  "asset_exif"."updateId"
from
  "asset_exif" as "asset_exif"
  inner join "album_asset" on "album_asset"."assetId" = "asset_exif"."assetId"
  inner join "album" on "album"."id" = "album_asset"."albumId"
  left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where
  "asset_exif"."updateId" < $1
  and "asset_exif"."updateId" > $2
  and "album_asset"."updateId" <= $3
  and (
    "album"."ownerId" = $4
    or "album_user"."userId" = $5
  )
order by
  "asset_exif"."updateId" asc

-- SyncRepository.albumAssetExif.getCreates
select
  "album_asset"."updateId",
  "asset_exif"."assetId",
  "asset_exif"."description",
  "asset_exif"."exifImageWidth",
  "asset_exif"."exifImageHeight",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."orientation",
  "asset_exif"."dateTimeOriginal",
  "asset_exif"."modifyDate",
  "asset_exif"."timeZone",
  "asset_exif"."latitude",
  "asset_exif"."longitude",
  "asset_exif"."projectionType",
  "asset_exif"."city",
  "asset_exif"."state",
  "asset_exif"."country",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  "asset_exif"."fNumber",
  "asset_exif"."focalLength",
  "asset_exif"."iso",
  "asset_exif"."exposureTime",
  "asset_exif"."profileDescription",
  "asset_exif"."rating",
  "asset_exif"."fps"
from
  "album_asset" as "album_asset"
  inner join "asset_exif" on "asset_exif"."assetId" = "album_asset"."assetId"
  inner join "album" on "album"."id" = "album_asset"."albumId"
  left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where
  "album_asset"."updateId" < $1
  and "album_asset"."updateId" > $2
  and (
    "album"."ownerId" = $3
    or "album_user"."userId" = $4
  )
order by
  "album_asset"."updateId" asc

-- SyncRepository.albumToAsset.getBackfill
select
  "album_asset"."assetId" as "assetId",
  "album_asset"."albumId" as "albumId",
  "album_asset"."updateId"
from
  "album_asset" as "album_asset"
where
  "album_asset"."updateId" < $1
  and "album_asset"."updateId" <= $2
  and "album_asset"."updateId" >= $3
  and "album_asset"."albumId" = $4
order by
  "album_asset"."updateId" asc

-- SyncRepository.albumToAsset.getDeletes
select
  "id",
  "assetId",
  "albumId"
from
  "album_asset_audit" as "album_asset_audit"
where
  "album_asset_audit"."id" < $1
  and "album_asset_audit"."id" > $2
  and "albumId" in (
    select
      "id"
    from
      "album"
    where
      "ownerId" = $3
    union
    (
      select
        "album_user"."albumId" as "id"
      from
        "album_user"
      where
        "album_user"."userId" = $4
    )
  )
order by
  "album_asset_audit"."id" asc

-- SyncRepository.albumToAsset.getUpserts
select
  "album_asset"."assetId" as "assetId",
  "album_asset"."albumId" as "albumId",
  "album_asset"."updateId"
from
  "album_asset" as "album_asset"
  inner join "album" on "album"."id" = "album_asset"."albumId"
  left join "album_user" on "album_user"."albumId" = "album_asset"."albumId"
where
  "album_asset"."updateId" < $1
  and "album_asset"."updateId" > $2
  and (
    "album"."ownerId" = $3
    or "album_user"."userId" = $4
  )
order by
  "album_asset"."updateId" asc

-- SyncRepository.albumUser.getBackfill
select
  "album_user"."albumId" as "albumId",
  "album_user"."userId" as "userId",
  "album_user"."role",
  "album_user"."updateId"
from
  "album_user" as "album_user"
where
  "album_user"."updateId" < $1
  and "album_user"."updateId" <= $2
  and "album_user"."updateId" >= $3
  and "albumId" = $4
order by
  "album_user"."updateId" asc

-- SyncRepository.albumUser.getDeletes
select
  "id",
  "userId",
  "albumId"
from
  "album_user_audit" as "album_user_audit"
where
  "album_user_audit"."id" < $1
  and "album_user_audit"."id" > $2
  and "albumId" in (
    select
      "id"
    from
      "album"
    where
      "ownerId" = $3
    union
    (
      select
        "album_user"."albumId" as "id"
      from
        "album_user"
      where
        "album_user"."userId" = $4
    )
  )
order by
  "album_user_audit"."id" asc

-- SyncRepository.albumUser.getUpserts
select
  "album_user"."albumId" as "albumId",
  "album_user"."userId" as "userId",
  "album_user"."role",
  "album_user"."updateId"
from
  "album_user" as "album_user"
where
  "album_user"."updateId" < $1
  and "album_user"."updateId" > $2
  and "album_user"."albumId" in (
    select
      "id"
    from
      "album"
    where
      "ownerId" = $3
    union
    (
      select
        "albumUsers"."albumId" as "id"
      from
        "album_user" as "albumUsers"
      where
        "albumUsers"."userId" = $4
    )
  )
order by
  "album_user"."updateId" asc

-- SyncRepository.asset.getDeletes
select
  "id",
  "assetId"
from
  "asset_audit" as "asset_audit"
where
  "asset_audit"."id" < $1
  and "asset_audit"."id" > $2
  and "ownerId" = $3
order by
  "asset_audit"."id" asc

-- SyncRepository.asset.getUpserts
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalFileName",
  "asset"."thumbhash",
  "asset"."checksum",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."localDateTime",
  "asset"."type",
  "asset"."deletedAt",
  "asset"."isFavorite",
  "asset"."visibility",
  "asset"."duration",
  "asset"."livePhotoVideoId",
  "asset"."stackId",
  "asset"."libraryId",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited",
  "asset"."updateId"
from
  "asset" as "asset"
where
  "asset"."updateId" < $1
  and "asset"."updateId" > $2
  and "ownerId" = $3
order by
  "asset"."updateId" asc

-- SyncRepository.assetExif.getUpserts
select
  "asset_exif"."assetId",
  "asset_exif"."description",
  "asset_exif"."exifImageWidth",
  "asset_exif"."exifImageHeight",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."orientation",
  "asset_exif"."dateTimeOriginal",
  "asset_exif"."modifyDate",
  "asset_exif"."timeZone",
  "asset_exif"."latitude",
  "asset_exif"."longitude",
  "asset_exif"."projectionType",
  "asset_exif"."city",
  "asset_exif"."state",
  "asset_exif"."country",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  "asset_exif"."fNumber",
  "asset_exif"."focalLength",
  "asset_exif"."iso",
  "asset_exif"."exposureTime",
  "asset_exif"."profileDescription",
  "asset_exif"."rating",
  "asset_exif"."fps",
  "asset_exif"."updateId"
from
  "asset_exif" as "asset_exif"
where
  "asset_exif"."updateId" < $1
  and "asset_exif"."updateId" > $2
  and "assetId" in (
    select
      "id"
    from
      "asset"
    where
      "ownerId" = $3
  )
order by
  "asset_exif"."updateId" asc

-- SyncRepository.assetFace.getDeletes
select
  "asset_face_audit"."id",
  "assetFaceId"
from
  "asset_face_audit" as "asset_face_audit"
  left join "asset" on "asset"."id" = "asset_face_audit"."assetId"
where
  "asset_face_audit"."id" < $1
  and "asset_face_audit"."id" > $2
  and "asset"."ownerId" = $3
order by
  "asset_face_audit"."id" asc

-- SyncRepository.assetFace.getUpserts
select
  "asset_face"."id",
  "assetId",
  "personId",
  "imageWidth",
  "imageHeight",
  "boundingBoxX1",
  "boundingBoxY1",
  "boundingBoxX2",
  "boundingBoxY2",
  "sourceType",
  "asset_face"."updateId"
from
  "asset_face" as "asset_face"
  left join "asset" on "asset"."id" = "asset_face"."assetId"
where
  "asset_face"."updateId" < $1
  and "asset_face"."updateId" > $2
  and "asset"."ownerId" = $3
  and "asset_face"."isVisible" = $4
order by
  "asset_face"."updateId" asc

-- SyncRepository.assetMetadata.getDeletes
select
  "asset_metadata_audit"."id",
  "assetId",
  "key"
from
  "asset_metadata_audit" as "asset_metadata_audit"
  left join "asset" on "asset"."id" = "asset_metadata_audit"."assetId"
where
  "asset_metadata_audit"."id" < $1
  and "asset_metadata_audit"."id" > $2
  and "asset"."ownerId" = $3
order by
  "asset_metadata_audit"."id" asc

-- SyncRepository.assetMetadata.getUpserts
select
  "assetId",
  "key",
  "value",
  "asset_metadata"."updateId"
from
  "asset_metadata" as "asset_metadata"
  inner join "asset" on "asset"."id" = "asset_metadata"."assetId"
where
  "asset_metadata"."updateId" < $1
  and "asset_metadata"."updateId" > $2
  and "asset"."ownerId" = $3
order by
  "asset_metadata"."updateId" asc

-- SyncRepository.authUser.getUpserts
select
  "id",
  "name",
  "email",
  "avatarColor",
  "deletedAt",
  "updateId",
  "profileImagePath",
  "profileChangedAt",
  "isAdmin",
  "pinCode",
  "oauthId",
  "storageLabel",
  "quotaSizeInBytes",
  "quotaUsageInBytes"
from
  "user" as "user"
where
  "user"."updateId" < $1
  and "user"."updateId" > $2
  and "id" = $3
order by
  "user"."updateId" asc

-- SyncRepository.memory.getDeletes
select
  "id",
  "memoryId"
from
  "memory_audit" as "memory_audit"
where
  "memory_audit"."id" < $1
  and "memory_audit"."id" > $2
  and "userId" = $3
order by
  "memory_audit"."id" asc

-- SyncRepository.memory.getUpserts
select
  "id",
  "createdAt",
  "updatedAt",
  "deletedAt",
  "ownerId",
  "type",
  "data",
  "isSaved",
  "memoryAt",
  "seenAt",
  "showAt",
  "hideAt",
  "updateId"
from
  "memory" as "memory"
where
  "memory"."updateId" < $1
  and "memory"."updateId" > $2
  and "ownerId" = $3
order by
  "memory"."updateId" asc

-- SyncRepository.memoryToAsset.getDeletes
select
  "id",
  "memoryId",
  "assetId"
from
  "memory_asset_audit" as "memory_asset_audit"
where
  "memory_asset_audit"."id" < $1
  and "memory_asset_audit"."id" > $2
  and "memoryId" in (
    select
      "id"
    from
      "memory"
    where
      "ownerId" = $3
  )
order by
  "memory_asset_audit"."id" asc

-- SyncRepository.memoryToAsset.getUpserts
select
  "memoriesId" as "memoryId",
  "assetId" as "assetId",
  "updateId"
from
  "memory_asset" as "memory_asset"
where
  "memory_asset"."updateId" < $1
  and "memory_asset"."updateId" > $2
  and "memoriesId" in (
    select
      "id"
    from
      "memory"
    where
      "ownerId" = $3
  )
order by
  "memory_asset"."updateId" asc

-- SyncRepository.partner.getCreatedAfter
select
  "sharedById",
  "createId"
from
  "partner"
where
  "sharedWithId" = $1
  and "createId" >= $2
  and "createId" < $3
order by
  "partner"."createId" asc

-- SyncRepository.partner.getDeletes
select
  "id",
  "sharedById",
  "sharedWithId"
from
  "partner_audit" as "partner_audit"
where
  "partner_audit"."id" < $1
  and "partner_audit"."id" > $2
  and (
    "sharedById" = $3
    or "sharedWithId" = $4
  )
order by
  "partner_audit"."id" asc

-- SyncRepository.partner.getUpserts
select
  "sharedById",
  "sharedWithId",
  "inTimeline",
  "updateId"
from
  "partner" as "partner"
where
  "partner"."updateId" < $1
  and "partner"."updateId" > $2
  and (
    "sharedById" = $3
    or "sharedWithId" = $4
  )
order by
  "partner"."updateId" asc

-- SyncRepository.partnerAsset.getBackfill
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalFileName",
  "asset"."thumbhash",
  "asset"."checksum",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."localDateTime",
  "asset"."type",
  "asset"."deletedAt",
  "asset"."isFavorite",
  "asset"."visibility",
  "asset"."duration",
  "asset"."livePhotoVideoId",
  "asset"."stackId",
  "asset"."libraryId",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited",
  "asset"."updateId"
from
  "asset" as "asset"
where
  "asset"."updateId" < $1
  and "asset"."updateId" <= $2
  and "asset"."updateId" >= $3
  and "ownerId" = $4
order by
  "asset"."updateId" asc

-- SyncRepository.partnerAsset.getDeletes
select
  "id",
  "assetId"
from
  "asset_audit" as "asset_audit"
where
  "asset_audit"."id" < $1
  and "asset_audit"."id" > $2
  and "ownerId" in (
    select
      "sharedById"
    from
      "partner"
    where
      "sharedWithId" = $3
  )
order by
  "asset_audit"."id" asc

-- SyncRepository.partnerAsset.getUpserts
select
  "asset"."id",
  "asset"."ownerId",
  "asset"."originalFileName",
  "asset"."thumbhash",
  "asset"."checksum",
  "asset"."fileCreatedAt",
  "asset"."fileModifiedAt",
  "asset"."localDateTime",
  "asset"."type",
  "asset"."deletedAt",
  "asset"."isFavorite",
  "asset"."visibility",
  "asset"."duration",
  "asset"."livePhotoVideoId",
  "asset"."stackId",
  "asset"."libraryId",
  "asset"."width",
  "asset"."height",
  "asset"."isEdited",
  "asset"."updateId"
from
  "asset" as "asset"
where
  "asset"."updateId" < $1
  and "asset"."updateId" > $2
  and "ownerId" in (
    select
      "sharedById"
    from
      "partner"
    where
      "sharedWithId" = $3
  )
order by
  "asset"."updateId" asc

-- SyncRepository.partnerAssetExif.getBackfill
select
  "asset_exif"."assetId",
  "asset_exif"."description",
  "asset_exif"."exifImageWidth",
  "asset_exif"."exifImageHeight",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."orientation",
  "asset_exif"."dateTimeOriginal",
  "asset_exif"."modifyDate",
  "asset_exif"."timeZone",
  "asset_exif"."latitude",
  "asset_exif"."longitude",
  "asset_exif"."projectionType",
  "asset_exif"."city",
  "asset_exif"."state",
  "asset_exif"."country",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  "asset_exif"."fNumber",
  "asset_exif"."focalLength",
  "asset_exif"."iso",
  "asset_exif"."exposureTime",
  "asset_exif"."profileDescription",
  "asset_exif"."rating",
  "asset_exif"."fps",
  "asset_exif"."updateId"
from
  "asset_exif" as "asset_exif"
  inner join "asset" on "asset"."id" = "asset_exif"."assetId"
where
  "asset_exif"."updateId" < $1
  and "asset_exif"."updateId" <= $2
  and "asset_exif"."updateId" >= $3
  and "asset"."ownerId" = $4
order by
  "asset_exif"."updateId" asc

-- SyncRepository.partnerAssetExif.getUpserts
select
  "asset_exif"."assetId",
  "asset_exif"."description",
  "asset_exif"."exifImageWidth",
  "asset_exif"."exifImageHeight",
  "asset_exif"."fileSizeInByte",
  "asset_exif"."orientation",
  "asset_exif"."dateTimeOriginal",
  "asset_exif"."modifyDate",
  "asset_exif"."timeZone",
  "asset_exif"."latitude",
  "asset_exif"."longitude",
  "asset_exif"."projectionType",
  "asset_exif"."city",
  "asset_exif"."state",
  "asset_exif"."country",
  "asset_exif"."make",
  "asset_exif"."model",
  "asset_exif"."lensModel",
  "asset_exif"."fNumber",
  "asset_exif"."focalLength",
  "asset_exif"."iso",
  "asset_exif"."exposureTime",
  "asset_exif"."profileDescription",
  "asset_exif"."rating",
  "asset_exif"."fps",
  "asset_exif"."updateId"
from
  "asset_exif" as "asset_exif"
where
  "asset_exif"."updateId" < $1
  and "asset_exif"."updateId" > $2
  and "assetId" in (
    select
      "id"
    from
      "asset"
    where
      "ownerId" in (
        select
          "sharedById"
        from
          "partner"
        where
          "sharedWithId" = $3
      )
  )
order by
  "asset_exif"."updateId" asc

-- SyncRepository.partnerStack.getDeletes
select
  "id",
  "stackId"
from
  "stack_audit" as "stack_audit"
where
  "stack_audit"."id" < $1
  and "stack_audit"."id" > $2
  and "userId" in (
    select
      "sharedById"
    from
      "partner"
    where
      "sharedWithId" = $3
  )
order by
  "stack_audit"."id" asc

-- SyncRepository.partnerStack.getBackfill
select
  "stack"."id",
  "stack"."createdAt",
  "stack"."updatedAt",
  "stack"."primaryAssetId",
  "stack"."ownerId",
  "updateId"
from
  "stack" as "stack"
where
  "stack"."updateId" < $1
  and "stack"."updateId" <= $2
  and "stack"."updateId" >= $3
  and "ownerId" = $4
order by
  "stack"."updateId" asc

-- SyncRepository.partnerStack.getUpserts
select
  "stack"."id",
  "stack"."createdAt",
  "stack"."updatedAt",
  "stack"."primaryAssetId",
  "stack"."ownerId",
  "updateId"
from
  "stack" as "stack"
where
  "stack"."updateId" < $1
  and "stack"."updateId" > $2
  and "ownerId" in (
    select
      "sharedById"
    from
      "partner"
    where
      "sharedWithId" = $3
  )
order by
  "stack"."updateId" asc

-- SyncRepository.person.getDeletes
select
  "id",
  "personId"
from
  "person_audit" as "person_audit"
where
  "person_audit"."id" < $1
  and "person_audit"."id" > $2
  and "ownerId" = $3
order by
  "person_audit"."id" asc

-- SyncRepository.person.getUpserts
select
  "id",
  "createdAt",
  "updatedAt",
  "ownerId",
  "name",
  "birthDate",
  "isHidden",
  "isFavorite",
  "color",
  "updateId",
  "faceAssetId"
from
  "person" as "person"
where
  "person"."updateId" < $1
  and "person"."updateId" > $2
  and "ownerId" = $3
order by
  "person"."updateId" asc

-- SyncRepository.stack.getDeletes
select
  "id",
  "stackId"
from
  "stack_audit" as "stack_audit"
where
  "stack_audit"."id" < $1
  and "stack_audit"."id" > $2
  and "userId" = $3
order by
  "stack_audit"."id" asc

-- SyncRepository.stack.getUpserts
select
  "stack"."id",
  "stack"."createdAt",
  "stack"."updatedAt",
  "stack"."primaryAssetId",
  "stack"."ownerId",
  "updateId"
from
  "stack" as "stack"
where
  "stack"."updateId" < $1
  and "stack"."updateId" > $2
  and "ownerId" = $3
order by
  "stack"."updateId" asc

-- SyncRepository.user.getDeletes
select
  "id",
  "userId"
from
  "user_audit" as "user_audit"
where
  "user_audit"."id" < $1
  and "user_audit"."id" > $2
order by
  "user_audit"."id" asc

-- SyncRepository.user.getUpserts
select
  "id",
  "name",
  "email",
  "avatarColor",
  "deletedAt",
  "updateId",
  "profileImagePath",
  "profileChangedAt"
from
  "user" as "user"
where
  "user"."updateId" < $1
  and "user"."updateId" > $2
order by
  "user"."updateId" asc

-- SyncRepository.userMetadata.getDeletes
select
  "id",
  "userId",
  "key"
from
  "user_metadata_audit" as "user_metadata_audit"
where
  "user_metadata_audit"."id" < $1
  and "user_metadata_audit"."id" > $2
  and "userId" = $3
order by
  "user_metadata_audit"."id" asc

-- SyncRepository.userMetadata.getUpserts
select
  "userId",
  "key",
  "value",
  "updateId"
from
  "user_metadata" as "user_metadata"
where
  "user_metadata"."updateId" < $1
  and "user_metadata"."updateId" > $2
  and "userId" = $3
order by
  "user_metadata"."updateId" asc
