From ccaaff000e42adc71149b56dfcd3d4a740d4b830 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Thu, 4 Feb 2016 11:37:04 -0500 Subject: [PATCH] database: add created_at field for layers and vulnerabilities --- database/pgsql/migrations/20151222113213_Initial.sql | 3 ++- database/pgsql/queries.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/database/pgsql/migrations/20151222113213_Initial.sql b/database/pgsql/migrations/20151222113213_Initial.sql index 77f0bd76..7bb024d4 100644 --- a/database/pgsql/migrations/20151222113213_Initial.sql +++ b/database/pgsql/migrations/20151222113213_Initial.sql @@ -30,7 +30,8 @@ CREATE TABLE IF NOT EXISTS Layer ( name VARCHAR(128) NOT NULL UNIQUE, engineversion SMALLINT NOT NULL, parent_id INT NULL REFERENCES Layer ON DELETE CASCADE, - namespace_id INT NULL REFERENCES Namespace); + namespace_id INT NULL REFERENCES Namespace, + created_at TIMESTAMP WITH TIME ZONE); CREATE INDEX ON Layer (parent_id); CREATE INDEX ON Layer (namespace_id); diff --git a/database/pgsql/queries.go b/database/pgsql/queries.go index 773cfeaf..beaaaeeb 100644 --- a/database/pgsql/queries.go +++ b/database/pgsql/queries.go @@ -115,8 +115,9 @@ func init() { AND v.deleted_at IS NULL` queries["i_layer"] = ` - INSERT INTO Layer(name, engineversion, parent_id, namespace_id) - VALUES($1, $2, $3, $4) RETURNING id` + INSERT INTO Layer(name, engineversion, parent_id, namespace_id, created_at) + VALUES($1, $2, $3, $4, CURRENT_TIMESTAMP) + RETURNING id` queries["u_layer"] = `UPDATE LAYER SET engineversion = $2, namespace_id = $3 WHERE id = $1` @@ -158,8 +159,8 @@ func init() { WHERE vfif.vulnerability_id = $1` queries["i_vulnerability"] = ` - INSERT INTO Vulnerability(namespace_id, name, description, link, severity, metadata) - VALUES($1, $2, $3, $4, $5, $6) + INSERT INTO Vulnerability(namespace_id, name, description, link, severity, metadata, created_at) + VALUES($1, $2, $3, $4, $5, $6, CURRENT_TIMESTAMP) RETURNING id` queries["i_vulnerability_fixedin_feature"] = `