mirror of
https://github.com/immich-app/immich.git
synced 2025-05-31 12:15:47 -04:00
handle different db name
This commit is contained in:
parent
db2493d003
commit
e851884f88
@ -116,7 +116,7 @@ export const DummyValue = {
|
|||||||
DATE: new Date(),
|
DATE: new Date(),
|
||||||
TIME_BUCKET: '2024-01-01T00:00:00.000Z',
|
TIME_BUCKET: '2024-01-01T00:00:00.000Z',
|
||||||
BOOLEAN: true,
|
BOOLEAN: true,
|
||||||
VECTOR: JSON.stringify(Array.from({ length: 512 }, () => 0)),
|
VECTOR: '[1,2,3]',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GENERATE_SQL_KEY = 'generate-sql-key';
|
export const GENERATE_SQL_KEY = 'generate-sql-key';
|
||||||
|
@ -222,21 +222,6 @@ where
|
|||||||
"person"."ownerId" = $3
|
"person"."ownerId" = $3
|
||||||
and "asset_faces"."deletedAt" is null
|
and "asset_faces"."deletedAt" is null
|
||||||
|
|
||||||
-- PersonRepository.refreshFaces
|
|
||||||
with
|
|
||||||
"added_embeddings" as (
|
|
||||||
insert into
|
|
||||||
"face_search" ("faceId", "embedding")
|
|
||||||
values
|
|
||||||
($1, $2)
|
|
||||||
)
|
|
||||||
select
|
|
||||||
from
|
|
||||||
(
|
|
||||||
select
|
|
||||||
1
|
|
||||||
) as "dummy"
|
|
||||||
|
|
||||||
-- PersonRepository.getFacesByIds
|
-- PersonRepository.getFacesByIds
|
||||||
select
|
select
|
||||||
"asset_faces".*,
|
"asset_faces".*,
|
||||||
|
@ -84,7 +84,7 @@ limit
|
|||||||
$7
|
$7
|
||||||
offset
|
offset
|
||||||
$8
|
$8
|
||||||
commit
|
rollback
|
||||||
|
|
||||||
-- SearchRepository.searchDuplicates
|
-- SearchRepository.searchDuplicates
|
||||||
begin
|
begin
|
||||||
@ -115,7 +115,7 @@ from
|
|||||||
"cte"
|
"cte"
|
||||||
where
|
where
|
||||||
"cte"."distance" <= $7
|
"cte"."distance" <= $7
|
||||||
commit
|
rollback
|
||||||
|
|
||||||
-- SearchRepository.searchFaces
|
-- SearchRepository.searchFaces
|
||||||
begin
|
begin
|
||||||
@ -144,7 +144,7 @@ from
|
|||||||
"cte"
|
"cte"
|
||||||
where
|
where
|
||||||
"cte"."distance" <= $4
|
"cte"."distance" <= $4
|
||||||
commit
|
rollback
|
||||||
|
|
||||||
-- SearchRepository.searchPlaces
|
-- SearchRepository.searchPlaces
|
||||||
select
|
select
|
||||||
|
@ -115,9 +115,10 @@ export class DatabaseRepository {
|
|||||||
async createExtension(extension: DatabaseExtension): Promise<void> {
|
async createExtension(extension: DatabaseExtension): Promise<void> {
|
||||||
await sql`CREATE EXTENSION IF NOT EXISTS ${sql.raw(extension)} CASCADE`.execute(this.db);
|
await sql`CREATE EXTENSION IF NOT EXISTS ${sql.raw(extension)} CASCADE`.execute(this.db);
|
||||||
if (extension === DatabaseExtension.VECTORCHORD) {
|
if (extension === DatabaseExtension.VECTORCHORD) {
|
||||||
await sql`ALTER DATABASE immich SET vchordrq.prewarm_dim = '512,640,768,1024,1152,1536'`.execute(this.db);
|
const db = await this.getDatabaseName();
|
||||||
|
await sql`ALTER DATABASE ${sql.table(db)} SET vchordrq.prewarm_dim = '512,640,768,1024,1152,1536'`.execute(this.db);
|
||||||
await sql`SET vchordrq.prewarm_dim = '512,640,768,1024,1152,1536'`.execute(this.db);
|
await sql`SET vchordrq.prewarm_dim = '512,640,768,1024,1152,1536'`.execute(this.db);
|
||||||
await sql`ALTER DATABASE immich SET vchordrq.probes = 1`.execute(this.db);
|
await sql`ALTER DATABASE ${sql.table(db)} SET vchordrq.probes = 1`.execute(this.db);
|
||||||
await sql`SET vchordrq.probes = 1`.execute(this.db);
|
await sql`SET vchordrq.probes = 1`.execute(this.db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,6 +271,11 @@ export class DatabaseRepository {
|
|||||||
await sql`SET search_path TO "$user", public, vectors`.execute(tx);
|
await sql`SET search_path TO "$user", public, vectors`.execute(tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getDatabaseName(): Promise<string> {
|
||||||
|
const { rows } = await sql<{ db: string }>`SELECT current_database() as db`.execute(this.db);
|
||||||
|
return rows[0].db;
|
||||||
|
}
|
||||||
|
|
||||||
async getDimensionSize(table: string, column = 'embedding'): Promise<number> {
|
async getDimensionSize(table: string, column = 'embedding'): Promise<number> {
|
||||||
const { rows } = await sql<{ dimsize: number }>`
|
const { rows } = await sql<{ dimsize: number }>`
|
||||||
SELECT atttypmod as dimsize
|
SELECT atttypmod as dimsize
|
||||||
|
@ -400,7 +400,6 @@ export class PersonRepository {
|
|||||||
return results.map(({ id }) => id);
|
return results.map(({ id }) => id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [[], [], [{ faceId: DummyValue.UUID, embedding: DummyValue.VECTOR }]] })
|
|
||||||
async refreshFaces(
|
async refreshFaces(
|
||||||
facesToAdd: (Insertable<AssetFaces> & { assetId: string })[],
|
facesToAdd: (Insertable<AssetFaces> & { assetId: string })[],
|
||||||
faceIdsToRemove: string[],
|
faceIdsToRemove: string[],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user