Skip to content

DatabaseFacade.Migrate - please allow --namespace as argument #21444

@Tommigun1980

Description

@Tommigun1980

Hi.

I have multiple sets of migrations as per #21443, and would like to run auto migration for the local and development environments.

DatabaseFacade.Migrate doesn't accept any arguments, so it will try to run all migrations in the project. Running

dotnet ef database update --namespace=MyApp.MobileAppService.Migrations.Development --context ContextName

allows for the --namespace argument, which will pick the correct "set" of migrations.

I'd like to do the same programmatically, but DatabaseFacade.Migrate() doesn't support it. So please add an overload,

DatabaseFacade.Migrate(string namespace)

so it reaches parity with the command line migration capability.


Here is an example of what I'd like to do:

if (this.IsLocalOrDevelopmentEnvironment())
{
    var migrationNamespace = $"MyApp.MobileAppService.Migrations.{this.environment.EnvironmentName}";
    myContext.Database.Migrate(migrationNamespace);
}

which would be analogous to running:

dotnet ef database update --namespace=MyApp.MobileAppService.Migrations.$ENVIRONMENT --context MyContext

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions