From f771499aeab03f22c6bf3acc909d122b857bc013 Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Wed, 28 Feb 2024 16:04:14 +0000 Subject: [PATCH 1/2] lxd/db/cluster: Add columns to identities table for auditing. Signed-off-by: Mark Laing --- lxd/db/cluster/update.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go index f54ac63d9c17..2e15b3467df6 100644 --- a/lxd/db/cluster/update.go +++ b/lxd/db/cluster/update.go @@ -108,6 +108,20 @@ var updates = map[int]schema.Update{ 69: updateFromV68, 70: updateFromV69, 71: updateFromV70, + 72: updateFromV71, +} + +func updateFromV71(ctx context.Context, tx *sql.Tx) error { + _, err := tx.ExecContext(ctx, ` +ALTER TABLE identities ADD COLUMN first_seen_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z"; +ALTER TABLE identities ADD COLUMN last_seen_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z"; +ALTER TABLE identities ADD COLUMN updated_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z"; +`) + if err != nil { + return err + } + + return nil } func updateFromV70(ctx context.Context, tx *sql.Tx) error { From 277196adbfb9c6530370f0c7d36e28df0d67951e Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Wed, 28 Feb 2024 17:43:44 +0000 Subject: [PATCH 2/2] lxd/db/cluster: Runs make update-schema. Signed-off-by: Mark Laing --- lxd/db/cluster/schema.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lxd/db/cluster/schema.go b/lxd/db/cluster/schema.go index 6c17ad26530c..77d185960e4b 100644 --- a/lxd/db/cluster/schema.go +++ b/lxd/db/cluster/schema.go @@ -47,6 +47,9 @@ CREATE TABLE identities ( identifier TEXT NOT NULL, name TEXT NOT NULL, metadata TEXT NOT NULL, + first_seen_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z", + last_seen_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z", + updated_date DATETIME NOT NULL DEFAULT "0001-01-01T00:00:00Z", UNIQUE (auth_method, identifier), UNIQUE (type, identifier) ); @@ -665,5 +668,5 @@ CREATE TABLE "warnings" ( ); CREATE UNIQUE INDEX warnings_unique_node_id_project_id_entity_type_code_entity_id_type_code ON warnings(IFNULL(node_id, -1), IFNULL(project_id, -1), entity_type_code, entity_id, type_code); -INSERT INTO schema (version, updated_at) VALUES (71, strftime("%s")) +INSERT INTO schema (version, updated_at) VALUES (72, strftime("%s")) `