# HG changeset patch # User Sascha L. Teichmann # Date 1571405674 -7200 # Node ID 47922c1a088d94b5c2ba23cc6b28a35da2be9721 # Parent b1428b44e43fbaf347123aa76739c2ae92d15283 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. diff -r b1428b44e43f -r 47922c1a088d pkg/controllers/importqueue.go --- a/pkg/controllers/importqueue.go Fri Oct 18 15:17:31 2019 +0200 +++ b/pkg/controllers/importqueue.go Fri Oct 18 15:34:34 2019 +0200 @@ -45,6 +45,7 @@ imports.id AS id, state::varchar, enqueued, + changed, kind, username, signer, @@ -273,10 +274,12 @@ for rows.Next() { var it models.Import var enqueued time.Time + var changed time.Time if err = rows.Scan( &it.ID, &it.State, &enqueued, + &changed, &it.Kind, &it.User, &signer, @@ -290,6 +293,7 @@ it.Signer = signer.String } it.Enqueued = models.ImportTime{Time: enqueued.UTC()} + it.Changed = models.ImportTime{Time: changed.UTC()} imports = append(imports, &it) } @@ -446,6 +450,7 @@ reviewSQL = ` UPDATE import.imports SET state = $1::import_state, + changed = CURRENT_TIMESTAMP, signer = $2 WHERE id = $3` diff -r b1428b44e43f -r 47922c1a088d pkg/imports/queue.go --- a/pkg/imports/queue.go Fri Oct 18 15:17:31 2019 +0200 +++ b/pkg/imports/queue.go Fri Oct 18 15:34:34 2019 +0200 @@ -138,7 +138,9 @@ queueUser = "sys_admin" reEnqueueRunningSQL = ` -UPDATE import.imports SET state = 'queued'::import_state +UPDATE import.imports SET + state = 'queued'::import_state, + changed = CURRENT_TIMESTAMP WHERE state = 'running'::import_state` insertJobSQL = ` @@ -180,12 +182,15 @@ LIMIT 1` updateStateSQL = ` -UPDATE import.imports SET state = $1::import_state +UPDATE import.imports SET + state = $1::import_state, + changed = CURRENT_TIMESTAMP WHERE id = $2` updateStateSummarySQL = ` UPDATE import.imports SET state = $1::import_state, + changed = CURRENT_TIMESTAMP, summary = $2 WHERE id = $3` diff -r b1428b44e43f -r 47922c1a088d pkg/models/import.go --- a/pkg/models/import.go Fri Oct 18 15:17:31 2019 +0200 +++ b/pkg/models/import.go Fri Oct 18 15:34:34 2019 +0200 @@ -28,6 +28,7 @@ ID int64 `json:"id"` State string `json:"state"` Enqueued ImportTime `json:"enqueued"` + Changed ImportTime `json:"changed"` Kind string `json:"kind"` User string `json:"user"` Signer string `json:"signer,omitempty"` diff -r b1428b44e43f -r 47922c1a088d schema/gemma.sql --- a/schema/gemma.sql Fri Oct 18 15:17:31 2019 +0200 +++ b/schema/gemma.sql Fri Oct 18 15:34:34 2019 +0200 @@ -864,6 +864,7 @@ state import_state NOT NULL DEFAULT 'queued', kind varchar NOT NULL, enqueued timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, + changed timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, due timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, retry_wait interval CHECK(retry_wait IS NULL diff -r b1428b44e43f -r 47922c1a088d schema/updates/1310/01.import-changed.sql --- /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); diff -r b1428b44e43f -r 47922c1a088d schema/version.sql --- a/schema/version.sql Fri Oct 18 15:17:31 2019 +0200 +++ b/schema/version.sql Fri Oct 18 15:34:34 2019 +0200 @@ -1,1 +1,1 @@ -INSERT INTO gemma_schema_version(version) VALUES (1309); +INSERT INTO gemma_schema_version(version) VALUES (1310);