Skip to content

Commit

Permalink
Merge pull request #12982 from markylaing/identity-audit-columns
Browse files Browse the repository at this point in the history
DB: Add columns to identities table for auditing.
  • Loading branch information
tomponline authored Feb 29, 2024
2 parents 854006f + 277196a commit 57b904f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lxd/db/cluster/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -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"))
`
14 changes: 14 additions & 0 deletions lxd/db/cluster/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 57b904f

Please sign in to comment.