Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/EFCore.Design/Design/Internal/MigrationsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,29 @@ public virtual void UpdateDatabase(
string? connectionString,
string? contextType)
{
// Fix wildcard * issue #38254
Comment thread
AndriySvyryd marked this conversation as resolved.
Outdated
if (contextType == "*")
{
var contexts = _contextOperations.CreateAllContexts();
foreach (var item in contexts)
Comment thread
BrunoSync marked this conversation as resolved.
Outdated
{
using (item)
{
if (connectionString is not null)
item.Database.SetConnectionString(connectionString);
Comment thread
BrunoSync marked this conversation as resolved.
Outdated

var services = _servicesBuilder.Build(item);
EnsureServices(services);

var migrator = services.GetRequiredService<IMigrator>();
migrator.Migrate(targetMigration);
}
}
Comment thread
AndriySvyryd marked this conversation as resolved.

_reporter.WriteInformation(DesignStrings.Done);
return;
}

using (var context = _contextOperations.CreateContext(contextType))
{
if (connectionString != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public void AddMigration_throws_when_name_is_whitespace()
Assert.Equal(DesignStrings.MigrationNameRequired, exception.Message);
}

[ConditionalFact]
public void UpdateDatabase_with_wildcard_context_runs_for_all_contexts()
{
var assembly = MockAssembly.Create([typeof(AssemblyTestContext), typeof(TestContext)]);
Comment thread
BrunoSync marked this conversation as resolved.
Outdated
var operations = new TestMigrationsOperations(
new TestOperationReporter(),
assembly,
assembly,
"projectDir",
"RootNamespace",
"C#",
nullable: false,
args: []);

operations.UpdateDatabase(null, null, "*");
}

private class TestContext : DbContext;

private class AssemblyTestContext : DbContext
Expand Down