MigLib 11.0.0

dotnet add package MigLib --version 11.0.0
                    
NuGet\Install-Package MigLib -Version 11.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="MigLib" Version="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MigLib" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MigLib" />
                    
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 MigLib --version 11.0.0
                    
#r "nuget: MigLib, 11.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 MigLib@11.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=MigLib&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MigLib&version=11.0.0
                    
Install as a Cake Tool

logo

.NET F# License: Apache2 NuGet Version NuGet Downloads Tests

Migrate is a SQLite-first toolkit: ordered *.sql files are the dev-time schema source of truth, and mig codegen turns them into typed F# query modules plus a migrations module that ships with the executable.

What it does

  1. You write ordered *.sql migrations (applied by file name) during development.
  2. You annotate tables/views with -- mig: comments for the ops you want.
  3. mig codegen (or MigLib.Codegen.generate) applies migrations to a temp DB, introspects schema, and emits one .fs module per annotated relation plus Migrations.fs (scripts as ordinary F# string constants) into an output directory.
  4. At runtime you call MigLib.migrateScripts dbPath Migrations.scripts and use dbTxn with generated helpers on Microsoft.Data.Sqlite.

Migrations travel inside the binary as compiled string data — not as loose *.sql files next to the app, not as EmbeddedResource / content files, and not via reflection. That keeps Native AOT and trimming friendly.

There is no F#-first schema DSL, no SqlProvider, no DbUp dependency, and no automatic normalization.

Annotation example

-- mig:rel User
-- mig:ops insert, select_by(email), select_by_id
-- mig:ops upsert
-- mig:bool active
-- mig:datetime created_at
CREATE TABLE app_user (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  email TEXT NOT NULL,
  active INTEGER NOT NULL,
  created_at TEXT NOT NULL
) STRICT;

-- mig:ops select_all, select_one_by(email)
CREATE VIEW active_user AS
  SELECT id, email, created_at FROM app_user WHERE active = 1;

Rules:

  • Unannotated relations generate no F#.
  • Ops are explicit; no ops means no type.
  • Multiple -- mig:ops lines on one relation are merged in order (handy for long lists).
  • Views only allow read ops (select_*); write ops fail at codegen.
  • -- mig:rel Name is optional; otherwise the F# name is derived from the SQL identifier.

See specs/sql_first_rewrite.md for the full design.

Installation

dotnet tool install --global migtool

Library:

dotnet add package MigLib

Codegen

mig codegen \
  --migrations ./Migrations \
  --output ./Stores \
  --namespace MyApp.Db

This writes Stores/User.fs, Stores/ActiveUser.fs, etc. (module MyApp.Db.User, …), plus Stores/Migrations.fs (module MyApp.Db.Migrations with scripts : (string * string) list). Hand-written companions can live alongside generated files; only files marked // <auto-generated /> are deleted when a relation disappears (Migrations.fs is always kept).

From build.fsx / F#:

open MigLib.Codegen

match generate "./Migrations" "./Stores" "MyApp.Db" with
| Ok r ->
    Console.WriteLine(
      "generated "
      + string r.relationCount
      + " relations in "
      + r.outputDir)
    r.generatedFiles |> List.iter (fun p -> Console.WriteLine("  " + p))
| Error e -> failwith e

Runtime

open System
open MigLib
open MyApp.Db

// apply scripts compiled into the app (module MyApp.Db.Migrations)
do!
  migrateScripts dbPath Migrations.scripts
  |> Task.map (function Ok () -> () | Error e -> failwith e)

// use transactions + generated queries (module MyApp.Db.User)
let! user =
  dbTxn dbPath {
    match! User.selectOneByEmail email with
    | Some u -> return u
    | None ->
      let! id =
        User.insert
          { Email = email
            Active = true
            CreatedAt = DateTimeOffset.UtcNow }
      return! User.selectById id |> TxnStep.map Option.get
  }

Packages

Package Role
migtool CLI (mig codegen, mig version)
MigLib Runtime: dbTxn / TxnStep, Query, list-based migrateScripts (AOT-friendly; no reflection)
MigLib.Codegen Dev-time generate API (used by CLI and build.fsx)

Local build

dotnet fsi build.fsx -- --target build
dotnet fsi build.fsx -- --target install
cd src && dotnet test

Version

Major version 10 is a greenfield rewrite (SQL-first). Older MigSchema / attribute-based workflows are not supported.

Further reading

See documentation/interesting-links.md for SQLite concurrency, migrations, and related theory links.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MigLib:

Package Downloads
MigLib.Web

Package Description

MigLib.Codegen

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.0 30 7/31/2026
10.0.0 42 7/30/2026
9.1.0 232 6/2/2026
9.0.0 144 6/1/2026
8.3.0 121 5/29/2026
8.2.0 121 5/29/2026
8.1.1 125 5/28/2026
8.1.0 134 5/28/2026
8.0.4 122 5/26/2026
8.0.3 123 5/26/2026
8.0.2 257 5/24/2026
8.0.1 122 5/23/2026
8.0.0 151 5/17/2026
7.0.2 143 4/14/2026
7.0.1 122 4/14/2026
7.0.0 121 4/11/2026
6.0.1 128 4/10/2026
6.0.0 130 4/10/2026
5.4.0 116 4/7/2026
5.3.0 113 4/7/2026
Loading failed