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

Migrations: Top level APIs for All/Applied/Pending #6110

Closed
rowanmiller opened this issue Jul 19, 2016 · 8 comments
Closed

Migrations: Top level APIs for All/Applied/Pending #6110

rowanmiller opened this issue Jul 19, 2016 · 8 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@rowanmiller
Copy link
Contributor

These APIs on DbContext.Database were useful in EF6. One example of where these would be useful is manually applying each migration so that you can give status to the user (#6038).

@rondefreitas
Copy link

@rowanmiller I haven't dug into the migrator code yet, but when you tell the migrator to apply a migration does it check again to see if it's already been applied?

I have a scenario wherein a load-balanced asp.net core application may require each instance to run on its own time after deploying a new version but then either share the migrations workload between the instances, or at least allow one of the instances to take ownership of the migrations by updating a database flag.

@rowanmiller
Copy link
Contributor Author

@Rdefreitas the code I shared in the previous issue migrator.Migrate(targetMigration: pending[i]); isn't saying to apply a specific migration, it's saying to apply all pending migrations up to (and including) the one specified. Because the specified migration was being incremented by one on each iteration, it was applying just a single migration. Given that, the answer is yes, it will skip the migration if it is already applied.

@bricelam
Copy link
Contributor

bricelam commented Aug 9, 2016

These APIs on DbContext.Database were useful in EF6.

Huh? 😕 We had APIs on DbMigrator, but never off DbContext.Database AFAIK.

@anpete
Copy link
Contributor

anpete commented Aug 9, 2016

@bricelam I think you are right.

@bricelam bricelam removed this from the 1.1.0 milestone Aug 10, 2016
@ajcvickers
Copy link
Contributor

I think the general idea here is that it was easy to create a Migrator in EF6, which made it easy to do these things. It's also pretty easy to get a Migrator in EF Core, although very undiscoverable:

var migrator = context.GetService<IMigrator>();

But then once you get the Migrator it only has Migrate and GenerateSql.

So, regardless of what the actual API was in EF6, we want to make it easier to do these additional things in EF Core in whatever way makes sense for EF Core.

@divega divega added this to the 1.1.0 milestone Aug 10, 2016
@bricelam
Copy link
Contributor

bricelam commented Aug 24, 2016

For comparison:

EF6

var migrator = new DbMigrator(new MigrationsConfiguration());

var all = migrator.GetLocalMigrations();
var applied = migrator.GetDatabaseMigrations();
var pending = migrator.GetPendingMigrations();

EFCore (1.0.0)

var migrationsAssembly = db.GetService<IMigrationsAssembly>();
var historyRepository = db.GetService<IHistoryRepository>();

var all = migrationsAssembly.Migrations.Keys;
var applied = historyRepository.GetAppliedMigrations().Select(r => r.MigrationId);
var pending = all.Except(applied);

@bricelam
Copy link
Contributor

The scenarios in this issue overlap with with those of issue #577

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 31, 2016
@greggbjensen
Copy link

We are using migrations against SQL Azure which requires a retry. We also need the progress of which migration it is on. This would be great to add to the framework. For now, I have done a workaround as above.

@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

7 participants