Skip to content

feat(database): prepare tables for storing affected package information - #2491

Merged
jdobes merged 1 commit into
RedHatInsights:masterfrom
jdobes:package_tables
Sep 7, 2026
Merged

jdobes merged 1 commit into
RedHatInsights:masterfrom
jdobes:package_tables

Conversation

@jdobes

@jdobes jdobes commented Sep 4, 2026

Copy link
Copy Markdown
Member
  • enum of all current package architectures
  • evr table for unique epoch+version+release tuples, same design as in vmaas
  • new partitioned table for system_vulnerabilities details
  • extension of system_vulnerable_package where the schema already works well with the new feature

RHINENG-28511

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

Prepare the database schema to record affected package versions and architectures for system vulnerabilities.

New Features:

  • Add a canonical package architecture enum and a deduplicated epoch/version/release table for package metadata.
  • Add partitioned storage for affected package details associated with system vulnerabilities, including affected and fixed package versions and architectures.

Enhancements:

  • Extend system-vulnerable package records with affected version and architecture references while preserving referential integrity across existing partitions.

Tests:

  • Update development data cleanup and database metrics expectations for the new schema objects and partitions.

@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

The database schema is advanced to version 171 with architecture and deduplicated EVR types, a 256-way hash-partitioned vulnerability package detail model, and affected package metadata on existing vulnerable-package records; the baseline schema, upgrade scripts, and table-count test are updated together.

Entity relationship diagram for affected package vulnerability data

erDiagram
    PACKAGE_NAME ||--o{ SYSTEM_VULNERABILITIES_PKG_DETAIL : identifies
    EVR ||--o{ SYSTEM_VULNERABILITIES_PKG_DETAIL : affected_version
    EVR ||--o{ SYSTEM_VULNERABILITIES_PKG_DETAIL : fixed_version
    SYSTEM_VULNERABILITIES_ACTIVE ||--o{ SYSTEM_VULNERABILITIES_PKG_DETAIL : contains

    PACKAGE_NAME {
        BIGINT id PK
    }
    EVR {
        INTEGER id PK
        INTEGER epoch
        TEXT version
        TEXT release
    }
    SYSTEM_VULNERABILITIES_PKG_DETAIL {
        INT rh_account_id
        BIGINT system_vulnerability_id FK
        BIGINT package_name_id FK
        INTEGER affected_evr_id FK
        arch affected_arch
        INTEGER fixed_evr_id FK
        arch fixed_arch
    }
    SYSTEM_VULNERABILITIES_ACTIVE {
        BIGINT id PK
    }
Loading

File-Level Changes

Change Details Files
Add shared package architecture and EVR reference data structures.
  • Define the supported package architectures as a PostgreSQL enum.
  • Create a deduplicated epoch/version/release table with surrogate IDs and uniqueness enforcement.
  • Include the enum and EVR table in the full schema and add upgrade scripts.
database/schema/upgrade_scripts/168-add-arch-enum.sql
database/schema/upgrade_scripts/169-add-evr-table.sql
database/schema/ve_db_postgresql.sql
Introduce partitioned storage for vulnerability package impact details.
  • Create a hash-partitioned detail table keyed by account and referencing package names and affected/fixed EVRs.
  • Provision 256 partitions with per-partition primary keys and cascading foreign keys to account-specific active vulnerability tables.
  • Mirror the partitioned table and provisioning logic in the full schema and migration script.
database/schema/upgrade_scripts/170-add-system-vulnerabilities-pkg-detail.sql
database/schema/ve_db_postgresql.sql
Extend installed vulnerable package records with affected package version metadata.
  • Add nullable affected EVR and architecture columns.
  • Add a foreign key from affected EVR IDs to the shared EVR table.
  • Update the upgrade migration and baseline schema consistently.
database/schema/upgrade_scripts/171-add-system-vulnerable-package-evr.sql
database/schema/ve_db_postgresql.sql
Advance the database schema version and adjust database metrics expectations for new partitions.
  • Set the schema version to 171.
  • Increase the expected table metric sample count to account for the 256 newly created partitions and related schema objects.
database/schema/ve_db_postgresql.sql
tests/taskomatic_tests/test_db_metrics.py

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="database/schema/upgrade_scripts/170-add-system-vulnerabilities-pkg-detail.sql" line_range="2" />
<code_context>
+CREATE TABLE IF NOT EXISTS system_vulnerabilities_pkg_detail (
+  rh_account_id INT NOT NULL,
+  system_vulnerability_id BIGINT NOT NULL,
+  package_name_id BIGINT NOT NULL,
</code_context>
<issue_to_address>
**issue (bug_risk):** `system_vulnerabilities_pkg_detail.rh_account_id` is declared as `INT`, while `rh_account.id` and the corresponding `rh_account_id` columns elsewhere are `BIGSERIAL`/`BIGINT`. An account ID above the signed 32-bit range cannot be inserted into this table and raises an integer-out-of-range error.

**Triggers:** When the database contains an account ID greater than 2,147,483,647.

**Suggested fix:** Use `BIGINT` for `rh_account_id` to match `rh_account.id` and the other account-scoped tables.

```suggestion
  rh_account_id BIGINT NOT NULL,
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread database/schema/upgrade_scripts/170-add-system-vulnerabilities-pkg-detail.sql Outdated
@jdobes
jdobes force-pushed the package_tables branch 3 times, most recently from bcc3ed3 to e475b82 Compare September 4, 2026 15:09
- enum of all current package architectures
- evr table for unique epoch+version+release tuples, same design as in vmaas
- new partitioned table for system_vulnerabilities details
- extension of system_vulnerable_package where the schema already works well with the new feature

RHINENG-28511
@jdobes
jdobes merged commit 91cdcaa into RedHatInsights:master Sep 7, 2026
7 of 9 checks passed
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