   SELECT ST_Collect(DISTINCT g.geom)::geography
   FROM
   (
-    SELECT geom::geometry FROM changes WHERE changeset_id = $1
+    SELECT current_geom::geometry AS geom FROM changes WHERE changeset_id = $1
     UNION
-    SELECT new_geom::geometry FROM changes WHERE changeset_id = $1
+    SELECT new_geom::geometry AS geom FROM changes WHERE changeset_id = $1
   ) g);
 
 UPDATE changesets SET geom = changeset_geom WHERE id = $1;

-- Create a table for changes.
CREATE TABLE changes (
  id bigserial PRIMARY KEY,
  user_id bigint NOT NULL,
  version int NOT NULL,
  changeset_id bigint NOT NULL REFERENCES changesets,
  tstamp timestamp without time zone NOT NULL,
  action action NOT NULL,
  change_type change_type NOT NULL,
  el_type element_type NOT NULL,
  el_id bigint NOT NULL,
  tags hstore, -- If action is CREATE or DELETE, contains new/deleted element tags;
               -- If action is MODIFY, contains tags of element existing in the database (if it exists - otherwise NULL).
  new_tags hstore, -- If action is MODIFY, contains new tags of the element; otherwise NULL.
  geom geography, -- If action is CREATE or DELETE, contains new/deleted element geometry;
                  -- If action is MODIFY, contains geometry of element existing in the database (if it exists - otherwise NULL).
  new_geom geography -- If action is MODIFY, contains new geometry of the element; otherwise NULL.
);

CREATE INDEX idx_changes_changeset_id ON changes USING btree (changeset_id);


DROP TYPE IF EXISTS action;
CREATE TYPE action AS ENUM ('CREATE', 'MODIFY', 'DELETE');

-- Create a table for changesets.
CREATE TABLE changesets (
