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

Get pending migrations using .NET Core CLI #28283

Open
PavelStefanov opened this issue Jun 21, 2022 · 2 comments
Open

Get pending migrations using .NET Core CLI #28283

PavelStefanov opened this issue Jun 21, 2022 · 2 comments

Comments

@PavelStefanov
Copy link

Hello guys!

First of all, thank you so much for so great tool.

My question is can I get pending migrations using .NET CLI?

In code I can use method DbMigrator.GetPendingMigrations
Example:

var migrations = dbContext.Database.GetPendingMigrations(); 
if (migrations.Any())
    db.Database.Migrate();

But I can't find the same method in the CLI.
My case is simple I need during my CI pipeline check if there are any pending migration I'll create executable bundle and publish it. Otherwise, I can always create a bundle and try to update my db. But I need more controls about changes and I need to understand if there are any migrations or not.

Thanks!

@ajcvickers
Copy link
Contributor

Note for triage: related to #26348.

@PavelStefanov
Copy link
Author

I found workaround. You can use migration list command with --json parameter.

dotnet ef migrations list --json

It gives you structed list of migrations with applied property. You can use it to find pending migrations

[  
  {
    "id": "20220420211839_migration1",
    "name": "migration1",
    "safeName": "migration1",
    "applied": true
  },
  {
    "id": "20220621122349_migration2",
    "name": "migration2",
    "safeName": "migration2",
    "applied": false
  }
]

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