Curiosus.Migrations.Utils 6.0.0

dotnet add package Curiosus.Migrations.Utils --version 6.0.0
                    
NuGet\Install-Package Curiosus.Migrations.Utils -Version 6.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Curiosus.Migrations.Utils" Version="6.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Curiosus.Migrations.Utils" Version="6.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Curiosus.Migrations.Utils" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Curiosus.Migrations.Utils --version 6.0.0
                    
#r "nuget: Curiosus.Migrations.Utils, 6.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Curiosus.Migrations.Utils@6.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Curiosus.Migrations.Utils&version=6.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Curiosus.Migrations.Utils&version=6.0.0
                    
Install as a Cake Tool

Curiosus.Migrations.Utils

NuGet Downloads Coverage

Helpers for Curiosus.Migrations code migrations. MassUpdateCodeMigrationBase updates large tables in small batches, each in its own short transaction, with a pause between batches. This lets data migrations run on a live production database without long locks.

Installation

dotnet add package Curiosus.Migrations.Utils

Usage

Derive from MassUpdateCodeMigrationBase. The base class marks the migration as long-running and turns off the engine transaction. Call DoMassUpdateAsync with a query that selects a limited batch where id > @id and returns the updated ids. The loop continues until a batch comes back empty.

using Curiosus.Migrations;
using Curiosus.Migrations.Utils;

public class FillNewResultCodeMigration : MassUpdateCodeMigrationBase
{
    public FillNewResultCodeMigration() : base(stepDelay: TimeSpan.FromMilliseconds(100)) { }

    public override MigrationVersion Version => new(3, 1);
    public override string? Comment => "Fill calls.new_result_code in batches";

    public override async Task UpgradeAsync(DbTransaction? transaction = null, CancellationToken cancellationToken = default)
    {
        const string sql = @"
            WITH cte AS (
                SELECT id FROM calls
                WHERE id > @id
                ORDER BY id
                LIMIT 10000)
            UPDATE calls c
                SET new_result_code = result_code + 1
            FROM cte
            WHERE cte.id = c.id
            RETURNING cte.id;";

        var total = await DoMassUpdateAsync(
            sql,
            (step, processed) => Logger?.LogInformation("Updated {Step} rows, {Total} total", step, processed),
            cancellationToken);
    }
}

The example is for PostgreSQL. On other databases, write an equivalent batched UPDATE that returns the ids it changed. Because the migration is long-running, it runs only when the policy allows it, for example MigrationPolicy.LongRunningAllowed or MigrationPolicy.AllAllowed.

See also

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 47 9/29/2026
5.0.0 52 9/28/2026