Reset event serial ids after re-import.

When the database is recreated, the sequences
used in the events_timed and events_seq tables
will be at their initial values, which will
almost certainly conflict with existing data
when it is imported via COPY.

With this commit, we set the current value for
those sequences to something usable.

Fixes #33.
This commit is contained in:
D. Berge
2020-09-14 01:36:40 +02:00
parent 53077f0baf
commit b5b91d41c9
2 changed files with 18 additions and 0 deletions

View File

@@ -90,6 +90,22 @@ All values are returned as being of type "text" and need casting before use.
';
--
-- Name: reset_events_serials(); Type: FUNCTION; Schema: _SURVEY__TEMPLATE_; Owner: postgres
--
CREATE FUNCTION _SURVEY__TEMPLATE_.reset_events_serials() RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM setval('events_timed_id_seq', (SELECT max(id)+1 FROM events_timed));
PERFORM setval('events_seq_id_seq', (SELECT max(id)+1 FROM events_seq));
END;
$$;
ALTER FUNCTION _SURVEY__TEMPLATE_.reset_events_serials() OWNER TO postgres;
--
-- Name: to_binning_grid(public.geometry); Type: FUNCTION; Schema: _SURVEY__TEMPLATE_; Owner: postgres
--