HistoryRepository should return filtered list of applied migrations where the list of migrations in code serves as a baseine.
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Repo to reporduce: https://github.com/voroninp/EfMultipleContextsSameHistoryTable
When working with migrations, active database context should provide a list of migrations defined in code, and this list should be the baseline.
By default the call to `GetAppliedMigrations` should return only the migrations which belong to the active context.
Currently, HisroryRepository [just returns the list of migrations from history table](https://github.com/dotnet/efcore/blob/757c823f0833805f8f8999a52cc7f931d29d198f/src/EFCore.Relational/Migrations/HistoryRepository.cs#L265).
Yet migrations history table can be reused by multiple contexts. (At least I could not find the warning in the documentation that each context should have its own history table.)
---
Alternatively, I'd propose that each migration withing the same history contains some fixed id, so it's easy to understand which context it belongs to.
```
[DbContext(typeof(Ctx2))]
[MigrationHistory(id: "abc-def")]
[Migration("20240730133611_Bar", historyId: )]
```
and
```
[DbContext(typeof(Ctx2))]
[MigrationHistory(id: "abc-def.")]
partial class Ctx2ModelSnapshot : ModelSnapshot
```
This `HisotoryId` should be the column in `__EFMigrationsHistory` table.
Contributor guide
Assessment
This issue has not been assessed yet.