MigLib 8.0.0
dotnet add package MigLib --version 8.0.0
NuGet\Install-Package MigLib -Version 8.0.0
<PackageReference Include="MigLib" Version="8.0.0" />
<PackageVersion Include="MigLib" Version="8.0.0" />
<PackageReference Include="MigLib" />
paket add MigLib --version 8.0.0
#r "nuget: MigLib, 8.0.0"
#:package MigLib@8.0.0
#addin nuget:?package=MigLib&version=8.0.0
#tool nuget:?package=MigLib&version=8.0.0
Migrate is a SQLite-first migration toolchain built around a DomainModeling project, generated Db.fs, and compiled schema modules.
It generates typed CRUD/query helpers from compiled schema definitions and provides blocking init, plan, migrate, status, and reset workflows for schema-bound SQLite files.
Project Convention
The current convention is:
- Keep the runtime project in the working directory.
- Keep the domain modeling project at
DomainModeling/DomainModeling.fsproj. - Keep the schema source at
DomainModeling/MigSchema.fs. - Run
mig codegenfrom the runtime project directory. - Let
mig codegenwriteDb.fsinto the domain modeling directory. - Build the runtime project after code generation so the compiled runtime assembly contains the generated module.
MigSchema.fs must mark the schema module with GeneratedDbNamespace:
[<MigLib.Dsl.Attributes.GeneratedDbNamespace("MyApp")>]
module MyApp.DomainModeling.MigSchema
mig codegen uses that attribute to generate MyApp.Db and derive the SQLite filename prefix.
Generated Code
mig codegen emits a runtime module that contains:
GeneratedSchema- generated record and DU types
- generated CRUD/query helpers driven by schema annotations
Examples of generated helpers include:
Student.InsertStudent.InsertOrIgnoreStudent.SelectByIdStudent.SelectAllStudent.SelectByNameStudent.SelectNameLikeStudent.SelectByNameOrInsertStudent.Upsert
Installation
Install the CLI as a global tool:
dotnet tool install --global migtool
For library usage:
- install
MigLibfor schema attributes, generated CRUD support, transactions, and migration workflows - install
MigLib.Webwhen you also want the ASP.NET CorewebResulthelpers
Local Tool Build
Build and install the current branch as a global mig tool from the local package output:
dotnet fsi build.fsx install
Quickstart: Init
Build the domain modeling project, generate Db.fs, build the runtime project, and initialize the schema-bound database:
dotnet build ./my-app/DomainModeling/DomainModeling.fsproj
mig codegen -d ./my-app
dotnet build ./my-app/my-app.fsproj
mig init -d ./my-app
mig init is idempotent at the workflow level: when the target database already exists, it reports success and does not recreate it.
Quickstart: Migrate
When a previous schema-bound SQLite file already exists for the same app/instance prefix, mig migrate creates the new target database, copies compatible data, and archives the old file into archive/ next to the database directory.
dotnet build ./my-app/DomainModeling/DomainModeling.fsproj
mig codegen -d ./my-app
dotnet build ./my-app/my-app.fsproj
mig plan -d ./my-app
mig migrate -d ./my-app
mig status -d ./my-app
If you need to discard the current target database and restore the latest archived database back into the main database directory:
mig reset -d ./my-app
Runtime Use
Generated helpers execute inside dbTxn or txn transaction workflows.
open System.IO
open MigLib
open MigLib.MigProject
open MyApp.Db
let project =
MigProject.Mig.resolveFromGeneratedSchema dataDirectory None GeneratedSchema
|> fun task -> task.Result
|> Result.defaultWith (fun error -> failwithf "%A" error)
let db = dbTxn project.targetDbPath
let result =
db {
let! student = Student.SelectByNameOrInsert { Id = 0L; Name = "Alice"; Age = 21L }
let! matches = Student.SelectNameLike "li"
return student, matches
}
Example
example/ shows the full convention in a working project:
- runtime project at
example/example.fsproj - domain modeling project at
example/DomainModeling/DomainModeling.fsproj - generated
Db.fsatexample/DomainModeling/Db.fs - generated CRUD usage in
example/Program.fs - scripted
initandmigrateflows inexample/build.fsx
Run it with:
dotnet fsi example/build.fsx
Commands
mig codegen: generateDb.fsfrom the compiledDomainModelingproject andMigSchema.fssource filemig init: create the current schema-bound database when it does not exist yetmig plan: report inferred source/target paths plus supported and unsupported schema differencesmig migrate: create the target database, copy data, and archive the previous source databasemig status: show the current database path, archived databases, and whether a migration source is still presentmig reset: delete the current target database and restore the latest archived database into the main database directory
Specs
specs/database_dsl.mdspecs/mig_command.mdspecs/operator_runbook.mdspecs/custom_migration.mdspecs/web_result.md
Contributing
- Open an issue to discuss the change and approach.
- Add relevant tests.
- Open a pull request with the problem statement and solution summary.
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
- Fabulous.AST (>= 2.0.0-pre06)
- Fantomas.Core (>= 7.0.1)
- FSharp.Core (>= 10.0.104)
- Microsoft.Data.Sqlite (>= 9.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MigLib:
| Package | Downloads |
|---|---|
|
MigLib.Web
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 53 | 5/17/2026 |
| 7.0.2 | 120 | 4/14/2026 |
| 7.0.1 | 107 | 4/14/2026 |
| 7.0.0 | 105 | 4/11/2026 |
| 6.0.1 | 107 | 4/10/2026 |
| 6.0.0 | 105 | 4/10/2026 |
| 5.4.0 | 100 | 4/7/2026 |
| 5.3.0 | 100 | 4/7/2026 |
| 5.2.9 | 182 | 4/3/2026 |
| 5.2.8 | 105 | 4/3/2026 |
| 5.2.7 | 105 | 4/3/2026 |
| 5.2.6 | 113 | 4/2/2026 |
| 5.2.5 | 118 | 4/2/2026 |
| 5.2.4 | 105 | 4/2/2026 |
| 5.2.3 | 110 | 4/1/2026 |
| 5.2.2 | 127 | 3/31/2026 |
| 5.2.1 | 120 | 3/30/2026 |
| 5.2.0 | 110 | 3/30/2026 |
| 5.1.0 | 106 | 3/30/2026 |
| 5.0.1 | 121 | 3/29/2026 |
