Skip to content

[PM-37470] Add UseRiskInsights data migration for existing Enterprise organizations#7691

Draft
AlexRubik wants to merge 2 commits into
mainfrom
dirt/pm-37470/use-risk-insights-data-migration
Draft

[PM-37470] Add UseRiskInsights data migration for existing Enterprise organizations#7691
AlexRubik wants to merge 2 commits into
mainfrom
dirt/pm-37470/use-risk-insights-data-migration

Conversation

@AlexRubik
Copy link
Copy Markdown
Contributor

@AlexRubik AlexRubik commented May 21, 2026

🎟️ Tracking

PM-37470
Parent epic: PM-37469

📔 Objective

Add the data migration step from the Organization Ability README for UseRiskInsights. Sets UseRiskInsights = 1 on every existing Organization row with an Enterprise plan type (4, 5, 10, 11, 14, 15, 19, 20). Covers MSSQL (cloud) and the three EF providers (MySQL, Postgres, SQLite) used by self-host.

The column has existed since 2024-11-25_00_AddUseRiskInsightsToOrganization.sql but the README's step 4 (data migration for existing orgs) was never performed. A stopgap one-off datafix (DBOPS-59) handled cloud in Dec 2025, but orgs created since are missing the flag and self-host instances never received it. This PR delivers the proper repeatable migration.

Re-runs are no-ops: MSSQL uses a WHERE UseRiskInsights = 0 guard so the batched loop exits immediately when there is nothing to update; EF variants set 1 over 1 which is idempotent by construction.

Other subtasks under the parent epic handle plan-definition mapping (PM-37471), admin portal toggle (PM-37473), self-host license claims (PM-37474), re-enabling the endpoint guard (PM-37475), and client-side divergence (PM-37476).

Mirrors the pattern from PM-35253 (#7489) UseInviteLinksDataMigration. SQL formatted per the Bitwarden SQL style guide (each top-level keyword on its own line).

🤖 Testing

The IMigrationTesterService infrastructure was disabled in PM-37482 (#7633, May 14 2026) due to flakiness, so no automated migration integration test ships with this PR. Verification is manual:

  • Seed local MSSQL with one org per Enterprise plan type (4, 5, 10, 11, 14, 15, 19, 20) and a non-Enterprise control, all with UseRiskInsights = 0.
  • Apply migration. Confirm all Enterprise rows flip to 1 and the non-Enterprise row stays at 0.
  • Re-run the script. Confirm the batched loop exits on first iteration with @@ROWCOUNT = 0.
  • On at least one EF provider (MySQL, Postgres, or SQLite), seed equivalent rows and apply the migration via dotnet ef database update. Confirm same outcome.

If this PR sits in review across a calendar shift, rename the MSSQL script's date prefix to the actual merge date.

AlexRubik added 2 commits May 21, 2026 12:45
Set UseRiskInsights = 1 on existing Organization rows with Enterprise
plan types (4, 5, 10, 11, 14, 15, 19, 20). Batched and idempotent.

[PM-37470]
Adds equivalent UPDATE migration for MySQL, Postgres, and SQLite
providers used by self-hosted instances. Mirrors the MSSQL script.

[PM-37470]
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.85%. Comparing base (c27eebb) to head (f9bcbc9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7691   +/-   ##
=======================================
  Coverage   64.85%   64.85%           
=======================================
  Files        2140     2140           
  Lines       94622    94622           
  Branches     8443     8443           
=======================================
  Hits        61370    61370           
  Misses      31156    31156           
  Partials     2096     2096           

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

@AlexRubik AlexRubik added the ai-review Request a Claude code review label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant