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

Support for a Single Project with Multiple Provider Migrations - Edge Case/Issue/Request #34197

Closed
anewton opened this issue Jul 9, 2024 · 3 comments

Comments

@anewton
Copy link

anewton commented Jul 9, 2024

Support for a Single Project with Multiple Provider Migrations - Edge Case/Issue/Request

  • Summary: Separate class library projects are required to support multiple database providers. It would be nice if one method in the IMigrator (that seems broken) could be fixed to allow placement of multiple provider migrations in a single project, but under different namespace folders (see example code).

Sample project to reproduce on my repo here: Single Project with Multiple Provider Migrations Issue - Entity Framework

Permalink to dotnet EF source code method not working as expected: efcore > src > EFCore.Relational > Migrations > Internal > Migrator.cs

public virtual void Migrate(string? targetMigration = null)

This project attempts to illustrate an edge case that makes separate class library projects a requirement when multiple database providers are used. There seems to be an error in an internal Migrate method that ignores any target migration id when supplied. Noting that this is all undocumented and not supported. It would be very nice to have support for the scenario described.

Code to retrieve the IMigrator implementation. Similar to EF source code that does the same thing.

    private static IMigrator GetMigratorService(DbContext dbContext)
    {
        DatabaseFacade databaseFacade = dbContext.Database;
        IInfrastructure<IServiceProvider> serviceProvider = databaseFacade;
        IMigrator service = serviceProvider.Instance.GetService<IMigrator>();
        return service ?? throw new InvalidOperationException(RelationalStrings.RelationalNotInUse);
    }

Documentation for the supported feature can be found here, Microsoft - Migrations with Multiple Providers, and here, Microsoft - Using a Separate Migrations Project.

Proposed solution:

Make a public method to allow running a migration by a specific target migration id. Or, fix the internal method that already has this parameter but seems not to work as expected. Based on the method name and parameter name.

Provider and version information

EF Core version: 8.0.6 or 8.0.7
Entity Framework Core .NET Command-line Tools: 8.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer or Microsoft.Data.Sqlite
Target framework: .NET 8.0
Operating system: Windows 11 Pro
IDE: Visual Studio 2022 17.10.3

@ajcvickers
Copy link
Contributor

Removing from the backlog because not triaged.

@ajcvickers ajcvickers removed this from the Backlog milestone Jul 11, 2024
@AndriySvyryd AndriySvyryd added this to the Backlog milestone Aug 8, 2024
@AndriySvyryd AndriySvyryd added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. closed-duplicate and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Dec 3, 2024
@AndriySvyryd AndriySvyryd removed this from the Backlog milestone Dec 3, 2024
@AndriySvyryd
Copy link
Member

The Migrate(string) overload was added in 8e9525f
The other aspects are tracked in #29343

@AndriySvyryd AndriySvyryd closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2024
@anewton
Copy link
Author

anewton commented Dec 3, 2024

Ok, thanks @AndriySvyryd.

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

4 participants