Repository: dotnet/efcore
File: src/EFCore.Relational/Migrations/Internal/Migrator.cs (C#)

Code before:
                    builder
                        .AppendLine(sqlGenerationHelper.CommitTransactionStatement)
                        .Append(sqlGenerationHelper.BatchTerminator);
                    transactionStarted = false;
                }
            }

            if (transactionStarted && !isFirstCommandInTransaction)
            {
                builder.Append(sqlGenerationHelper.BatchTerminator);
            }

            isFirstCommandInTransaction = false;

            if (idempotencyCondition != null
                && idempotencyEnd != null)
            {
                builder.AppendLine(idempotencyCondition);
                using (builder.Indent())
                {
                    builder.AppendLines(command.CommandText);
                }

                builder.Append(idempotencyEnd);
            }
            else
            {
                builder.Append(command.CommandText);
            }

            if (!transactionStarted)
            {
                builder.Append(sqlGenerationHelper.BatchTerminator);
            }
        }

        if (transactionStarted)
        {
            builder
                .AppendLine(sqlGenerationHelper.CommitTransactionStatement)
                .Append(sqlGenerationHelper.BatchTerminator);
        }
    }

    /// <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
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    protected virtual IReadOnlyList<MigrationCommand> GenerateUpSql(

Review comment (performance):
@copilot Revert this change and try to find a different fix that also works for multiple batch separators in the same SQL operation 

Code after:
                        .Append(sqlGenerationHelper.BatchTerminator);
                    transactionStarted = false;
                }
            }

            if (idempotencyCondition != null
                && idempotencyEnd != null)
            {
                builder.AppendLine(idempotencyCondition);
                using (builder.Indent())
                {
                    builder.AppendLines(command.CommandText);
                }

                builder.Append(idempotencyEnd);
            }
            else
            {
                builder.Append(command.CommandText);
            }

            if (!transactionStarted)
            {
                builder.Append(sqlGenerationHelper.BatchTerminator);
            }
            else
            {
                builder.Append(Environment.NewLine);
            }
        }

        if (transactionStarted)
        {
            builder
                .AppendLine(sqlGenerationHelper.CommitTransactionStatement)
                .Append(sqlGenerationHelper.BatchTerminator);
        }
    }

    /// <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
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    protected virtual IReadOnlyList<MigrationCommand> GenerateUpSql(
        Migration migration,
        MigrationsSqlGenerationOptions options = MigrationsSqlGenerationOptions.Default)
    {
        var insertCommand = _rawSqlCommandBuilder.Build(
            _historyRepository.GetInsertScript(new HistoryRow(migration.GetId(), ProductInfo.GetVersion())));