MigLib 10.0.0
dotnet add package MigLib --version 10.0.0
NuGet\Install-Package MigLib -Version 10.0.0
<PackageReference Include="MigLib" Version="10.0.0" />
<PackageVersion Include="MigLib" Version="10.0.0" />
<PackageReference Include="MigLib" />
paket add MigLib --version 10.0.0
#r "nuget: MigLib, 10.0.0"
#:package MigLib@10.0.0
#addin nuget:?package=MigLib&version=10.0.0
#tool nuget:?package=MigLib&version=10.0.0
Migrate is a SQLite-first toolkit: filesystem SQL migrations are the schema source of truth, and mig codegen emits typed F# queries for relations you annotate.
What it does
- You write ordered
*.sqlmigrations (applied by file name). - You annotate tables/views with
-- mig:comments for the ops you want. mig codegen(orMigLib.Codegen.generate) applies migrations to a temp DB, introspects schema, and emits one.fsmodule file per annotated relation into an output directory.- At runtime you call
MigLib.migrateScriptsand usedbTxnwith generated helpers onMicrosoft.Data.Sqlite(runtime package only — no codegen dependency).
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:opslines on one relation are merged in order (handy for long lists). - Views only allow read ops (
select_*); write ops fail at codegen. -- mig:rel Nameis 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, …). Hand-written companions can live alongside generated files; only files marked // <auto-generated /> are deleted when a relation disappears.
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 migrations from a directory of *.sql files
do!
migrateScripts dbPath "./Migrations"
|> 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, filesystem migrateScripts (AOT-oriented) |
| 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.
| 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
- FSharp.Core (>= 10.1.301)
- Lamg.Env (>= 0.6.0)
- Microsoft.Data.Sqlite (>= 9.0.0)
- SQLitePCLRaw.bundle_e_sqlite3 (>= 2.1.12)
- SQLitePCLRaw.core (>= 2.1.12)
- SQLitePCLRaw.lib.e_sqlite3 (>= 2.1.12)
- SQLitePCLRaw.provider.e_sqlite3 (>= 2.1.12)
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 |
|---|---|---|
| 10.0.0 | 0 | 7/30/2026 |
| 9.1.0 | 230 | 6/2/2026 |
| 9.0.0 | 143 | 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 |
| 5.2.9 | 196 | 4/3/2026 |