Migratable 2.2.0

dotnet add package Migratable --version 2.2.0
NuGet\Install-Package Migratable -Version 2.2.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="Migratable" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Migratable --version 2.2.0
#r "nuget: Migratable, 2.2.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.
// Install Migratable as a Cake Addin
#addin nuget:?package=Migratable&version=2.2.0

// Install Migratable as a Cake Tool
#tool nuget:?package=Migratable&version=2.2.0


Simple, efficient, and tested DotNet Core database migrations supporting multiple database technologies.

  • Create a completely new database by running all your migrations in one go
  • Easily bring an existing database structure up to date
  • Roll your database structure backwards as well as forwards
  • Use it to pre-populate, amend, or remove data
  • Your database structure is version-controlled
  • Migrations are defined as up and down SQL files in a folder
  • Migrations are run in transactions for atomic up/down


Available on nuget:

Using Migratable

Migratable is a versioned database migration manager. In order to do anything, it requires a provider for your chosen database system. Postgres and MySQL/MariaDB are already available. Implementing your own is straightforward, being just a single interface.

There is also an Example project which is totally self-contained as it uses an in-memory provider.

Sample usage

// Configure.
var provider = new SampleProvider();
var migrator = new Migratable.Migrator(provider);

// Confirm the connection.
Console.Write("Press enter/return to continue (or Ctrl+C) ... ");

// Migrate from the current version to version 5.
Console.WriteLine($"Old version: {migrator.GetVersion()}");
Console.WriteLine($"New version: {migrator.GetVersion()}");

The Describe() method is designed to give confidence in proceeding. For MySQL/MariaDB, for example, it shows the server and database name. The code above passes in the folder ./migrations to LoadMigrations. That folder should contain something like:

    \001 Create accounts
    \002 Populate accounts

The folder name starts with the version sequence and is followed by the description. Inside each folder, the up.sql file would contain the SQL needed to progress to that version. The down.sql file would contain the SQL needed to drop down from this version to the one below.

You must start at version one and you cannot omit a version in the sequence. You may also not have duplicate version numbers.

How it works

There are 2 components, with an optional third:

  • Migrator - what your code should interact with to load/perform migrations
  • Provider - a utility package to support a particular database technology
  • Notifier - an optional class that can be sent progress messages

You follow this process:

  • Create a Provider instance for your database
  • Create a Migrator and pass in your Provider
  • Optionally create a Notifier and pass that to the Migrator
  • Ask your Migrator to load your migrations
  • Ask your Migrator to manage your current version

That final stage will result in your up/down SQL statements being issued as needed to transition from your current database version to your target one.

By default, this is supported by an automatically created/updated MigratableVersion table. It does, however, depend on the particular Provider.

Note about MySQL

MySQL has a habit of silently committing structural changes (add column, create table etc) mid-transaction. You should therefore avoid using multiple statements in a single migration if any one of them is structural. If you do, and one of the other statements fail, the transaction rollback will fail to undo a structural change that is already applied.

For developers working on Migratable itself

If you only intend making use of Migratable in your own projects read no further.

Running the tests

cd Migratable.Tests
dotnet test

Creating a new version for Nuget

The Migratable/Migratable.csproj file contains Nuget settings. Within that file, update the version number then create the Nuget package:

cd Migratable
dotnet build
dotnet pack -c Release

Forcing another project to get the latest from Nuget

It sometimes takes a while for a new version to be available after pushing. You may be able to speed up the process:

cd <other-project>
dotnet restore --no-cache

MIT Licence

Copyright (c) 2019 K Cartlidge. See the included LICENCE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Migratable:

Package Downloads

Database provider for kcartlidge/migratable adding support for MySql/MariaDB


Database provider for kcartlidge/migratable adding support for Postgres

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 563 1/27/2023
2.1.0 1,111 2/1/2019
1.2.0 1,278 5/24/2018