feat(data): replace pre-seeded db with EF Core migrations and HasData() (#459)#460
Conversation
…() (#459) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 14 minutes and 35 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR replaces a pre-seeded SQLite database file committed to the repository with EF Core runtime migrations applied during application startup via Changes
Sequence Diagram(s)sequenceDiagram
participant Startup as Application Startup
participant DI as Dependency Injection
participant EFCore as EF Core
participant SQLite as SQLite Database
Startup->>DI: CreateAsyncScope()
DI->>EFCore: Resolve PlayerDbContext
EFCore->>SQLite: Connect to players-sqlite3.db
Startup->>EFCore: Database.MigrateAsync()
EFCore->>SQLite: Apply InitialCreate migration (DDL)
EFCore->>SQLite: Apply SeedStarting11 migration (DML)
EFCore->>SQLite: Apply SeedSubstitutes migration (DML)
SQLite-->>EFCore: Schema + 25 seed records created
EFCore-->>Startup: Migration complete
Startup->>Startup: Register middleware & endpoints
Startup->>Startup: RunAsync()
Note over Startup,SQLite: App ready to serve 25 players
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Assessment against linked issues
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…459) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@adr/0003-use-sqlite-for-data-storage.md`:
- Around line 21-22: The markdown heading "### Positive" is missing a blank line
before the following bullet list (MD022); edit the ADR content around the
heading "### Positive" and insert a single blank line between that heading and
the list item(s) (e.g., before "- Zero-config: ...") so the heading is separated
from the bullet list.
In
`@src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs`:
- Around line 34-36: The code currently uses
Environment.GetEnvironmentVariable("STORAGE_PATH") directly when building
dataSource, which only falls back on null and will treat empty or whitespace as
a valid (but invalid-for-SQLite) path; change the logic in
ServiceCollectionExtensions so you first read var storagePath =
Environment.GetEnvironmentVariable("STORAGE_PATH"), then check
string.IsNullOrWhiteSpace(storagePath) and only use storagePath when it has
content, otherwise set dataSource to Path.Combine(AppContext.BaseDirectory,
"storage", "players-sqlite3.db"); update the dataSource assignment that
currently references Environment.GetEnvironmentVariable(...) accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f4525fa1-edf5-487d-a33c-d5fd5c1f5892
⛔ Files ignored due to path filters (14)
src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.Designer.csis excluded by!**/Migrations/**,!**/*.Designer.cssrc/Dotnet.Samples.AspNetCore.WebApi/Migrations/20250414195445_SeedStarting11.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.Designer.csis excluded by!**/Migrations/**,!**/*.Designer.cssrc/Dotnet.Samples.AspNetCore.WebApi/Migrations/20251221220614_SeedSubstitutes.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.Designer.csis excluded by!**/Migrations/**,!**/*.Designer.cssrc/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260329000000_NormalizePlayerDataset.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.Designer.csis excluded by!**/Migrations/**,!**/*.Designer.cssrc/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141647_InitialCreate.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.Designer.csis excluded by!**/Migrations/**,!**/*.Designer.cssrc/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141707_SeedStarting11.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.Designer.csis excluded by!**/Migrations/**,!**/*.Designer.cssrc/Dotnet.Samples.AspNetCore.WebApi/Migrations/20260409141721_SeedSubstitutes.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/Migrations/PlayerDbContextModelSnapshot.csis excluded by!**/Migrations/**src/Dotnet.Samples.AspNetCore.WebApi/storage/players-sqlite3.dbis excluded by!**/*.db,!**/storage/**,!**/*.db
📒 Files selected for processing (15)
.github/copilot-instructions.md.gitignoreCHANGELOG.mdDockerfileREADME.mdadr/0003-use-sqlite-for-data-storage.mdscripts/entrypoint.shscripts/run-migrations-and-copy-database.shsrc/Dotnet.Samples.AspNetCore.WebApi/Data/PlayerDbContext.cssrc/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csprojsrc/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cssrc/Dotnet.Samples.AspNetCore.WebApi/Program.cssrc/Dotnet.Samples.AspNetCore.WebApi/appsettings.Development.jsonsrc/Dotnet.Samples.AspNetCore.WebApi/appsettings.jsontest/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/DatabaseFakes.cs
💤 Files with no reviewable changes (3)
- src/Dotnet.Samples.AspNetCore.WebApi/Dotnet.Samples.AspNetCore.WebApi.csproj
- Dockerfile
- scripts/run-migrations-and-copy-database.sh
|
HasData() (#459)



Summary
storage/players-sqlite3.dbbinary blob withdb.Database.MigrateAsync()at startup — schema and seed data are applied automatically before the first request is servedHasData()inOnModelCreating: three self-contained migrations (InitialCreateDDL,SeedStarting11DML,SeedSubstitutesDML) generated by EF Core with literalInsertDatavalues — no migration calls application methods;NormalizePlayerDataseteliminatedDatabaseFakes.CreateTable()(placeholder schema) andSeed()(bypassed migrations) withMigrateAsync()on in-memory SQLiteInformationin developmententrypoint.shto report database presence before launch (matching Rust repo style)Test plan
dotnet build --configuration Releasepassesdotnet test --settings .runsettings— 41/41 passdotnet csharpier --check .passesdocker compose down -v && docker compose up— first run logs "No existing database file found", app starts and serves all 25 players; no raw SQL in container outputdocker compose down && docker compose up— subsequent run logs "Existing database file found", app starts cleanlyReferences
Closes #459
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
STORAGE_PATHenvironment variable.Improvements