Skip to content

Commit cc70afd

Browse files
committed
Update migration to drop all media that was duplicated
1 parent 91ebba0 commit cc70afd

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/components/file/media/detect-existing-media.migration.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FileVersion } from '../dto';
66
import { FileRepository } from '../file.repository';
77
import { MediaService } from './media.service';
88

9-
@Migration('2023-09-01T18:00:00')
9+
@Migration('2023-09-05T19:00:00')
1010
export class DetectExistingMediaMigration extends BaseMigration {
1111
constructor(
1212
private readonly mediaService: MediaService,
@@ -16,8 +16,9 @@ export class DetectExistingMediaMigration extends BaseMigration {
1616
}
1717

1818
async up() {
19+
await this.dropAllDuplicatedMedia();
20+
1921
const detect = async (f: FileVersion) => {
20-
this.logger.info('Detecting', f);
2122
try {
2223
const result = await this.mediaService.detectAndSave(f);
2324
this.logger.info('Detected and saved media', {
@@ -80,4 +81,14 @@ export class DetectExistingMediaMigration extends BaseMigration {
8081
// eslint-disable-next-line no-constant-condition
8182
} while (true);
8283
}
84+
85+
private async dropAllDuplicatedMedia() {
86+
await this.db.query().raw`
87+
match (fv:FileVersion)-->(media:Media)
88+
with fv, collect(media) as medias
89+
where size(medias) > 1
90+
unwind medias as media
91+
detach delete media
92+
`.executeAndLogStats();
93+
}
8394
}

0 commit comments

Comments
 (0)