Skip to content

Commit

Permalink
fix: split project images into data and mimetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-escience committed Dec 6, 2021
1 parent b5df222 commit 02c3c2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ public static void saveProjectImages(JsonArray allProjectsFromLegacyRSD) {
JsonArray allImagesToSave = new JsonArray();
allProjectsFromLegacyRSD.forEach(jsonElement -> {
JsonObject projectsFromLegacyRSD = jsonElement.getAsJsonObject();
JsonObject imageFromLegacyRSD = projectsFromLegacyRSD.getAsJsonObject("image");

String slug = projectsFromLegacyRSD.get("slug").getAsString();
JsonObject imageToSave = new JsonObject();
imageToSave.addProperty("project", slugToId.get(slug));
imageToSave.add("image", jsonElement.getAsJsonObject().get("image"));
imageToSave.add("data", imageFromLegacyRSD.get("data"));
imageToSave.add("mime_type", imageFromLegacyRSD.get("mimeType"));
allImagesToSave.add(imageToSave);
});
post(URI.create(PORSGREST_URI + "/image_for_project"), allImagesToSave.toString());
Expand Down
3 changes: 2 additions & 1 deletion database/005-create-project-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ CREATE TABLE project (

CREATE TABLE image_for_project(
project UUID references project (id) PRIMARY KEY,
image BYTEA
data BYTEA,
mime_type VARCHAR(100)
);

CREATE FUNCTION sanitise_insert_project() RETURNS TRIGGER LANGUAGE plpgsql as
Expand Down

0 comments on commit 02c3c2d

Please sign in to comment.