From af275d24317e329898e66101ba47d3e37e03881c Mon Sep 17 00:00:00 2001 From: Daniel Dietzler Date: Thu, 26 Nov 2026 12:01:09 +0100 Subject: [PATCH] chore: postgres.js v4 --- native/Cargo.lock | 64 +++++++++---------- pnpm-lock.yaml | 35 ++++++++-- pnpm-workspace.yaml | 2 +- server/package.json | 4 +- server/src/queries/asset.job.repository.sql | 6 +- server/src/queries/library.repository.sql | 4 +- server/src/queries/memory.repository.sql | 32 +++++----- server/src/queries/sync.repository.sql | 46 ++++++------- .../src/repositories/asset-job.repository.ts | 4 +- server/src/repositories/library.repository.ts | 2 +- server/src/repositories/memory.repository.ts | 2 +- server/src/repositories/sync.repository.ts | 10 +-- 12 files changed, 118 insertions(+), 93 deletions(-) diff --git a/native/Cargo.lock b/native/Cargo.lock index 9d95b80a20aa..bf61900f65cf 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -569,16 +569,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "nasm-rs" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "706bf8a5e8c8ddb99128c3291d31bd21f4bcde17f0f4c20ec678d85c74faa149" -dependencies = [ - "jobserver", - "log", -] - [[package]] name = "napi" version = "3.8.3" @@ -636,6 +626,16 @@ dependencies = [ "libloading", ] +[[package]] +name = "nasm-rs" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "706bf8a5e8c8ddb99128c3291d31bd21f4bcde17f0f4c20ec678d85c74faa149" +dependencies = [ + "jobserver", + "log", +] + [[package]] name = "native_core" version = "0.1.0" @@ -653,16 +653,6 @@ dependencies = [ "native_core", ] -[[package]] -name = "num-bigint" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" -dependencies = [ - "num-integer", - "num-traits", -] - [[package]] name = "native_core_node" version = "0.1.0" @@ -679,6 +669,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "num-bigint" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-derive" version = "0.4.2" @@ -993,6 +993,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.16.4" @@ -1026,12 +1032,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "slab" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" - [[package]] name = "syn" version = "2.0.119" @@ -1138,18 +1138,18 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "unicode-segmentation" version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + [[package]] name = "walkdir" version = "2.5.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6319571bd3f9..ad40e47f984b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -584,8 +584,8 @@ importers: specifier: workspace:* version: link:../packages/plugin-sdk '@immich/sql-tools': - specifier: ^0.7.0 - version: 0.7.0 + specifier: ^0.8.0 + version: 0.8.0 '@immich/walkrs': specifier: 0.0.17 version: 0.0.17 @@ -723,7 +723,7 @@ importers: version: 0.29.9 kysely-postgres-js: specifier: ^5.0.0 - version: 5.1.0(kysely@0.29.9)(postgres@3.4.9) + version: 5.1.0(kysely@0.29.9)(postgres@4.1.1) lodash-es: specifier: ^4.17.21 version: 4.18.1 @@ -758,8 +758,8 @@ importers: specifier: ^8.11.3 version: 8.23.1 postgres: - specifier: 3.4.9 - version: 3.4.9 + specifier: ^4.0.0 + version: 4.1.1 react: specifier: ^19.0.0 version: 19.3.1 @@ -3210,6 +3210,10 @@ packages: resolution: {integrity: sha512-RWSHO5UEza6zUrF1vncsbkeTT59MuWlUz6Ys47Dkujb+FqjBOsXnzQb0v8d5g4iTtIfXZzQKTWgvfIMY3GbzrA==} hasBin: true + '@immich/sql-tools@0.8.0': + resolution: {integrity: sha512-u39/5G5sTCuq2GZn4aTMgPhJZKtvPEyaapYBGMTTFw0doI4LW1hzM2cBXFOl8hr2pBDIot055C6iLbA21+RZ2A==} + hasBin: true + '@immich/ui@0.90.0': resolution: {integrity: sha512-bQY5K1af/m8p66jTZyzGSfUvfzAQZd3+8z+9nMGPb5wojTZODU81s+TSg/zNE93DcXY2++DdRpdf2nrPH1Nbpw==} peerDependencies: @@ -11252,6 +11256,10 @@ packages: resolution: {integrity: sha512-GD3qdB0x1z9xgFI6cdRD6xu2Sp2WCOEoe3mtnyB5Ee0XrrL5Pe+e4CCnJrRMnL1zYtRDZmQQVbvOttLnKDLnaw==} engines: {node: '>=12'} + postgres@4.1.1: + resolution: {integrity: sha512-1kJDojqNZC+iTHHXh6eif0J98LUtyLAePe/qkW1GK35eh2JixlsAiIKq3FGI+xqI+SUGTNodzf7TScVeIIyUug==} + engines: {node: '>=18'} + potpack@2.1.0: resolution: {integrity: sha512-pcaShQc1Shq0y+E7GqJqvZj8DTthWV1KeHGdi0Z6IAin2Oi3JnLCOfwnCo84qc+HAp52wT9nK9H7FAJp5a44GQ==} @@ -16482,6 +16490,15 @@ snapshots: pg-connection-string: 2.14.1 postgres: 3.4.9 + '@immich/sql-tools@0.8.0': + dependencies: + commander: 15.1.0 + graph-data-structure: 4.5.0 + kysely: 0.29.9 + kysely-postgres-js: 5.1.0(kysely@0.29.9)(postgres@4.1.1) + pg-connection-string: 2.14.1 + postgres: 4.1.1 + '@immich/ui@0.90.0(@sveltejs/kit@2.70.3(@sveltejs/vite-plugin-svelte@7.3.1(svelte@5.58.0(@typescript-eslint/types@8.73.0))(vite@8.3.8(@types/node@26.6.6)(jiti@2.7.0)(yaml@2.9.1)))(@typescript/typescript6@6.0.2)(svelte@5.58.0(@typescript-eslint/types@8.73.0))(vite@8.3.8(@types/node@26.6.6)(jiti@2.7.0)(yaml@2.9.1)))(svelte@5.58.0(@typescript-eslint/types@8.73.0))': dependencies: '@internationalized/date': 3.12.2 @@ -23608,6 +23625,12 @@ snapshots: optionalDependencies: postgres: 3.4.9 + kysely-postgres-js@5.1.0(kysely@0.29.9)(postgres@4.1.1): + dependencies: + kysely: 0.29.9 + optionalDependencies: + postgres: 4.1.1 + kysely@0.29.9: {} latest-version@7.0.0: @@ -25703,6 +25726,8 @@ snapshots: postgres@3.4.9: {} + postgres@4.1.1: {} + potpack@2.1.0: {} powershell-utils@0.1.0: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 3042b1c89b9c..843d557683da 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -72,7 +72,7 @@ shamefullyHoist: false verifyDepsBeforeRun: install minimumReleaseAgeExclude: - '@immich/ui' - - '@immich/sql-tools@0.7.0' + - '@immich/sql-tools@0.8.0' - '@nestjs/cli@12.0.1' - '@futo-org/*' - '@immich/nestjs-standard-schema@0.1.0' diff --git a/server/package.json b/server/package.json index 3d7d8e672ca7..c8832ea1a332 100644 --- a/server/package.json +++ b/server/package.json @@ -44,7 +44,7 @@ "@immich/native-core": "workspace:*", "@immich/nestjs-standard-schema": "^0.1.0", "@immich/plugin-sdk": "workspace:*", - "@immich/sql-tools": "^0.7.0", + "@immich/sql-tools": "^0.8.0", "@immich/walkrs": "0.0.17", "@nestjs/bullmq": "^12.0.0", "@nestjs/common": "^12.0.0", @@ -102,7 +102,7 @@ "nodemailer": "^10.0.0", "openid-client": "^6.3.3", "pg": "^8.11.3", - "postgres": "3.4.9", + "postgres": "^4.0.0", "react": "^19.0.0", "react-dom": "^19.0.0", "react-email": "^6.0.0", diff --git a/server/src/queries/asset.job.repository.sql b/server/src/queries/asset.job.repository.sql index eb1e2db6f3db..55a619814624 100644 --- a/server/src/queries/asset.job.repository.sql +++ b/server/src/queries/asset.job.repository.sql @@ -679,8 +679,8 @@ from where "stack_asset"."stackId" = "stack"."id" and "stack_asset"."id" != "stack"."primaryAssetId" - and "stack_asset"."visibility" = $1 - and "stack_asset"."status" != $2 + and "stack_asset"."visibility" = 'timeline' + and "stack_asset"."status" != 'deleted' ) as agg ) as "assets" from @@ -689,7 +689,7 @@ from "stack"."id" = "asset"."stackId" ) as "stack_result" on true where - "asset"."id" = $3 + "asset"."id" = $1 -- AssetJobRepository.streamForVideoConversion select diff --git a/server/src/queries/library.repository.sql b/server/src/queries/library.repository.sql index 102a0e6db981..b969c0cdd2f4 100644 --- a/server/src/queries/library.repository.sql +++ b/server/src/queries/library.repository.sql @@ -45,14 +45,14 @@ select and "asset"."visibility" != $4 ) ) as "videos", - coalesce(sum("asset_exif"."fileSizeInByte"), $5) as "usage" + coalesce(sum("asset_exif"."fileSizeInByte"), 0) as "usage" from "library" inner join "asset" on "asset"."libraryId" = "library"."id" left join "asset_exif" on "asset_exif"."assetId" = "asset"."id" where "asset"."deletedAt" is null - and "library"."id" = $6 + and "library"."id" = $5 group by "library"."id" select diff --git a/server/src/queries/memory.repository.sql b/server/src/queries/memory.repository.sql index 7c4f177a49c8..05f221672057 100644 --- a/server/src/queries/memory.repository.sql +++ b/server/src/queries/memory.repository.sql @@ -44,14 +44,14 @@ select and "asset"."deletedAt" is null and not exists ( select - $1 as "one" + 1 as "one" from "asset_face" inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId" and "person"."ownerId" = "asset"."ownerId" where "asset_face"."assetId" = "asset"."id" - and "person"."isHidden" = $2 + and "person"."isHidden" = $1 ) order by "asset"."fileCreatedAt" asc @@ -62,7 +62,7 @@ from "memory" where "deletedAt" is null - and "ownerId" = $3 + and "ownerId" = $2 order by "showAt" desc nulls last, "memoryAt" desc @@ -85,14 +85,14 @@ select and "asset"."deletedAt" is null and not exists ( select - $1 as "one" + 1 as "one" from "asset_face" inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId" and "person"."ownerId" = "asset"."ownerId" where "asset_face"."assetId" = "asset"."id" - and "person"."isHidden" = $2 + and "person"."isHidden" = $1 ) order by "asset"."fileCreatedAt" asc @@ -104,14 +104,14 @@ from where ( "showAt" is null - or "showAt" <= $3 + or "showAt" <= $2 ) and ( "hideAt" is null - or "hideAt" >= $4 + or "hideAt" >= $3 ) and "deletedAt" is null - and "ownerId" = $5 + and "ownerId" = $4 order by "showAt" desc nulls last, "memoryAt" desc @@ -134,14 +134,14 @@ select and "asset"."deletedAt" is null and not exists ( select - $1 as "one" + 1 as "one" from "asset_face" inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId" and "person"."ownerId" = "asset"."ownerId" where "asset_face"."assetId" = "asset"."id" - and "person"."isHidden" = $2 + and "person"."isHidden" = $1 ) order by "asset"."fileCreatedAt" asc @@ -151,9 +151,9 @@ select from "memory" where - "showAt" > $3 + "showAt" > $2 and "deletedAt" is null - and "ownerId" = $4 + and "ownerId" = $3 order by "showAt" desc nulls last, "memoryAt" desc @@ -176,14 +176,14 @@ select and "asset"."deletedAt" is null and not exists ( select - $1 as "one" + 1 as "one" from "asset_face" inner join "person" on "person"."personGroupId" = "asset_face"."personGroupId" and "person"."ownerId" = "asset"."ownerId" where "asset_face"."assetId" = "asset"."id" - and "person"."isHidden" = $2 + and "person"."isHidden" = $1 ) order by "asset"."fileCreatedAt" asc @@ -195,10 +195,10 @@ from where ( "showAt" is null - or "showAt" <= $3 + or "showAt" <= $2 ) and "deletedAt" is null - and "ownerId" = $4 + and "ownerId" = $3 order by "showAt" desc nulls last, "memoryAt" desc diff --git a/server/src/queries/sync.repository.sql b/server/src/queries/sync.repository.sql index ce8a70d3fc73..792c74e9e98b 100644 --- a/server/src/queries/sync.repository.sql +++ b/server/src/queries/sync.repository.sql @@ -70,17 +70,17 @@ select "asset"."isEdited", case when "asset"."ownerId" = $1 then "asset"."isFavorite" - else $2 + else false end as "isFavorite", "album_asset"."updateId" from "album_asset" as "album_asset" inner join "asset" on "asset"."id" = "album_asset"."assetId" where - "album_asset"."updateId" < $3 - and "album_asset"."updateId" <= $4 - and "album_asset"."updateId" > $5 - and "album_asset"."albumId" = $6 + "album_asset"."updateId" < $2 + and "album_asset"."updateId" <= $3 + and "album_asset"."updateId" > $4 + and "album_asset"."albumId" = $5 order by "album_asset"."updateId" asc @@ -107,7 +107,7 @@ select "asset"."isEdited", case when "asset"."ownerId" = $1 then "asset"."isFavorite" - else $2 + else false end as "isFavorite", "asset"."updateId" from @@ -115,10 +115,10 @@ from inner join "album_asset" on "album_asset"."assetId" = "asset"."id" inner join "album_user" on "album_user"."albumId" = "album_asset"."albumId" where - "asset"."updateId" < $3 - and "asset"."updateId" > $4 - and "album_asset"."updateId" <= $5 - and "album_user"."userId" = $6 + "asset"."updateId" < $2 + and "asset"."updateId" > $3 + and "album_asset"."updateId" <= $4 + and "album_user"."userId" = $5 order by "asset"."updateId" asc @@ -146,16 +146,16 @@ select "asset"."isEdited", case when "asset"."ownerId" = $1 then "asset"."isFavorite" - else $2 + else false end as "isFavorite" from "album_asset" as "album_asset" inner join "asset" on "asset"."id" = "album_asset"."assetId" inner join "album_user" on "album_user"."albumId" = "album_asset"."albumId" where - "album_asset"."updateId" < $3 - and "album_asset"."updateId" > $4 - and "album_user"."userId" = $5 + "album_asset"."updateId" < $2 + and "album_asset"."updateId" > $3 + and "album_user"."userId" = $4 order by "album_asset"."updateId" asc @@ -871,15 +871,15 @@ select "asset"."width", "asset"."height", "asset"."isEdited", - $1 as "isFavorite", + false as "isFavorite", "asset"."updateId" from "asset" as "asset" where - "asset"."updateId" < $2 - and "asset"."updateId" <= $3 - and "asset"."updateId" > $4 - and "ownerId" = $5 + "asset"."updateId" < $1 + and "asset"."updateId" <= $2 + and "asset"."updateId" > $3 + and "ownerId" = $4 order by "asset"."updateId" asc @@ -924,20 +924,20 @@ select "asset"."width", "asset"."height", "asset"."isEdited", - $1 as "isFavorite", + false as "isFavorite", "asset"."updateId" from "asset" as "asset" where - "asset"."updateId" < $2 - and "asset"."updateId" > $3 + "asset"."updateId" < $1 + and "asset"."updateId" > $2 and "ownerId" in ( select "sharedById" from "partner" where - "sharedWithId" = $4 + "sharedWithId" = $3 ) order by "asset"."updateId" asc diff --git a/server/src/repositories/asset-job.repository.ts b/server/src/repositories/asset-job.repository.ts index b782dbff1f85..e7bc85687ab2 100644 --- a/server/src/repositories/asset-job.repository.ts +++ b/server/src/repositories/asset-job.repository.ts @@ -288,8 +288,8 @@ export class AssetJobRepository { .select(['stack_asset.id']) .whereRef('stack_asset.stackId', '=', 'stack.id') .whereRef('stack_asset.id', '!=', 'stack.primaryAssetId') - .where('stack_asset.visibility', '=', sql.val(AssetVisibility.Timeline)) - .where('stack_asset.status', '!=', sql.val(AssetStatus.Deleted)), + .where('stack_asset.visibility', '=', sql.lit(AssetVisibility.Timeline)) + .where('stack_asset.status', '!=', sql.lit(AssetStatus.Deleted)), ).as('assets'), ]) .as('stack_result'), diff --git a/server/src/repositories/library.repository.ts b/server/src/repositories/library.repository.ts index 41dd2a90f0be..53d10a527f54 100644 --- a/server/src/repositories/library.repository.ts +++ b/server/src/repositories/library.repository.ts @@ -84,7 +84,7 @@ export class LibraryRepository { ) .as('videos'), ) - .select((eb) => eb.fn.coalesce((eb) => eb.fn.sum('asset_exif.fileSizeInByte'), eb.val(0)).as('usage')) + .select((eb) => eb.fn.coalesce((eb) => eb.fn.sum('asset_exif.fileSizeInByte'), eb.lit(0)).as('usage')) .where('asset.deletedAt', 'is', null) .groupBy('library.id') .where('library.id', '=', id) diff --git a/server/src/repositories/memory.repository.ts b/server/src/repositories/memory.repository.ts index 2989d7430908..fef307820089 100644 --- a/server/src/repositories/memory.repository.ts +++ b/server/src/repositories/memory.repository.ts @@ -98,7 +98,7 @@ export class MemoryRepository implements IBulkAsset { .onRef('person.personGroupId', '=', 'asset_face.personGroupId') .onRef('person.ownerId', '=', 'asset.ownerId'), ) - .select((eb) => eb.val(1).as('one')) + .select((eb) => eb.lit(1).as('one')) .whereRef('asset_face.assetId', '=', 'asset.id') .where('person.isHidden', '=', true), ), diff --git a/server/src/repositories/sync.repository.ts b/server/src/repositories/sync.repository.ts index 9d43bfd9d468..693fecee09d5 100644 --- a/server/src/repositories/sync.repository.ts +++ b/server/src/repositories/sync.repository.ts @@ -215,7 +215,7 @@ class AlbumAssetSync extends BaseSync { .case() .when('asset.ownerId', '=', userId) .then(eb.ref('asset.isFavorite')) - .else(eb.val(false)) + .else(eb.lit(false)) .end() .as('isFavorite'), ) @@ -235,7 +235,7 @@ class AlbumAssetSync extends BaseSync { .case() .when('asset.ownerId', '=', userId) .then(eb.ref('asset.isFavorite')) - .else(eb.val(false)) + .else(eb.lit(false)) .end() .as('isFavorite'), ) @@ -258,7 +258,7 @@ class AlbumAssetSync extends BaseSync { .case() .when('asset.ownerId', '=', userId) .then(eb.ref('asset.isFavorite')) - .else(eb.val(false)) + .else(eb.lit(false)) .end() .as('isFavorite'), ) @@ -671,7 +671,7 @@ class PartnerAssetsSync extends BaseSync { getBackfill(options: SyncBackfillOptions, partnerId: string) { return this.backfillQuery('asset', options) .select(columns.syncPartnerAsset) - .select(sql.val(false).as('isFavorite')) + .select(sql.lit(false).as('isFavorite')) .select('asset.updateId') .where('ownerId', '=', partnerId) .stream(); @@ -691,7 +691,7 @@ class PartnerAssetsSync extends BaseSync { getUpserts(options: SyncQueryOptions) { return this.upsertQuery('asset', options) .select(columns.syncPartnerAsset) - .select(sql.val(false).as('isFavorite')) + .select(sql.lit(false).as('isFavorite')) .select('asset.updateId') .where('ownerId', 'in', (eb) => eb.selectFrom('partner').select(['sharedById']).where('sharedWithId', '=', options.userId),