diff --git a/server/apps/immich/src/api-v1/asset/asset-repository.ts b/server/apps/immich/src/api-v1/asset/asset-repository.ts index fcbcb44748..2b169fd491 100644 --- a/server/apps/immich/src/api-v1/asset/asset-repository.ts +++ b/server/apps/immich/src/api-v1/asset/asset-repository.ts @@ -43,7 +43,7 @@ export class AssetRepository implements IAssetRepository { return await this.assetRepository .createQueryBuilder('asset') .where('asset.userId = :userId', { userId: userId }) - .andWhere(`date_trunc('month', "createdAt"::timestamptz) IN (:...buckets)`, { + .andWhere(`date_trunc('month', "createdAt") IN (:...buckets)`, { buckets: [...getAssetByTimeBucketDto.timeBucket], }) .andWhere('asset.resizePath is not NULL') @@ -58,19 +58,19 @@ export class AssetRepository implements IAssetRepository { result = await this.assetRepository .createQueryBuilder('asset') .select(`COUNT(asset.id)::int`, 'count') - .addSelect(`date_trunc('month', "createdAt"::timestamptz)`, 'timeBucket') + .addSelect(`date_trunc('month', "createdAt")`, 'timeBucket') .where('"userId" = :userId', { userId: userId }) - .groupBy(`date_trunc('month', "createdAt"::timestamptz)`) - .orderBy(`date_trunc('month', "createdAt"::timestamptz)`, 'DESC') + .groupBy(`date_trunc('month', "createdAt")`) + .orderBy(`date_trunc('month', "createdAt")`, 'DESC') .getRawMany(); } else if (timeBucket === TimeGroupEnum.Day) { result = await this.assetRepository .createQueryBuilder('asset') .select(`COUNT(asset.id)::int`, 'count') - .addSelect(`date_trunc('day', "createdAt"::timestamptz)`, 'timeBucket') + .addSelect(`date_trunc('day', "createdAt")`, 'timeBucket') .where('"userId" = :userId', { userId: userId }) - .groupBy(`date_trunc('day', "createdAt"::timestamptz)`) - .orderBy(`date_trunc('day', "createdAt"::timestamptz)`, 'DESC') + .groupBy(`date_trunc('day', "createdAt")`) + .orderBy(`date_trunc('day', "createdAt")`, 'DESC') .getRawMany(); } @@ -212,15 +212,15 @@ export class AssetRepository implements IAssetRepository { /** * Get asset by checksum on the database - * @param userId - * @param checksum - * + * @param userId + * @param checksum + * */ getAssetByChecksum(userId: string, checksum: Buffer): Promise { return this.assetRepository.findOneOrFail({ where: { userId, - checksum + checksum, }, relations: ['exifInfo'], }); diff --git a/server/libs/database/src/entities/asset.entity.ts b/server/libs/database/src/entities/asset.entity.ts index 1cddedc79d..97e218b256 100644 --- a/server/libs/database/src/entities/asset.entity.ts +++ b/server/libs/database/src/entities/asset.entity.ts @@ -32,10 +32,10 @@ export class AssetEntity { @Column({ type: 'varchar', nullable: true, default: '' }) encodedVideoPath!: string; - @Column() + @Column({ type: 'timestamptz' }) createdAt!: string; - @Column() + @Column({ type: 'timestamptz' }) modifiedAt!: string; @Column({ type: 'boolean', default: false }) diff --git a/server/libs/database/src/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts b/server/libs/database/src/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts new file mode 100644 index 0000000000..a0ce4dc8c6 --- /dev/null +++ b/server/libs/database/src/migrations/1662427365521-FixTimestampDataTypeInAssetTable.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class FixTimestampDataTypeInAssetTable1662427365521 implements MigrationInterface { + name = 'FixTimestampDataTypeInAssetTable1662427365521'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "exif" ALTER COLUMN "exifTextSearchableColumn" SET NOT NULL`); + await queryRunner.query( + `ALTER TABLE "assets" ALTER COLUMN "createdAt" TYPE timestamptz USING "createdAt"::timestamptz`, + ); + await queryRunner.query( + `ALTER TABLE "assets" ALTER COLUMN "modifiedAt" TYPE timestamptz USING "createdAt"::timestamptz`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "assets" ALTER COLUMN "createdAt" TYPE varchar USING "createdAt"::varchar`); + await queryRunner.query(`ALTER TABLE "assets" ALTER COLUMN "modifiedAt" TYPE varchar USING "createdAt"::varchar`); + await queryRunner.query(`ALTER TABLE "exif" ALTER COLUMN "exifTextSearchableColumn" DROP NOT NULL`); + } +}