Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
10 changes: 10 additions & 0 deletions src/EFCore.Design/Design/Internal/DbContextOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ protected DbContextOperations(
/// </summary>
public virtual void DropDatabase(string? contextType, string? connectionString)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
}

using var context = CreateContext(contextType);

if (connectionString != null)
Expand Down Expand Up @@ -425,6 +430,11 @@ private IReadOnlyList<string> PrecompileQueries(
/// </summary>
public virtual ContextInfo GetContextInfo(string? contextType, string? connectionString = null)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
Comment thread
AndriySvyryd marked this conversation as resolved.
}

using var context = CreateContext(contextType);

if (connectionString != null)
Expand Down
53 changes: 52 additions & 1 deletion src/EFCore.Design/Design/Internal/MigrationsOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public virtual MigrationFiles AddMigration(
string? @namespace,
bool dryRun)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
}

using var context = _contextOperations.CreateContext(contextType);
var services = PrepareForMigration(name, context);

Expand Down Expand Up @@ -147,6 +152,11 @@ public virtual IEnumerable<MigrationInfo> GetMigrations(
string? connectionString,
bool noConnect)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
}

using var context = _contextOperations.CreateContext(contextType);

if (connectionString != null)
Expand Down Expand Up @@ -197,6 +207,11 @@ public virtual string ScriptMigration(
MigrationsSqlGenerationOptions options,
string? contextType)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
}

using var context = _contextOperations.CreateContext(contextType);
var services = _servicesBuilder.Build(context);
EnsureServices(services);
Expand All @@ -217,9 +232,40 @@ 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();

if (!contexts.Any())
{
throw new OperationException(DesignStrings.NoContext(_assembly.GetName().Name));
}

foreach (var item in contexts)
{
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)
if (connectionString is not null)
{
context.Database.SetConnectionString(connectionString);
}
Expand Down Expand Up @@ -247,6 +293,11 @@ public virtual MigrationFiles RemoveMigration(
bool dryRun,
string? connectionString)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
}

using var context = _contextOperations.CreateContext(contextType);

if (connectionString != null)
Expand Down
6 changes: 6 additions & 0 deletions src/EFCore.Design/Properties/DesignStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore.Design/Properties/DesignStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,7 @@ Change your target project to the migrations project by using the Package Manage
<data name="MigrationCreatedAndApplied" xml:space="preserve">
<value>Migration '{migrationId}' was successfully created and applied.</value>
</data>
<data name="WildcardNotSupported" xml:space="preserve">
<value>The wildcard '*' is not supported for this command.</value>
Comment thread
AndriySvyryd marked this conversation as resolved.
Outdated
</data>
</root>