Skip to content

Gate Admin database migrations behind environment variable instead of self-hosted check#7810

Draft
trmartin4 wants to merge 4 commits into
mainfrom
PM-38758/admin-run-migrations-env-var
Draft

Gate Admin database migrations behind environment variable instead of self-hosted check#7810
trmartin4 wants to merge 4 commits into
mainfrom
PM-38758/admin-run-migrations-env-var

Conversation

@trmartin4

@trmartin4 trmartin4 commented Jun 14, 2026

Copy link
Copy Markdown
Member

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-38758

📔 Objective

Helm deployments are self-hosted, but we do not want them to run the Admin-controlled database migrations.

To support this, we disconnect the running of migrations from the user's hosting method, and instead rely on an environment variable.

The value of the variable will be as follows:

Environment Value Result
Self-Hosted Docker deployment Set to true in Docker initialization. Same behavior as today, the migrations run. 👍
Self-Hosted Helm deployment Not set (defaults to false) Changed behavior - will NOT run now. 👍
Cloud Not set (defaults to false) Same behavior as today, the migrations do not run. 👍

Implementation Notes:

  • I elected to move the check into the service, so that it could be tested and so that we can avoid having to use magic strings for the configuration value; if it's checked within Startup.cs the config pipeline hasn't run.
  • As I introduced tests, and the service had a hard-coded 20-second startup and retry delay, I added a TimeProvider to allow testability without making every test run wait the full 20 seconds.

@trmartin4 trmartin4 changed the title Added environment variable for doing database migrations. Gate Admin database migrations behind environment variable instead of self-hosted check Jun 14, 2026
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.17%. Comparing base (125b647) to head (f883857).

Files with missing lines Patch % Lines
src/Admin/Startup.cs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7810      +/-   ##
==========================================
+ Coverage   61.14%   61.17%   +0.02%     
==========================================
  Files        2175     2175              
  Lines       96899    96904       +5     
  Branches     8738     8738              
==========================================
+ Hits        59247    59279      +32     
+ Misses      35542    35513      -29     
- Partials     2110     2112       +2     

☔ View full report in Codecov by Harness.
📢 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.

@trmartin4 trmartin4 added the ai-review Request a Claude code review label Jun 14, 2026
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the change that decouples Admin database migrations from the self-hosted flag and gates them behind a new AdminSettings.RunDatabaseMigrations environment variable. The hosted service is now always registered, performs an early return when the flag is unset, and uses an injected TimeProvider so delays are testable. The Docker installer seeds adminSettings__runDatabaseMigrations=true in global.env, preserving today's Docker self-host behavior while letting Helm deployments opt out by default. Unit tests cover the unset/false gate, the success path, retry-on-DbException, and rethrow-after-max-attempts.

Code Review Details

No new findings beyond the existing (now outdated) suggestion thread on test naming, which has since been addressed in the current test names. CI signals (Codecov patch coverage 66.66% on Startup.cs, SonarCloud quality gate passing) are consistent with hard-to-cover composition-root code.

Comment thread test/Admin.Test/HostedServices/DatabaseMigrationHostedServiceTests.cs Outdated
Comment thread test/Admin.Test/HostedServices/DatabaseMigrationHostedServiceTests.cs Outdated
@sonarqubecloud

Copy link
Copy Markdown

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