Skip to content

Remove zones

Instead of having a Zone model between elements and images, we can link them directly by moving image_id and polygon to Elements. This can make a significant improvement in ListProcessElements or for #706 by removing a large join. The model does not hold any other attributes and is no longer useful now that only elements can have zones. This also removes the maximum size constraint on polygons, which has caused some issues (#635 (closed), #715 (closed)).

A local test with a preprod dump shows that this query to perform the data migration would take less than 15 minutes in preprod:

ALTER TABLE documents_element ADD COLUMN image_id UUID;
ALTER TABLE documents_element ADD COLUMN polygon GEOMETRY(LINESTRING);
UPDATE documents_element e
SET image_id = z.image_id, polygon = z.polygon
FROM images_zone z
WHERE e.zone_id = z.id

Moving should then only affect the backend, as we could edit the serializers to not affect the entire API.

Edited by Erwan Rouchet