Skip to content

Commit

Permalink
1543 fix file management refactor migration (#1555)
Browse files Browse the repository at this point in the history
* Fix file management refactor DB migration

[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).

* Fix formatting of misc. files
  • Loading branch information
joseAyudarte91 authored Aug 22, 2023
1 parent 17b7ff2 commit fd0d204
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 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
2 changes: 1 addition & 1 deletion backend/src/gpml/handler/programmatic/files_migrator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
[:entity-key
[:and
[:keyword]
(apply conj [:enum ] available-entities)]]
(apply conj [:enum] available-entities)]]
[:limit {:optional true} pos-int?]])

(defn- get-file-payload
Expand Down
2 changes: 1 addition & 1 deletion backend/test/gpml/auth_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
unapproved (new-stakeholder db 2 "[email protected]" "USER" "SUBMITTED")]

(are [expected auth-header]
(= expected (auth/get-user-info db auth-header))
(= expected (auth/get-user-info db auth-header))

;; Anonymous user
{:approved? false :user nil} {:authenticated? false}
Expand Down

0 comments on commit fd0d204

Please sign in to comment.