Fully embrace provider-specific migrations
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- databases, documentation, tooling
Research direction
Start by reviewing issues #12212 and #15174 and the provider-migrations documentation linked in the issue. Done means addressing the proposal to store database types in the model snapshot, enforce provider-specific migrations, and update the documentation to stop recommending conditional code.
Written by the indexing model from the issue text.
Description
Current situation
Scaffolded migrations target a specific database provider. This means that it is not in general possible to scaffold a migration against one provider and then use it with another provider.
However, we try to keep the migration "relatively agnostic to the provider" so that there should be only small differences between the migrations for different providers. The most obvious case of this (and perhaps the only one) is that we don't put store types obtained from a type mapping in the migration, because they are very provider-specific. But this has been a source of bugs such as #12212.
So if we drop the "relatively agnostic" part, then we can make provider-specific migrations more robust by removing a source of complexity and bugs.
What changed?
So why did we not take this path already? Well I, for one, believed that it was relatively easy to take two migrations and edit them together into a single migration with some conditional code. Indeed, we even documented this. But it turns out that this isn't easy, because if you want to maintain a full set of migrations that can go up/down for multiple providers, then you also need to merge the model snapshot and the code-behind, both of which are also provider specific. It's hard to believe that many people are doing this, let alone doing it right.
How to we make the experience good
The other way to handle migrations for multiple providers is to have multiple parallel sets of migrations, one for each provider. This is also documented.
However, I think we could make this easier (post-3.0) by annotating the migration with the provider it targets and then adding some support in tooling. For example, #15174 is about throwing if the migration was created for a different provider. But we could extend this to find the right migration from multiple annotated with different provider names.
What should we do now?
Proposal:
- Fix issues like #12212 by storing the database type in the model snapshot.
- Implement #15174 to more forcibly assert that migrations are provider-specific.
- Update the docs to stop recommending conditional code.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 134
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/efcore
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
customer-reported
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
area-cosmos area-vector-search
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-cosmos
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
area-tools needs-design
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100