fix: storage template failure after re-upload and previous fail (#16611)

fix: storage template breaks when files are re-uploaded after a move failure
This commit is contained in:
Zack Pollard
2025-03-05 15:00:37 +00:00
committed by GitHub
parent 3f4bbab4eb
commit 9922c8de59
6 changed files with 81 additions and 3 deletions

View File

@@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { Insertable, Kysely, Updateable } from 'kysely';
import { Insertable, Kysely, sql, Updateable } from 'kysely';
import { InjectKysely } from 'nestjs-kysely';
import { DB, MoveHistory } from 'src/db';
import { DummyValue, GenerateSql } from 'src/decorators';
import { MoveEntity } from 'src/entities/move.entity';
import { PathType } from 'src/enum';
import { AssetPathType, PathType } from 'src/enum';
export type MoveCreate = Pick<MoveEntity, 'oldPath' | 'newPath' | 'entityId' | 'pathType'> & Partial<MoveEntity>;
@@ -47,4 +47,28 @@ export class MoveRepository {
.returningAll()
.executeTakeFirstOrThrow() as unknown as Promise<MoveEntity>;
}
@GenerateSql()
async cleanMoveHistory(): Promise<void> {
await this.db
.deleteFrom('move_history')
.where((eb) =>
eb(
'move_history.entityId',
'not in',
eb.selectFrom('assets').select('id').whereRef('assets.id', '=', 'move_history.entityId'),
),
)
.where('move_history.pathType', '=', sql.lit(AssetPathType.ORIGINAL))
.execute();
}
@GenerateSql()
async cleanMoveHistorySingle(assetId: string): Promise<void> {
await this.db
.deleteFrom('move_history')
.where('move_history.pathType', '=', sql.lit(AssetPathType.ORIGINAL))
.where('entityId', '=', assetId)
.execute();
}
}