kasuken / kasuken/LearnStack

[Blocker] Move EF Core migrations out of application startup

Open
#41 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
HTML
Stars
10
Forks
0
Avg merge
2h 52m
Merged PRs (30d)
20

Description

Tier 1 — release blocker

Problem

Database.MigrateAsync() runs on every boot inside Program.cs and rethrows on failure, so a bad migration or a cold/throttled SQL connection takes the whole site down at startup. With more than one instance, migrations race against each other. This has already caused an Azure startup failure (commit 06b8f0a, "fix: add missing user display name migration").

Evidence
  • LearnStack/Program.cs:57-70
Proposed fix
  1. Generate a migration bundle in CI: dotnet ef migrations bundle --self-contained.
  2. Run the bundle as a deployment step against the target database, before the app is swapped in.
  3. Keep startup read-only — at most a CanConnectAsync check wired into the health endpoint.
  4. Optionally guard with a pending-migration check that fails the health probe rather than the process.
Acceptance criteria
  • App startup performs no schema changes
  • Deploy pipeline applies migrations as an explicit, observable step
  • A failed migration blocks the swap instead of crashing production

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with LearnStack/Program.cs:57-70 and trace the current Database.MigrateAsync() startup path. Review how the deployment pipeline can run dotnet ef migrations bundle --self-contained before swap and how the health endpoint should report connectivity or pending migrations. Done means startup performs no schema changes, deployment applies migrations observably, and failures block the swap rather than crash the app.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, database, devops
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.