Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions base/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ func (TemplateBase) TableName() string {
return "template"
}

type TemplateAdvisory struct {
RhAccountID int `gorm:"primaryKey"`
TemplateID int64 `gorm:"primaryKey"`
AdvisoryID int64 `gorm:"primaryKey"`
Advisory AdvisoryMetadata
}
Comment thread
TenSt marked this conversation as resolved.

func (TemplateAdvisory) TableName() string {
return "template_advisory"
}

type TemplateAdvisorySlice []TemplateAdvisory

type SystemInventory struct {
ID int64 `gorm:"primaryKey"`
InventoryID uuid.UUID `gorm:"unique"`
Expand Down
1 change: 1 addition & 0 deletions database_admin/migrations/161_template_advisory.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS template_advisory;
23 changes: 23 additions & 0 deletions database_admin/migrations/161_template_advisory.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE IF NOT EXISTS template_advisory
(
rh_account_id INT NOT NULL,
template_id BIGINT NOT NULL,
advisory_id BIGINT NOT NULL,
PRIMARY KEY (rh_account_id, template_id, advisory_id),
CONSTRAINT template_advisory_template_id
FOREIGN KEY (rh_account_id, template_id)
REFERENCES template (rh_account_id, id) ON DELETE CASCADE,
CONSTRAINT template_advisory_advisory_id
FOREIGN KEY (advisory_id)
REFERENCES advisory_metadata (id) ON DELETE CASCADE
) PARTITION BY HASH (rh_account_id);

SELECT create_table_partitions('template_advisory', 16,
$$WITH (fillfactor = '70', autovacuum_vacuum_scale_factor = '0.05')$$);

CREATE INDEX ON template_advisory (rh_account_id, advisory_id);

SELECT grant_table_partitions('SELECT', 'template_advisory', 'manager');
SELECT grant_table_partitions('SELECT', 'template_advisory', 'evaluator');
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'template_advisory', 'listener');
SELECT grant_table_partitions('SELECT', 'template_advisory', 'vmaas_sync');
27 changes: 26 additions & 1 deletion database_admin/schema/create_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations


INSERT INTO schema_migrations
VALUES (160, false);
VALUES (161, false);

-- ---------------------------------------------------------------------------
-- Functions
Expand Down Expand Up @@ -787,6 +787,31 @@ VALUES (0, 'Installable'),
ON CONFLICT DO NOTHING;


-- template_advisory
CREATE TABLE IF NOT EXISTS template_advisory
(
rh_account_id INT NOT NULL,
template_id BIGINT NOT NULL,
advisory_id BIGINT NOT NULL,
PRIMARY KEY (rh_account_id, template_id, advisory_id),
CONSTRAINT template_advisory_template_id
FOREIGN KEY (rh_account_id, template_id)
REFERENCES template (rh_account_id, id) ON DELETE CASCADE,
CONSTRAINT template_advisory_advisory_id
FOREIGN KEY (advisory_id)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
REFERENCES advisory_metadata (id) ON DELETE CASCADE
) PARTITION BY HASH (rh_account_id);

SELECT create_table_partitions('template_advisory', 16,
$$WITH (fillfactor = '70', autovacuum_vacuum_scale_factor = '0.05')$$);

CREATE INDEX ON template_advisory (rh_account_id, advisory_id);

SELECT grant_table_partitions('SELECT', 'template_advisory', 'manager');
SELECT grant_table_partitions('SELECT', 'template_advisory', 'evaluator');
SELECT grant_table_partitions('SELECT, INSERT, UPDATE, DELETE', 'template_advisory', 'listener');
SELECT grant_table_partitions('SELECT', 'template_advisory', 'vmaas_sync');

-- system_advisories
CREATE TABLE IF NOT EXISTS system_advisories
(
Expand Down
1 change: 1 addition & 0 deletions tasks/cleaning/clean_unused_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func deleteUnusedAdvisories() {
subq := tx.Select("id").Table("advisory_metadata am").
Where("am.synced = ?", false).
Where("NOT EXISTS (SELECT 1 FROM system_advisories sa WHERE am.id = sa.advisory_id)").
Where("NOT EXISTS (SELECT 1 FROM template_advisory ta WHERE am.id = ta.advisory_id)").
Where("NOT EXISTS (SELECT 1 FROM package p WHERE am.id = p.advisory_id)").
Where("NOT EXISTS (SELECT 1 FROM advisory_account_data aad WHERE am.id = aad.advisory_id)").
Limit(tasks.DeleteUnusedDataLimit)
Expand Down
5 changes: 3 additions & 2 deletions tasks/vmaas_sync/metrics_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ func TestTableSizes(t *testing.T) {
for _, item := range tableSizes {
uniqueTables[item.Key] = true
}
assert.Equal(t, 263, len(tableSizes))
assert.Equal(t, 263, len(uniqueTables))
assert.Equal(t, 280, len(tableSizes))
assert.Equal(t, 280, 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"])
assert.True(t, uniqueTables["public.template_advisory"])
}

func TestDatabaseSize(t *testing.T) {
Expand Down
Loading