Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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 on lines +433 to +435
}

using var context = CreateContext(contextType);

if (connectionString != null)
Expand Down
66 changes: 56 additions & 10 deletions 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 @@ -213,27 +228,53 @@ public virtual string ScriptMigration(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void UpdateDatabase(
string? targetMigration,
string? connectionString,
string? contextType)
string? targetMigration,
string? connectionString,
string? contextType)
{
using (var context = _contextOperations.CreateContext(contextType))
if (contextType == "*")
{
if (connectionString != null)
var contexts = _contextOperations.CreateAllContexts();

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

var services = _servicesBuilder.Build(context);
EnsureServices(services);
foreach (var item in contexts)
{
using (item)
{
MigrateContext(item, targetMigration, connectionString);
Comment thread
AndriySvyryd marked this conversation as resolved.
}
Comment thread
AndriySvyryd marked this conversation as resolved.
}

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

var migrator = services.GetRequiredService<IMigrator>();
migrator.Migrate(targetMigration);
using (var context = _contextOperations.CreateContext(contextType))
{
MigrateContext(context, targetMigration, connectionString);
}

_reporter.WriteInformation(DesignStrings.Done);
}

private void MigrateContext(DbContext context, string? targetMigration, string? connectionString)
{
if (connectionString is not null)
{
context.Database.SetConnectionString(connectionString);
}

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

var migrator = services.GetRequiredService<IMigrator>();
migrator.Migrate(targetMigration);
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand All @@ -247,6 +288,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>
Loading