Skip to content

Commit d6585f4

Browse files
committed
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
1 parent 007083a commit d6585f4

6 files changed

Lines changed: 59 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS account_advisory;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE TABLE IF NOT EXISTS account_advisory
2+
(
3+
advisory_id BIGINT NOT NULL,
4+
rh_account_id INT NOT NULL,
5+
workspace_id UUID NOT NULL,
6+
systems_applicable INT NOT NULL DEFAULT 0,
7+
systems_installable INT NOT NULL DEFAULT 0,
8+
notified TIMESTAMP WITH TIME ZONE NULL,
9+
CONSTRAINT account_advisory_advisory_id
10+
FOREIGN KEY (advisory_id)
11+
REFERENCES advisory_metadata (id),
12+
CONSTRAINT account_advisory_rh_account_id
13+
FOREIGN KEY (rh_account_id)
14+
REFERENCES rh_account (id),
15+
PRIMARY KEY (rh_account_id, workspace_id, advisory_id)
16+
) PARTITION BY HASH (rh_account_id);
17+
18+
SELECT create_table_partitions('account_advisory', 32,
19+
$$WITH (fillfactor = '70', autovacuum_vacuum_scale_factor = '0.05')
20+
TABLESPACE pg_default$$);
21+
22+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'manager');
23+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'evaluator');
24+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'listener');
25+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'vmaas_sync');

database_admin/schema/create_schema.sql

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations
77

88

99
INSERT INTO schema_migrations
10-
VALUES (154, false);
10+
VALUES (155, false);
1111

1212
-- ---------------------------------------------------------------------------
1313
-- Functions
@@ -781,6 +781,33 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON advisory_account_data TO vmaas_sync;
781781
CREATE INDEX ON advisory_account_data (systems_applicable);
782782
CREATE INDEX ON advisory_account_data (systems_installable);
783783

784+
-- account_advisory
785+
CREATE TABLE IF NOT EXISTS account_advisory
786+
(
787+
advisory_id BIGINT NOT NULL,
788+
rh_account_id INT NOT NULL,
789+
workspace_id UUID NOT NULL,
790+
systems_applicable INT NOT NULL DEFAULT 0,
791+
systems_installable INT NOT NULL DEFAULT 0,
792+
notified TIMESTAMP WITH TIME ZONE NULL,
793+
CONSTRAINT account_advisory_advisory_id
794+
FOREIGN KEY (advisory_id)
795+
REFERENCES advisory_metadata (id),
796+
CONSTRAINT account_advisory_rh_account_id
797+
FOREIGN KEY (rh_account_id)
798+
REFERENCES rh_account (id),
799+
PRIMARY KEY (rh_account_id, workspace_id, advisory_id)
800+
) PARTITION BY HASH (rh_account_id);
801+
802+
SELECT create_table_partitions('account_advisory', 32,
803+
$$WITH (fillfactor = '70', autovacuum_vacuum_scale_factor = '0.05')
804+
TABLESPACE pg_default$$);
805+
806+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'manager');
807+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'evaluator');
808+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'listener');
809+
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'account_advisory', 'vmaas_sync');
810+
784811
-- repo
785812
CREATE TABLE IF NOT EXISTS repo
786813
(

dev/test_data.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DELETE FROM deleted_system;
77
DELETE FROM repo;
88
DELETE FROM timestamp_kv;
99
DELETE FROM advisory_account_data;
10+
DELETE FROM account_advisory;
1011
DELETE FROM package_account_data;
1112
DELETE FROM package;
1213
DELETE FROM package_name;

docs/md/database.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Main database tables description:
77
- **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.
88
- **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.
99
- **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.
10+
- **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).
1011
- **package_name** - names of the packages installed on systems
1112
- **package** - list of all packages versions, precisely all EVRAs (epoch-version-release-arch)
1213
- **system_package2** - list of packages installed on a system

tasks/vmaas_sync/metrics_db_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ func TestTableSizes(t *testing.T) {
1717
for _, item := range tableSizes {
1818
uniqueTables[item.Key] = true
1919
}
20-
assert.Equal(t, 230, len(tableSizes))
21-
assert.Equal(t, 230, len(uniqueTables))
20+
assert.Equal(t, 263, len(tableSizes))
21+
assert.Equal(t, 263, len(uniqueTables))
2222
assert.True(t, uniqueTables["public.system_inventory"]) // check whether table names were loaded
2323
assert.True(t, uniqueTables["public.system_patch"]) // check whether table names were loaded
2424
assert.True(t, uniqueTables["public.package"])
2525
assert.True(t, uniqueTables["public.repo"])
26+
assert.True(t, uniqueTables["public.account_advisory"])
2627
}
2728

2829
func TestDatabaseSize(t *testing.T) {

0 commit comments

Comments
 (0)