Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ protected override void Generate(SqlOperation operation, IModel? model, Migratio
.Replace("\\\r\n", "")
.Split(["\r\n", "\n"], StringSplitOptions.None);

var isScript = Options.HasFlag(MigrationsSqlGenerationOptions.Script);
var hasPendingBatch = false;
var state = ParsingState.Normal;
var batchBuilder = new StringBuilder();
foreach (var line in preBatched)
Expand Down Expand Up @@ -1650,6 +1652,11 @@ protected override void Generate(SqlOperation operation, IModel? model, Migratio

AppendBatch(batchBuilder.ToString());

if (isScript && hasPendingBatch)
Comment thread
AndriySvyryd marked this conversation as resolved.
Outdated
{
EndStatement(builder, operation.SuppressTransaction);
}

ParsingState ConsumeAndReturn(ref int index, ParsingState newState)
{
index++;
Expand All @@ -1660,8 +1667,21 @@ void AppendBatch(string batch)
{
if (!string.IsNullOrWhiteSpace(batch))
{
builder.Append(batch);
EndStatement(builder, operation.SuppressTransaction);
if (isScript)
{
if (hasPendingBatch)
{
builder.Append(Dependencies.SqlGenerationHelper.BatchTerminator);
}

builder.Append(batch);
hasPendingBatch = true;
}
else
{
builder.Append(batch);
EndStatement(builder, operation.SuppressTransaction);
}
}
}
}
Expand Down
Loading