From 4d5430f2493f470a7ac12050783fedd318e2a7b9 Mon Sep 17 00:00:00 2001 From: rverdile Date: Fri, 8 May 2026 14:46:17 -0400 Subject: [PATCH 1/5] 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 068cbbcc5..33cdbabaa 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -783,6 +783,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 386e7d17a..7987baaa2 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 c0c60f1ca43deaa9afd3c68d236affaf241ca339 Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 12 May 2026 11:50:20 -0400 Subject: [PATCH 2/5] 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 33cdbabaa..a83f2cbef 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -788,14 +788,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); @@ -808,8 +807,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 81054a16d3df5419c818b681a73199a9324edd0e Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 12 May 2026 11:57:59 -0400 Subject: [PATCH 3/5] update migration number --- ..._account_advisory.down.sql => 154_account_advisory.down.sql} | 0 ...{153_account_advisory.up.sql => 154_account_advisory.up.sql} | 0 database_admin/schema/create_schema.sql | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) 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 diff --git a/database_admin/schema/create_schema.sql b/database_admin/schema/create_schema.sql index a83f2cbef..a59320e4c 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 (153, false); +VALUES (154, false); -- --------------------------------------------------------------------------- -- Functions From 8273ed871779b19d0fdeab64c23cc90d924c2363 Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 12 May 2026 14:01:28 -0400 Subject: [PATCH 4/5] 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 92dce9ad0049fafa86e7898b26a19f085bd5d295 Mon Sep 17 00:00:00 2001 From: rverdile Date: Tue, 19 May 2026 10:05:55 -0400 Subject: [PATCH 5/5] 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 a59320e4c..3baba9dbb 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -795,6 +795,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);