From a4690a53649e5551eecfbcc455b3742aa98d731b Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Wed, 27 Nov 2024 15:56:25 +0200 Subject: [PATCH] filename migration --- backend/src/migration/1730123930898-AddFilenameColumn.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/src/migration/1730123930898-AddFilenameColumn.ts b/backend/src/migration/1730123930898-AddFilenameColumn.ts index fb565d211..cfa0c9a16 100644 --- a/backend/src/migration/1730123930898-AddFilenameColumn.ts +++ b/backend/src/migration/1730123930898-AddFilenameColumn.ts @@ -5,7 +5,11 @@ export class AddFilenameColumn1730123930898 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query(`ALTER TABLE "regular_file" ADD "filename" character varying`); + await queryRunner.query(`UPDATE "regular_file" SET "filename" = regexp_replace(s3key, '.+/', '')`); + await queryRunner.query(`ALTER TABLE "regular_file" ALTER COLUMN "filename" SET NOT NULL;`); await queryRunner.query(`ALTER TABLE "model_file" ADD "filename" character varying`); + await queryRunner.query(`UPDATE "model_file" SET "filename" = regexp_replace(s3key, '.+/', '')`); + await queryRunner.query(`ALTER TABLE "model_file" ALTER COLUMN "filename" SET NOT NULL;`); } public async down(queryRunner: QueryRunner): Promise {