Hirondelle 0.4.0
dotnet add package Hirondelle --version 0.4.0
NuGet\Install-Package Hirondelle -Version 0.4.0
<PackageReference Include="Hirondelle" Version="0.4.0" />
<PackageVersion Include="Hirondelle" Version="0.4.0" />
<PackageReference Include="Hirondelle" />
paket add Hirondelle --version 0.4.0
#r "nuget: Hirondelle, 0.4.0"
#:package Hirondelle@0.4.0
#addin nuget:?package=Hirondelle&version=0.4.0
#tool nuget:?package=Hirondelle&version=0.4.0
Hirondelle
Light migration tool for SQLite.
Hirondelle applies the SQL scripts embedded in your assembly to a SQLite database, in version order, one transaction per script. Applied scripts are recorded in a journal table, so each script runs only once, and a script modified after it was applied is detected.
- No configuration: put
.sqlfiles in aMigrationsfolder, they are embedded at build time. - Safe: every script runs in its own transaction; the migration is validated against the journal before anything is executed.
- Concurrent-safe: two applications migrating the same database at the same time cannot corrupt it.
Installation
dotnet add package Hirondelle
Hirondelle targets .NET 10 and uses Microsoft.Data.Sqlite.
Quick start
1. Add your scripts in a Migrations folder at the root of your project:
MyApp/
├── MyApp.csproj
└── Migrations/
├── 1.0.0_create_tables.sql
├── 1.1.0_add_users.sql
└── 1.1.0.1_seed_users.sql
Nothing to add to the .csproj: the package embeds every .sql file of this folder (and of its subfolders) as a resource of your assembly.
2. Register Hirondelle in the dependency injection container. It needs the logging services:
using Hirondelle;
services.AddLogging()
.AddHirondelle();
3. Run the migration at startup, with the assembly that contains the scripts:
using Microsoft.Data.Sqlite;
var migrator = provider.GetRequiredService<IMigrator>();
using var connection = new SqliteConnection("Data Source=app.db");
var applied = migrator.Migrate(connection, typeof(Program).Assembly);
Migrate opens the connection if it is closed, applies the pending scripts and returns the file names of the scripts applied by this call (empty when the database is up to date).
Script names
A script name is a version, an optional name, and the .sql extension:
<version>[_<name>].sql
<version>[-<name>].sql
| Name | Version |
|---|---|
1.0.0_create_tables.sql |
1.0.0 |
1.1.0-add-users.sql |
1.1.0 |
1.1.0.1_seed_users.sql |
1.1.0.1 |
2.0.0.sql |
2.0.0 |
- The version has 3 or 4 numbers.
1.0.0and1.0.0.0are the same version. - The name cannot contain dots or spaces.
- Scripts are applied in version order, not in alphabetical order:
1.10.0comes after1.9.0. - Subfolders are only for organising the scripts: the folder is not part of the script identity, only its file name.
The migration fails before running anything (ArgumentException) when:
- a script has an invalid name;
- two scripts have the same version;
- the assembly contains no script.
Configuration
The embedding is configured with MSBuild properties in your .csproj:
<PropertyGroup>
<HirondelleFolder>Database\Scripts</HirondelleFolder>
<HirondelleAutoEmbed>true</HirondelleAutoEmbed>
</PropertyGroup>
The scripts are embedded with a logical name starting with Hirondelle\, which is the default prefix of Migrate. If you embed the scripts yourself (HirondelleAutoEmbed set to false), give them a logical name that starts with the prefix you pass to Migrate:
<ItemGroup>
<EmbeddedResource Include="Sql\**\*.sql" LogicalName="MyScripts\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
migrator.Migrate(connection, typeof(Program).Assembly, prefix: "MyScripts");
How a migration runs
- The journal table
__migration_historyis created if it does not exist. - The scripts are validated against the journal (see below). On any error, nothing is executed.
- Each pending script runs in its own transaction, together with its entry in the journal:
- on success, the transaction is committed and the next script runs;
- on failure, the transaction is rolled back and the migration stops with the original exception. The scripts applied before stay applied: fix the script and run the migration again.
Since each script already runs in a transaction, a script must not contain BEGIN / COMMIT statements.
The journal
create table __migration_history (
script text primary key, -- file name of the script
sha256 text not null, -- hash of the script content
content text not null, -- content of the script, as applied
applied_at text not null default(strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) -- UTC
);
Validation
Before running anything, every script is compared with the journal:
| Script | In the journal | Situation | Result |
|---|---|---|---|
| Present | Yes, same hash | Already applied | Skipped |
| Present | No | Version above the last applied script | Applied |
| Present, modified | Yes | Content changed after it was applied | Error HashMismatch |
| Missing | Yes | Removed after it was applied | Error MissingResource |
| Present | No | Version below the last applied script | Error VersionBelowLatest |
All the errors are collected and thrown together in a MigrationValidationException. Its Errors property lists them, each with the script, the kind of error and a message:
try
{
migrator.Migrate(connection, typeof(Program).Assembly);
}
catch (MigrationValidationException ex)
{
foreach (var error in ex.Errors)
{
Console.WriteLine($"{error.Kind}: {error.Script} — {error.Message}");
}
}
The hash is computed after normalising the line endings to \n and trimming the leading and trailing white spaces: converting a script from CRLF to LF, or adding a blank line at its end, is not a modification.
Concurrent migrations
When two migrations run on the same database at the same time (e.g. two instances of an application starting together), one of them wins the race and the other one throws a MigrationConcurrencyException:
- on the creation of the journal table, or
- on a script that the other migration applied in the meantime (its
Scriptproperty gives the script name).
The script of the losing migration is rolled back: the database is consistent, and running the migration again completes it.
Contributing
See CONTRIBUTING.md.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.Data.Sqlite (>= 11.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 11.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 11.0.0)
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 |
|---|---|---|
| 0.4.0 | 0 | 12/1/2026 |