MigLib.Web 8.0.0

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

logo

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

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:

  1. Keep the runtime project in the working directory.
  2. Keep the domain modeling project at DomainModeling/DomainModeling.fsproj.
  3. Keep the schema source at DomainModeling/MigSchema.fs.
  4. Run mig codegen from the runtime project directory.
  5. Let mig codegen write Db.fs into the domain modeling directory.
  6. 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.Insert
  • Student.InsertOrIgnore
  • Student.SelectById
  • Student.SelectAll
  • Student.SelectByName
  • Student.SelectNameLike
  • Student.SelectByNameOrInsert
  • Student.Upsert

Installation

Install the CLI as a global tool:

dotnet tool install --global migtool

For library usage:

  • install MigLib for schema attributes, generated CRUD support, transactions, and migration workflows
  • install MigLib.Web when you also want the ASP.NET Core webResult helpers

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.fs at example/DomainModeling/Db.fs
  • generated CRUD usage in example/Program.fs
  • scripted init and migrate flows in example/build.fsx

Run it with:

dotnet fsi example/build.fsx

Commands

  • mig codegen: generate Db.fs from the compiled DomainModeling project and MigSchema.fs source file
  • mig init: create the current schema-bound database when it does not exist yet
  • mig plan: report inferred source/target paths plus supported and unsupported schema differences
  • mig migrate: create the target database, copy data, and archive the previous source database
  • mig status: show the current database path, archived databases, and whether a migration source is still present
  • mig reset: delete the current target database and restore the latest archived database into the main database directory

Specs

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

Apache 2.0

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

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
8.0.0 68 5/17/2026
7.0.2 98 4/14/2026
7.0.1 102 4/14/2026
7.0.0 102 4/11/2026
6.0.1 99 4/10/2026
6.0.0 94 4/10/2026
5.4.0 91 4/7/2026
5.3.0 90 4/7/2026
5.2.9 160 4/3/2026
5.2.8 94 4/3/2026
5.2.7 96 4/3/2026
5.2.6 102 4/2/2026
5.2.5 105 4/2/2026
5.2.4 97 4/2/2026
5.2.3 104 4/1/2026
5.2.2 114 3/31/2026
5.2.1 106 3/30/2026
5.2.0 97 3/30/2026
5.1.0 101 3/30/2026
5.0.1 115 3/29/2026
Loading failed