Skip to content

ROX-32721: Add migration to backfill deployment_type and enforcement_count#20031

Draft
dashrews78 wants to merge 3 commits intodashrews/add-columns-32721from
dashrews/migration-32721
Draft

ROX-32721: Add migration to backfill deployment_type and enforcement_count#20031
dashrews78 wants to merge 3 commits intodashrews/add-columns-32721from
dashrews/migration-32721

Conversation

@dashrews78
Copy link
Copy Markdown
Contributor

Three-phase migration that avoids walking the full alerts table:

  1. DDL: Add deployment_type (varchar) and enforcementcount (integer) columns
    via GORM CreateTable (idempotent, instant in Postgres).

  2. Backfill deployment_type via JOIN with deployments table (pure SQL, no
    blob deserialization). Orphaned alerts (deployment deleted) fall back to
    reading the value from the serialized blob.

  3. Backfill enforcement_count only for the small subset of active alerts
    with enforcement (state=ACTIVE AND enforcement_action!=0). These rows
    are deserialized, the count is computed, and both the column and
    serialized blob are updated to maintain consistency.

The migration is idempotent and backwards compatible -- old code ignores
the new columns, and pre-migration queries continue to work.

Partially generated by AI.

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

Description

change me!

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

change me!

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 15, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@dashrews78
Copy link
Copy Markdown
Contributor Author

dashrews78 commented Apr 15, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

🚀 Build Images Ready

Images are ready for commit cd5e37e. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.11.x-665-gcd5e37e583

@dashrews78 dashrews78 force-pushed the dashrews/migration-32721 branch from c70f096 to 5413be2 Compare April 15, 2026 19:21
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 59.67078% with 98 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.62%. Comparing base (9287d8c) to head (cd5e37e).

Files with missing lines Patch % Lines
..._and_enforcement_count_to_alerts/migration_impl.go 59.33% 70 Missing and 28 partials ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           dashrews/add-columns-32721   #20031      +/-   ##
==============================================================
+ Coverage                       49.61%   49.62%   +0.01%     
==============================================================
  Files                            2765     2767       +2     
  Lines                          208707   208950     +243     
==============================================================
+ Hits                           103548   103693     +145     
- Misses                          97497    97568      +71     
- Partials                         7662     7689      +27     
Flag Coverage Δ
go-unit-tests 49.62% <59.67%> (+0.01%) ⬆️

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:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

dashrews78 and others added 3 commits April 16, 2026 07:12
…count

Three-phase migration that avoids walking the full alerts table:

1. DDL: Add deployment_type (varchar) and enforcementcount (integer) columns
   via GORM CreateTable (idempotent, instant in Postgres).

2. Backfill deployment_type via JOIN with deployments table (pure SQL, no
   blob deserialization). Orphaned alerts (deployment deleted) fall back to
   reading the value from the serialized blob.

3. Backfill enforcement_count only for the small subset of active alerts
   with enforcement (state=ACTIVE AND enforcement_action!=0). These rows
   are deserialized, the count is computed, and both the column and
   serialized blob are updated to maintain consistency.

The migration is idempotent and backwards compatible -- old code ignores
the new columns, and pre-migration queries continue to work.

Partially generated by AI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Migrations cannot import pkg/alert/convert (roxvet restriction). Remove
the compile-time sync check and replace with a comment noting the
dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add migration import to migrator/runner/all.go and increment
CurrentDBVersionSeqNum from 223 to 224. These were generated by
make bootstrap_migration but missed from the initial commit.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dashrews78 dashrews78 force-pushed the dashrews/migration-32721 branch from 5413be2 to cd5e37e Compare April 16, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant