Skip to content

RHINENG-26117: Add recompute infrastructure for account_advisory#2195

Draft
rverdile wants to merge 4 commits into
RedHatInsights:masterfrom
rverdile:recompute-query
Draft

RHINENG-26117: Add recompute infrastructure for account_advisory#2195
rverdile wants to merge 4 commits into
RedHatInsights:masterfrom
rverdile:recompute-query

Conversation

@rverdile
Copy link
Copy Markdown
Contributor

@rverdile rverdile commented May 14, 2026

Summary

This adds recompute and trigger infrastructure for account_advisory. It's mostly modeled after the existing recompute and trigger for account_advisory_data. I also added a little bit of Go infrastructure so that I could add unit tests.

This is dependent on this PR: #2184

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Introduce workspace-scoped account_advisory aggregation with recompute and trigger support, plus supporting Go model and tests.

New Features:

  • Add partitioned account_advisory table to store per-account, per-workspace advisory aggregates and notification metadata.
  • Implement database functions to backfill and refresh account_advisory aggregates and to update them via system_inventory update triggers.
  • Expose account_advisory as a Go model with helper functions for test data management.

Enhancements:

  • Extend vmaas_sync metrics tests and database docs to cover the new account_advisory table.

Documentation:

  • Document the new account_advisory table and its role as the workspace-scoped equivalent of advisory_account_data.

Tests:

  • Add integration tests validating backfill, refresh, and trigger behavior for account_advisory aggregates.

rverdile added 2 commits May 14, 2026 15:38
adds a new table for account advisories by workspace, but does not
wire-up the table to anything
…dvisory

Add SQL functions that mirror advisory_account_data functions to
populate account_advisory table
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 14, 2026

Reviewer's Guide

Adds a new workspace-scoped account_advisory aggregate table with full schema, migrations, recompute/backfill functions, and system_inventory triggers, plus Go model/test helpers and integration tests to validate recompute and trigger behavior.

File-Level Changes

Change Details Files
Introduce account_advisory table as a workspace-scoped advisory aggregate with schema, partitioning, grants, and documentation.
  • Create account_advisory table partitioned by rh_account_id with primary key (rh_account_id, workspace_id, advisory_id) and foreign key to advisory_metadata
  • Configure account_advisory partitions with storage parameters and grant CRUD privileges to manager, evaluator, listener, and vmaas_sync roles
  • Document account_advisory purpose and structure in database.md
  • Ensure dev test data cleanup truncates account_advisory and metrics tests assert presence of the new table
database_admin/schema/create_schema.sql
database_admin/migrations/154_account_advisory.up.sql
database_admin/migrations/154_account_advisory.down.sql
docs/md/database.md
dev/test_data.sql
tasks/vmaas_sync/metrics_db_test.go
Add recompute/backfill functions and AFTER UPDATE trigger plumbing to keep account_advisory in sync with system_inventory and system_advisories.
  • Implement on_system_update_account_advisory() trigger function to adjust per-workspace advisory counts when system staleness or workspace changes, guarded by system_patch/last_evaluation existence
  • Register partition triggers system_inventory_on_update_account_advisory on system_inventory partitions to invoke the new trigger function after updates
  • Create refresh_account_advisory_caches_multi(), refresh_account_advisory_caches(), and backfill_account_advisory() to recompute aggregates from system_advisories/system_inventory/system_patch and remove orphaned rows
  • Add matching migration to create indices, trigger, and refresh/backfill functions, and a down migration to drop them and their triggers
database_admin/schema/create_schema.sql
database_admin/migrations/155_account_advisory_queries.up.sql
database_admin/migrations/155_account_advisory_queries.down.sql
Extend Go data model and test utilities to work with account_advisory and add end-to-end tests for recompute and triggers.
  • Add AccountAdvisory GORM model and slice type mapped to account_advisory table
  • Introduce database helper functions to create, verify, and delete account_advisory records for tests, including deletion by account
  • Update testing DB utilities to import uuid for workspace IDs
  • Add cache tests that validate backfill_account_advisory and refresh_account_advisory_caches correct corrupted counts and delete rows for fully-stale workspaces, and that the on_system_update_account_advisory trigger reacts to stale and workspace changes
base/models/models.go
base/database/testing.go
tasks/caches/refresh_account_advisory_caches_test.go
Advance schema migration baseline version to include new account_advisory migrations.
  • Update schema_migrations seed value from 153 to 155 in create_schema.sql so new migrations are considered applied in fresh environments
database_admin/schema/create_schema.sql

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 15, 2026

Codecov Report

❌ Patch coverage is 0% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.86%. Comparing base (836502e) to head (3a0955c).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
base/database/testing.go 0.00% 28 Missing ⚠️
base/models/models.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2195      +/-   ##
==========================================
- Coverage   59.06%   58.86%   -0.21%     
==========================================
  Files         136      136              
  Lines        8761     8791      +30     
==========================================
  Hits         5175     5175              
- Misses       3040     3070      +30     
  Partials      546      546              
Flag Coverage Δ
unittests 58.86% <0.00%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rverdile rverdile changed the title RHINENG-26116: Add recompute and trigger infrastructure for account_advisory RHINENG-26116: Add recompute infrastructure for account_advisory May 15, 2026
@rverdile rverdile changed the title RHINENG-26116: Add recompute infrastructure for account_advisory RHINENG-26117: Add recompute infrastructure for account_advisory May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants