diff --git a/server/src/db.d.ts b/server/src/db.d.ts index 454c5176de..a5cab5dab7 100644 --- a/server/src/db.d.ts +++ b/server/src/db.d.ts @@ -62,6 +62,7 @@ export interface Albums { export interface AlbumsAssetsAssets { albumsId: string; assetsId: string; + createdAt: Generated; } export interface AlbumsSharedUsersUsers { @@ -201,7 +202,6 @@ export interface GeodataPlaces { admin2Name: string | null; alternateNames: string | null; countryCode: string; - earthCoord: Generated; id: number; latitude: number; longitude: number; @@ -257,7 +257,7 @@ export interface NaturalearthCountries { admin: string; admin_a3: string; coordinates: string; - id: Generated; + id: number; type: string; } @@ -311,13 +311,6 @@ export interface SharedLinks { userId: string; } -export interface SmartInfo { - assetId: string; - objects: string[] | null; - smartInfoTextSearchableColumn: Generated; - tags: string[] | null; -} - export interface SmartSearch { assetId: string; embedding: string; @@ -399,6 +392,12 @@ export interface VectorsPgVectorIndexStat { tablerelid: number | null; } +export interface VersionHistory { + createdAt: Generated; + id: Generated; + version: string; +} + export interface DB { activity: Activity; albums: Albums; @@ -425,7 +424,6 @@ export interface DB { sessions: Sessions; shared_link__asset: SharedLinkAsset; shared_links: SharedLinks; - smart_info: SmartInfo; smart_search: SmartSearch; socket_io_attachments: SocketIoAttachments; system_config: SystemConfig; @@ -436,4 +434,5 @@ export interface DB { user_metadata: UserMetadata; users: Users; 'vectors.pg_vector_index_stat': VectorsPgVectorIndexStat; + version_history: VersionHistory; } diff --git a/server/src/interfaces/version-history.interface.ts b/server/src/interfaces/version-history.interface.ts index 6733706220..c38552c24f 100644 --- a/server/src/interfaces/version-history.interface.ts +++ b/server/src/interfaces/version-history.interface.ts @@ -5,5 +5,5 @@ export const IVersionHistoryRepository = 'IVersionHistoryRepository'; export interface IVersionHistoryRepository { create(version: Omit): Promise; getAll(): Promise; - getLatest(): Promise; + getLatest(): Promise; } diff --git a/server/src/queries/version.history.repository.sql b/server/src/queries/version.history.repository.sql new file mode 100644 index 0000000000..2e898cac31 --- /dev/null +++ b/server/src/queries/version.history.repository.sql @@ -0,0 +1,17 @@ +-- NOTE: This file is auto generated by ./sql-generator + +-- VersionHistoryRepository.getAll +select + * +from + "version_history" +order by + "createdAt" desc + +-- VersionHistoryRepository.getLatest +select + * +from + "version_history" +order by + "createdAt" desc diff --git a/server/src/repositories/version-history.repository.ts b/server/src/repositories/version-history.repository.ts index e32ceaf4e9..a501687350 100644 --- a/server/src/repositories/version-history.repository.ts +++ b/server/src/repositories/version-history.repository.ts @@ -1,23 +1,27 @@ import { Injectable } from '@nestjs/common'; -import { InjectRepository } from '@nestjs/typeorm'; +import { Kysely } from 'kysely'; +import { InjectKysely } from 'nestjs-kysely'; +import { DB } from 'src/db'; +import { DummyValue, GenerateSql } from 'src/decorators'; import { VersionHistoryEntity } from 'src/entities/version-history.entity'; import { IVersionHistoryRepository } from 'src/interfaces/version-history.interface'; -import { Repository } from 'typeorm'; @Injectable() export class VersionHistoryRepository implements IVersionHistoryRepository { - constructor(@InjectRepository(VersionHistoryEntity) private repository: Repository) {} + constructor(@InjectKysely() private db: Kysely) {} - async getAll(): Promise { - return this.repository.find({ order: { createdAt: 'DESC' } }); + @GenerateSql() + getAll(): Promise { + return this.db.selectFrom('version_history').selectAll().orderBy('createdAt', 'desc').execute(); } - async getLatest(): Promise { - const results = await this.repository.find({ order: { createdAt: 'DESC' }, take: 1 }); - return results[0] || null; + @GenerateSql() + getLatest(): Promise { + return this.db.selectFrom('version_history').selectAll().orderBy('createdAt', 'desc').executeTakeFirst(); } + @GenerateSql({ params: [DummyValue.STRING] }) create(version: Omit): Promise { - return this.repository.save(version); + return this.db.insertInto('version_history').values(version).returningAll().executeTakeFirstOrThrow(); } }