diff schema/updates/1310/01.import-changed.sql @ 4748:47922c1a088d

Added a 'changed' column to the import.imports table. Changed is update each time the state changes (TODO: solve this with a trigger). The update script takes as approximation the time of the last log entry connected with the particular import.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 18 Oct 2019 15:34:34 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/updates/1310/01.import-changed.sql	Fri Oct 18 15:34:34 2019 +0200
@@ -0,0 +1,6 @@
+ALTER TABLE import.imports ADD COLUMN changed timestamp WITH time zone NOT NULL DEFAULT CURRENT_TIMESTAMP;
+
+UPDATE import.imports imp SET
+  changed = (SELECT coalesce(max(time), imp.changed)
+             FROM import.import_logs
+             WHERE import_id = imp.id);