Skip to content

Commit

Permalink
Fix file management refactor DB migration
Browse files Browse the repository at this point in the history
[Re #1543]

We needed to take into account dash characters among the
allowed/expected file names when building the temporal image tables for
the "image" and "thumbnail" properties during the DB migration related
to already stored GCS images for the different resource types.
Otherwise, the file name string generation ends up with an empty value,
which violates the NOT NULL constraint in the File table's Name
column.

After further checking the code and both Prod and Test Env DBs, we are
confident that these are the only changes needed to fix the issue and
avoid any other surprises (since we know how the code is building the
image urls when uploading them to GCS).
  • Loading branch information
joseAyudarte91 committed Aug 22, 2023
1 parent 17b7ff2 commit 033de06
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ SELECT uuid_generate_v4(),
entity_id,
entity_type,
replace(image, 'https://storage.googleapis.com/akvo-unep-gpml/images', concat_ws('/', entity_type, 'images')) AS object_key,
substring(image from 'images\/([a-zA-Z0-9_]+)\.') AS name,
substring(image from 'images\/([a-zA-Z0-9_\-]+)\.') AS name,
concat_ws('/', 'image',lower(substring(image FROM '\.([^\.]*)$'))) AS type,
substring(image FROM '\.([^\.]*)$') AS extension,
(CASE WHEN entity_type = 'organisation' THEN 'private' ELSE 'public' END)::FILE_VISIBILITY AS visibility
Expand Down Expand Up @@ -127,7 +127,7 @@ SELECT uuid_generate_v4(),
entity_id,
entity_type,
replace(thumbnail, 'https://storage.googleapis.com/akvo-unep-gpml/images', concat_ws('/', entity_type, 'images')) AS object_key,
substring(thumbnail from 'images\/([a-zA-Z0-9_]+)\.') AS name,
substring(thumbnail from 'images\/([a-zA-Z0-9_\-]+)\.') AS name,
concat_ws('/', 'image',lower(substring(thumbnail FROM '\.([^\.]*)$'))) AS type,
substring(thumbnail FROM '\.([^\.]*)$') AS extension,
'public' AS visibility
Expand Down

0 comments on commit 033de06

Please sign in to comment.