Skip to content

Commit

Permalink
Patch for older EF Core versions where "applied" field might be unava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
stil committed Dec 11, 2023
1 parent 0e476f7 commit b10179b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions Efmig/Migrations/Actions/GenerateMigrationScriptAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,32 @@ public class GenerateMigrationScriptAction(IMigrationScriptMode migrationScriptM
public async Task ExecuteAsync(ActionContext ctx)
{
List<MigrationJsonModel> migrations = null;
if (migrationScriptMode is IApplyLastMigrationScriptMode ||
migrationScriptMode is IRollbackLastMigrationScriptMode)
try
{
var migrationsJson = new StringBuilder();

await CommonActionHelper.RunDotnetEfTool(ctx, new CommonActionOptions
if (migrationScriptMode is IApplyLastMigrationScriptMode ||
migrationScriptMode is IRollbackLastMigrationScriptMode)
{
ActionName = "detect migrations",
DataCallback = line => { migrationsJson.AppendLine(line); },
DotnetEfArgs = new[]
{
"migrations",
"list",
"--json"
}
});
var migrationsJson = new StringBuilder();

migrations = JsonSerializer.Deserialize<List<MigrationJsonModel>>(migrationsJson.ToString());
await CommonActionHelper.RunDotnetEfTool(ctx, new CommonActionOptions
{
ActionName = "detect migrations",
DataCallback = line => { migrationsJson.AppendLine(line); },
DotnetEfArgs = new[]
{
"migrations",
"list",
"--json"
}
});

migrations = JsonSerializer.Deserialize<List<MigrationJsonModel>>(migrationsJson.ToString());
}
}
catch (Exception e)
{
ctx.LogError(e.ToString());
throw;
}


Expand Down Expand Up @@ -95,5 +103,5 @@ public class MigrationJsonModel
public string id { get; set; }
public string name { get; set; }
public string safeName { get; set; }
public bool applied { get; set; }
public bool? applied { get; set; }
}

0 comments on commit b10179b

Please sign in to comment.