[PM-37470] Add UseRiskInsights data migration for existing Enterprise organizations#7691
[PM-37470] Add UseRiskInsights data migration for existing Enterprise organizations#7691AlexRubik wants to merge 4 commits into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7691 +/- ##
==========================================
+ Coverage 64.85% 65.05% +0.20%
==========================================
Files 2140 2147 +7
Lines 94622 95184 +562
Branches 8443 8526 +83
==========================================
+ Hits 61370 61926 +556
+ Misses 31156 31137 -19
- Partials 2096 2121 +25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Keep UPDATE TOP (N) [target] (and bare UPDATE [target] in the EF variants) as a single header line. SET and WHERE arguments still indent onto their own line. No functional change. [PM-37470]
Bitwarden Claude Code ReviewOverall Assessment: APPROVE This PR delivers the step 4 data migration from the Organization Ability README for Code Review DetailsNo findings. |
|
Match the MSSQL DbScript, which only updates rows where UseRiskInsights is currently 0. Reduces write churn on already-correct rows and keeps cloud (MSSQL) and self-host (EF) UPDATE shape identical. [PM-37470]
|
@claude review this again pleaseee |
|
Claude finished @AlexRubik's task in 1m 43s —— View job Claude Code Review (re-review)
Overall Assessment: APPROVE — no new findings since the prior review. Verification notes
Observation (not a blocker)The PR description already calls this out: if the PR sits in review past calendar shifts, the MSSQL filename |
| AND [UseRiskInsights] = 0; | ||
|
|
||
| SET @RowsAffected = @@ROWCOUNT; | ||
| END |



🎟️ Tracking
PM-37470
Parent epic: PM-37469
📔 Objective
Add the data migration step from the Organization Ability README for
UseRiskInsights. SetsUseRiskInsights = 1on every existingOrganizationrow 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.sqlbut 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 = 0guard so the batched loop exits immediately when there is nothing to update; EF variants set1over1which 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
IMigrationTesterServiceinfrastructure 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:UseRiskInsights = 0.1and the non-Enterprise row stays at0.@@ROWCOUNT = 0.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.