Curiosus.Migrations
6.0.0
dotnet add package Curiosus.Migrations --version 6.0.0
NuGet\Install-Package Curiosus.Migrations -Version 6.0.0
<PackageReference Include="Curiosus.Migrations" Version="6.0.0" />
<PackageVersion Include="Curiosus.Migrations" Version="6.0.0" />
<PackageReference Include="Curiosus.Migrations" />
paket add Curiosus.Migrations --version 6.0.0
#r "nuget: Curiosus.Migrations, 6.0.0"
#:package Curiosus.Migrations@6.0.0
#addin nuget:?package=Curiosus.Migrations&version=6.0.0
#tool nuget:?package=Curiosus.Migrations&version=6.0.0
Curiosus.Migrations
Core engine of Curiosus.Migrations, a database migration framework for .NET that combines raw SQL scripts and C# code migrations. Install it together with a database provider: PostgreSQL or SQL Server.
Installation
dotnet add package Curiosus.Migrations
dotnet add package Curiosus.Migrations.PostgreSQL # or Curiosus.Migrations.SqlServer
Usage
Put SQL scripts named by version (1.0.sql, 1.1-add_users.sql, 2.0.down.sql) into a directory. Then configure and run the engine:
using Curiosus.Migrations;
using Curiosus.Migrations.PostgreSQL;
var engine = new MigrationEngineBuilder(services)
.UseScriptMigrations().FromDirectory("./Migrations")
.UseCodeMigrations().FromAssembly(typeof(Program).Assembly)
.ConfigureForPostgreSql(connectionString)
.UseUpgradeMigrationPolicy(MigrationPolicy.ShortRunningAllowed)
.Build();
var result = await engine.UpgradeDatabaseAsync(cancellationToken);
if (!result.IsSuccessfully)
throw new InvalidOperationException($"{result.ErrorCode}: {result.ErrorMessage}");
The engine creates the database and the migration history table if they do not exist. To register
IMigrationEngine as a singleton, call services.AddMigrations(builder => ...) instead.
A code migration is a class derived from CodeMigration:
public class SeedRolesMigration : CodeMigration
{
public override MigrationVersion Version => new(1, 2);
public override string? Comment => "Seed default roles";
public override Task UpgradeAsync(DbTransaction? transaction = null, CancellationToken cancellationToken = default) =>
MigrationConnection.ExecuteNonQuerySqlAsync("INSERT INTO roles (name) VALUES ('admin');", null, cancellationToken);
}
Key concepts
- Script migrations come from a directory or from embedded resources. They can be split into batches with
--BATCH:. Directives such as--CURIOSUS:TRANSACTION=OFF,--CURIOSUS:LONG-RUNNING=TRUEand--CURIOSUS:DEPENDENCIES=1.0, 1.1set options for a script. The legacy--CURIOSITY:prefix still works. - Code migrations are C# classes. They support dependency injection and EF Core.
- Downgrade uses
*.down.sqlscripts orIDowngradeMigration. CallDowngradeDatabaseAsyncwith a target version set bySetUpTargetVersion. - Long-running migrations and policies: the upgrade and downgrade
MigrationPolicyvalues decide which migrations run, so heavy data migrations can run separately from fast schema changes. - Pre-migrations, variables, transactions, dependencies, journal and custom migration providers.
See also
- Curiosus.Migrations.PostgreSQL: PostgreSQL provider
- Curiosus.Migrations.SqlServer: SQL Server provider
- Curiosus.Migrations.Utils: helpers for batched mass data updates
- Documentation and Quick Start
- Curiosus.Migrations: repository and all packages
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Curiosus.Migrations:
| Package | Downloads |
|---|---|
|
Curiosus.Migrations.Utils
Without migrations you need to create a lots of sql scripts that have to be run manually by every developer involved. Migrations solve the problem of evolving a database schema for multiple databases (for example, the developer's local database, the test database and the production database). |
|
|
Curiosus.Migrations.PostgreSQL
Curiosus.Migrations is a migration framework that uses SQL scripts and code migration to alter your database schema or seed a data. |
|
|
Curiosus.Migrations.SqlServer
Curiosus.Migrations is a migration framework that uses SQL scripts and code migration to alter your database schema or seed a data. |
GitHub repositories
This package is not used by any popular GitHub repositories.