Skip to content

Commit

Permalink
Fix DAM file extension migration (#2308)
Browse files Browse the repository at this point in the history
Only execute SQL if sqlCaseClauses.length > 0. Otherwise the migration
fails for a database with no DamFiles
  • Loading branch information
thomasdax98 authored Jul 18, 2024
1 parent ec4685b commit d66bd70
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ export class Migration20240702123233 extends Migration {
})
.join(" OR ");

this.addSql(`
WITH mimetype_extension_map AS (
SELECT jsonb_build_object(${sqlMimetypeToSingleExtensionMap}) AS map
)
UPDATE "DamFile"
SET "name" = CONCAT("name", '.', mimetype_extension_map.map ->> "DamFile".mimetype)
FROM mimetype_extension_map
WHERE ${sqlCaseClauses};
`);
if (sqlCaseClauses.length > 0) {
this.addSql(`
WITH mimetype_extension_map AS (
SELECT jsonb_build_object(${sqlMimetypeToSingleExtensionMap}) AS map
)
UPDATE "DamFile"
SET "name" = CONCAT("name", '.', mimetype_extension_map.map ->> "DamFile".mimetype)
FROM mimetype_extension_map
WHERE ${sqlCaseClauses};
`);
}
}
}

0 comments on commit d66bd70

Please sign in to comment.