Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HistoryRepository should return filtered list of applied migrations where the list of migrations in code serves as a baseine. #34318

Open
voroninp opened this issue Jul 30, 2024 · 4 comments

Comments

@voroninp
Copy link

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.

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.

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Aug 8, 2024

IHistoryRepository is a low-level service, so it's by-design that it returns rows for all contexts. But we should filter them in Database.GetAppliedMigrationsAsync and Database.GetPendingMigrationsAsync

@ErikEJ FYI, in case you have thoughts about this

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 9, 2024

@AndriySvyryd I have removed my migrations tooling in case that's what you are referring to?

https://github.com/ErikEJ/EFCorePowerTools/wiki/Migrations-Tool

@AndriySvyryd
Copy link
Member

Oh, didn't realize that

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 9, 2024

It is a quite recent decision. Never heard from anyone missing it 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants