From 758f2ee434c525b70022ee4f59c79757106b6d34 Mon Sep 17 00:00:00 2001 From: rverdile Date: Fri, 8 May 2026 14:46:17 -0400 Subject: [PATCH 1/6] RHINENG-26116: create workspace-aware advisories aggregate table adds a new table for account advisories by workspace, but does not wire-up the table to anything --- .../migrations/153_account_advisory.down.sql | 1 + .../migrations/153_account_advisory.up.sql | 25 +++++++++++++++++ database_admin/schema/create_schema.sql | 27 +++++++++++++++++++ dev/test_data.sql | 1 + docs/md/database.md | 1 + 5 files changed, 55 insertions(+) create mode 100644 database_admin/migrations/153_account_advisory.down.sql create mode 100644 database_admin/migrations/153_account_advisory.up.sql diff --git a/database_admin/migrations/153_account_advisory.down.sql b/database_admin/migrations/153_account_advisory.down.sql new file mode 100644 index 000000000..d2de54398 --- /dev/null +++ b/database_admin/migrations/153_account_advisory.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS account_advisory; diff --git a/database_admin/migrations/153_account_advisory.up.sql b/database_admin/migrations/153_account_advisory.up.sql new file mode 100644 index 000000000..4be54c8fc --- /dev/null +++ b/database_admin/migrations/153_account_advisory.up.sql @@ -0,0 +1,25 @@ +CREATE TABLE IF NOT EXISTS account_advisory +( + advisory_id BIGINT NOT NULL, + rh_account_id INT NOT NULL, + workspace_id TEXT NOT NULL, + systems_applicable INT NOT NULL DEFAULT 0, + systems_installable INT NOT NULL DEFAULT 0, + notified TIMESTAMP WITH TIME ZONE NULL, + CONSTRAINT account_advisory_advisory_id + FOREIGN KEY (advisory_id) + REFERENCES advisory_metadata (id), + UNIQUE (advisory_id, rh_account_id, workspace_id), + PRIMARY KEY (rh_account_id, workspace_id, advisory_id) +) PARTITION BY HASH (rh_account_id); + +SELECT create_table_partitions('account_advisory', 32, + $$WITH (fillfactor = '70', autovacuum_vacuum_scale_factor = '0.05') + TABLESPACE pg_default$$); + +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'manager'); +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'evaluator'); +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'listener'); +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'vmaas_sync'); + +CREATE INDEX ON account_advisory (rh_account_id, workspace_id); diff --git a/database_admin/schema/create_schema.sql b/database_admin/schema/create_schema.sql index 9486abf78..72d500c12 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -781,6 +781,33 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON advisory_account_data TO vmaas_sync; CREATE INDEX ON advisory_account_data (systems_applicable); CREATE INDEX ON advisory_account_data (systems_installable); +-- account_advisory +CREATE TABLE IF NOT EXISTS account_advisory +( + advisory_id BIGINT NOT NULL, + rh_account_id INT NOT NULL, + workspace_id TEXT NOT NULL, + systems_applicable INT NOT NULL DEFAULT 0, + systems_installable INT NOT NULL DEFAULT 0, + notified TIMESTAMP WITH TIME ZONE NULL, + CONSTRAINT account_advisory_advisory_id + FOREIGN KEY (advisory_id) + REFERENCES advisory_metadata (id), + UNIQUE (advisory_id, rh_account_id, workspace_id), + PRIMARY KEY (rh_account_id, workspace_id, advisory_id) +) PARTITION BY HASH (rh_account_id); + +SELECT create_table_partitions('account_advisory', 32, + $$WITH (fillfactor = '70', autovacuum_vacuum_scale_factor = '0.05') + TABLESPACE pg_default$$); + +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'manager'); +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'evaluator'); +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'listener'); +SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'vmaas_sync'); + +CREATE INDEX ON account_advisory (rh_account_id, workspace_id); + -- repo CREATE TABLE IF NOT EXISTS repo ( diff --git a/dev/test_data.sql b/dev/test_data.sql index c4fb5f544..8c5062716 100644 --- a/dev/test_data.sql +++ b/dev/test_data.sql @@ -7,6 +7,7 @@ DELETE FROM deleted_system; DELETE FROM repo; DELETE FROM timestamp_kv; DELETE FROM advisory_account_data; +DELETE FROM account_advisory; DELETE FROM package_account_data; DELETE FROM package; DELETE FROM package_name; diff --git a/docs/md/database.md b/docs/md/database.md index 25e3d9e4c..fa191a700 100644 --- a/docs/md/database.md +++ b/docs/md/database.md @@ -7,6 +7,7 @@ Main database tables description: - **advisory_metadata** - stores info about advisories (`description`, `summary`, `solution` etc.). It's synced and stored on trigger by `vmaas_sync` component. It allows to display detail information about the advisory. - **system_advisories** - stores info about advisories evaluated for particular systems (system - advisory M-N mapping table). `system_id` references **system_inventory.id**. Contains info when system advisory was firstly reported and patched (if so). Records are created and updated by `evaluator` component. It allows to display list of advisories related to a system. - **advisory_account_data** - stores info about all advisories detected within at least one system that belongs to a given account. So it provides overall statistics about system advisories displayed by the application. +- **account_advisory** - workspace-scoped version of `advisory_account_data`. Stores per-advisory aggregate counts (`systems_applicable`, `systems_installable`) and notification state for each workspace within an account. Keyed by `(rh_account_id, workspace_id, advisory_id)`, partitioned by `rh_account_id` (32 partitions). - **package_name** - names of the packages installed on systems - **package** - list of all packages versions, precisely all EVRAs (epoch-version-release-arch) - **system_package2** - list of packages installed on a system From 157e523116790abe5c824987acc0daabfd3af2fd Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 12 May 2026 11:50:20 -0400 Subject: [PATCH 2/6] review --- database_admin/migrations/153_account_advisory.up.sql | 5 +---- database_admin/schema/create_schema.sql | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/database_admin/migrations/153_account_advisory.up.sql b/database_admin/migrations/153_account_advisory.up.sql index 4be54c8fc..464e22792 100644 --- a/database_admin/migrations/153_account_advisory.up.sql +++ b/database_admin/migrations/153_account_advisory.up.sql @@ -2,14 +2,13 @@ CREATE TABLE IF NOT EXISTS account_advisory ( advisory_id BIGINT NOT NULL, rh_account_id INT NOT NULL, - workspace_id TEXT NOT NULL, + workspace_id UUID NOT NULL, systems_applicable INT NOT NULL DEFAULT 0, systems_installable INT NOT NULL DEFAULT 0, notified TIMESTAMP WITH TIME ZONE NULL, CONSTRAINT account_advisory_advisory_id FOREIGN KEY (advisory_id) REFERENCES advisory_metadata (id), - UNIQUE (advisory_id, rh_account_id, workspace_id), PRIMARY KEY (rh_account_id, workspace_id, advisory_id) ) PARTITION BY HASH (rh_account_id); @@ -21,5 +20,3 @@ SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisor SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'evaluator'); SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'listener'); SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'vmaas_sync'); - -CREATE INDEX ON account_advisory (rh_account_id, workspace_id); diff --git a/database_admin/schema/create_schema.sql b/database_admin/schema/create_schema.sql index 72d500c12..01da1566c 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -786,14 +786,13 @@ CREATE TABLE IF NOT EXISTS account_advisory ( advisory_id BIGINT NOT NULL, rh_account_id INT NOT NULL, - workspace_id TEXT NOT NULL, + workspace_id UUID NOT NULL, systems_applicable INT NOT NULL DEFAULT 0, systems_installable INT NOT NULL DEFAULT 0, notified TIMESTAMP WITH TIME ZONE NULL, CONSTRAINT account_advisory_advisory_id FOREIGN KEY (advisory_id) REFERENCES advisory_metadata (id), - UNIQUE (advisory_id, rh_account_id, workspace_id), PRIMARY KEY (rh_account_id, workspace_id, advisory_id) ) PARTITION BY HASH (rh_account_id); @@ -806,8 +805,6 @@ SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisor SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'listener'); SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'vmaas_sync'); -CREATE INDEX ON account_advisory (rh_account_id, workspace_id); - -- repo CREATE TABLE IF NOT EXISTS repo ( From 74952d84854881090752fdedb0843f3fe47dd507 Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 12 May 2026 11:57:59 -0400 Subject: [PATCH 3/6] update migration number --- ...53_account_advisory.down.sql => 154_account_advisory.down.sql} | 0 .../{153_account_advisory.up.sql => 154_account_advisory.up.sql} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename database_admin/migrations/{153_account_advisory.down.sql => 154_account_advisory.down.sql} (100%) rename database_admin/migrations/{153_account_advisory.up.sql => 154_account_advisory.up.sql} (100%) diff --git a/database_admin/migrations/153_account_advisory.down.sql b/database_admin/migrations/154_account_advisory.down.sql similarity index 100% rename from database_admin/migrations/153_account_advisory.down.sql rename to database_admin/migrations/154_account_advisory.down.sql diff --git a/database_admin/migrations/153_account_advisory.up.sql b/database_admin/migrations/154_account_advisory.up.sql similarity index 100% rename from database_admin/migrations/153_account_advisory.up.sql rename to database_admin/migrations/154_account_advisory.up.sql From be8526ad8a5daa15175f473b7126bebdd7b863d4 Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 12 May 2026 14:01:28 -0400 Subject: [PATCH 4/6] update test --- tasks/vmaas_sync/metrics_db_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tasks/vmaas_sync/metrics_db_test.go b/tasks/vmaas_sync/metrics_db_test.go index f1437f974..2566436a0 100644 --- a/tasks/vmaas_sync/metrics_db_test.go +++ b/tasks/vmaas_sync/metrics_db_test.go @@ -17,12 +17,13 @@ func TestTableSizes(t *testing.T) { for _, item := range tableSizes { uniqueTables[item.Key] = true } - assert.Equal(t, 230, len(tableSizes)) - assert.Equal(t, 230, len(uniqueTables)) + assert.Equal(t, 263, len(tableSizes)) + assert.Equal(t, 263, len(uniqueTables)) assert.True(t, uniqueTables["public.system_inventory"]) // check whether table names were loaded assert.True(t, uniqueTables["public.system_patch"]) // check whether table names were loaded assert.True(t, uniqueTables["public.package"]) assert.True(t, uniqueTables["public.repo"]) + assert.True(t, uniqueTables["public.account_advisory"]) } func TestDatabaseSize(t *testing.T) { From 8a515dd7a2701f77e038fc6dce94a4c77c02cba0 Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 19 May 2026 10:05:55 -0400 Subject: [PATCH 5/6] add rh_account_id FK --- database_admin/migrations/154_account_advisory.up.sql | 3 +++ database_admin/schema/create_schema.sql | 3 +++ 2 files changed, 6 insertions(+) diff --git a/database_admin/migrations/154_account_advisory.up.sql b/database_admin/migrations/154_account_advisory.up.sql index 464e22792..6ebb081dd 100644 --- a/database_admin/migrations/154_account_advisory.up.sql +++ b/database_admin/migrations/154_account_advisory.up.sql @@ -9,6 +9,9 @@ CREATE TABLE IF NOT EXISTS account_advisory CONSTRAINT account_advisory_advisory_id FOREIGN KEY (advisory_id) REFERENCES advisory_metadata (id), + CONSTRAINT account_advisory_rh_account_id + FOREIGN KEY (rh_account_id) + REFERENCES rh_account (id), PRIMARY KEY (rh_account_id, workspace_id, advisory_id) ) PARTITION BY HASH (rh_account_id); diff --git a/database_admin/schema/create_schema.sql b/database_admin/schema/create_schema.sql index 01da1566c..e3d7d7334 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -793,6 +793,9 @@ CREATE TABLE IF NOT EXISTS account_advisory CONSTRAINT account_advisory_advisory_id FOREIGN KEY (advisory_id) REFERENCES advisory_metadata (id), + CONSTRAINT account_advisory_rh_account_id + FOREIGN KEY (rh_account_id) + REFERENCES rh_account (id), PRIMARY KEY (rh_account_id, workspace_id, advisory_id) ) PARTITION BY HASH (rh_account_id); From 6e646e712c1b179479165b187848a9a2e5a67ed1 Mon Sep 17 00:00:00 2001 From: rverdile Date: Thu, 21 May 2026 12:51:39 -0400 Subject: [PATCH 6/6] increase migration number --- ..._account_advisory.down.sql => 155_account_advisory.down.sql} | 0 ...{154_account_advisory.up.sql => 155_account_advisory.up.sql} | 0 database_admin/schema/create_schema.sql | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename database_admin/migrations/{154_account_advisory.down.sql => 155_account_advisory.down.sql} (100%) rename database_admin/migrations/{154_account_advisory.up.sql => 155_account_advisory.up.sql} (100%) diff --git a/database_admin/migrations/154_account_advisory.down.sql b/database_admin/migrations/155_account_advisory.down.sql similarity index 100% rename from database_admin/migrations/154_account_advisory.down.sql rename to database_admin/migrations/155_account_advisory.down.sql diff --git a/database_admin/migrations/154_account_advisory.up.sql b/database_admin/migrations/155_account_advisory.up.sql similarity index 100% rename from database_admin/migrations/154_account_advisory.up.sql rename to database_admin/migrations/155_account_advisory.up.sql diff --git a/database_admin/schema/create_schema.sql b/database_admin/schema/create_schema.sql index e3d7d7334..997423f5a 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations INSERT INTO schema_migrations -VALUES (154, false); +VALUES (155, false); -- --------------------------------------------------------------------------- -- Functions