diff --git a/etc/db/upgrades/upgrade11-v0.2.1-new-event-log-schema.sql b/etc/db/upgrades/upgrade12-v0.2.2-new-event-log-schema.sql similarity index 92% rename from etc/db/upgrades/upgrade11-v0.2.1-new-event-log-schema.sql rename to etc/db/upgrades/upgrade12-v0.2.2-new-event-log-schema.sql index 61a9be0..6acec68 100644 --- a/etc/db/upgrades/upgrade11-v0.2.1-new-event-log-schema.sql +++ b/etc/db/upgrades/upgrade12-v0.2.2-new-event-log-schema.sql @@ -1,6 +1,6 @@ -- Add new event log schema. -- --- New schema version: 0.2.1 +-- New schema version: 0.2.2 -- -- ATTENTION: -- @@ -156,6 +156,11 @@ BEGIN BEGIN IF (TG_OP = 'INSERT') THEN + -- Complete the tstamp if possible + IF NEW.sequence IS NOT NULL AND NEW.point IS NOT NULL AND NEW.tstamp IS NULL THEN + SELECT ts INTO NEW.tstamp FROM tstamp_from_sequence_shot(NEW.sequence, NEW.point); + END IF; + -- Any id that is provided will be ignored. The generated -- id will match uid. INSERT INTO event_log_full @@ -178,6 +183,13 @@ BEGIN RETURN NULL; END IF; + -- If the sequence / point has changed, and no new tstamp is provided, get one + IF NEW.sequence <> OLD.sequence OR NEW.point <> OLD.point + AND NEW.sequence IS NOT NULL AND NEW.point IS NOT NULL + AND NEW.tstamp IS NULL OR NEW.tstamp = OLD.tstamp THEN + SELECT ts INTO NEW.tstamp FROM tstamp_from_sequence_shot(NEW.sequence, NEW.point); + END IF; + UPDATE event_log_full SET validity = tstzrange(lower(validity), current_timestamp) WHERE validity @> current_timestamp AND id = OLD.id; @@ -258,9 +270,9 @@ CALL show_notice('Updating db_schema version'); -- This is technically still compatible with 0.2.0 as we are only adding -- some more tables and views but not yet dropping the old ones, which we -- will do separately so that these scripts do not get too big. -INSERT INTO public.info VALUES ('version', '{"db_schema": "0.2.1"}') +INSERT INTO public.info VALUES ('version', '{"db_schema": "0.2.2"}') ON CONFLICT (key) DO UPDATE - SET value = public.info.value || '{"db_schema": "0.2.1"}' WHERE public.info.key = 'version'; + SET value = public.info.value || '{"db_schema": "0.2.2"}' WHERE public.info.key = 'version'; CALL show_notice('All done. You may now run "COMMIT;" to persist the changes'); diff --git a/etc/db/upgrades/upgrade12-v0.3.0-migrate-events.sql b/etc/db/upgrades/upgrade13-v0.3.0-migrate-events.sql similarity index 100% rename from etc/db/upgrades/upgrade12-v0.3.0-migrate-events.sql rename to etc/db/upgrades/upgrade13-v0.3.0-migrate-events.sql diff --git a/etc/db/upgrades/upgrade13-v0.3.1-drop-old-event-tables.sql b/etc/db/upgrades/upgrade14-v0.3.1-drop-old-event-tables.sql similarity index 100% rename from etc/db/upgrades/upgrade13-v0.3.1-drop-old-event-tables.sql rename to etc/db/upgrades/upgrade14-v0.3.1-drop-old-event-tables.sql