LiteDB.Migration 0.0.10

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

// Install LiteDB.Migration as a Cake Tool
#tool nuget:?package=LiteDB.Migration&version=0.0.10                

LiteDB.Migration

LiteDB.Migration is a lightweight, easy-to-use library designed to facilitate schema migrations for LiteDB databases in .NET applications. It provides a structured way to evolve your database schema over time, ensuring that your application can safely and efficiently migrate data as your models change.

Features

  • Flexible Migration Paths: Migrate data across multiple versions with ease.
  • Simple API: Define your migrations using a simple API.
  • Implicit and Explicit Migrations: Migrate all at once or in a Lazy way.

Getting Started

Installation

LiteDB.Migration is available as a NuGet package. You can install it via the NuGet Package Manager or the CLI:

dotnet add package LiteDB.Migration

Basic Usage

Get started by following the steps below. For a full example, see the Tests

  1. Define Your Models: Start by defining your document models. For each version change that requires a migration, prepare a new version of the model.
// Initial model
public class EntryModel
{
    public int Id { get; set; }
    public string OldProperty { get; set; }
}

// The latest version of the model, which is actively used in your app
public class CurrentModel
{
    public int Id { get; set; }
    public string NewestProperty { get; set; }
}
  1. Seed Data: Seed your database with the original model.
 // seed db
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var col = db.GetCollection<EntryModel>("ModelX");
    col.Insert(new EntryModel { Id = 1, OldProperty = "OldValue" });
}
  1. Define and apply Migrations: Define your migrations using the MigrationContainer class and apply them using the MigrationContainer class.<br/> Whenever you want to change the model, you can define a new migration using the WithMigration method.
 // apply migration
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var container = new MigrationContainer(migConfig =>
    {
        migConfig.Collection<CurrentModel>("ModelX", config => config
            .StartWithModel<EntryModel>()
            .WithMigration(x => new
            {
                x.Id,
                NewProperty = "New-" + x.OldProperty
            })
            .WithMigration(x => new
            {
                x.Id,
                NewestProperty = "New-" + x.NewProperty
            })
        );
    });

    container.Apply(db);
}
  1. Query Data: Query your database using the new model.
// verify migration
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var col = db.GetCollection<CurrentModel>("ModelX");
    var model = col.FindById(1);

    Console.WriteLine($"Id: {model.Id}, NewestProperty: {model.NewestProperty}");
    if (model.Id != 1 || model.NewestProperty != "New-New-OldValue")
    {
        throw new Exception("Migration failed");
    }
    else
    {
        Console.WriteLine("Migration succeeded");
    }
}

Advanced Usage

For larger (enterprise) applications, you may want to use a more structured approach to migrations. In this case, you can use the please see the Full Example (Wiki page coming soon).

Contributing

Contributions are welcome! Feel free to submit

  • pull requests
  • report issues
  • feature requests

If you are motivated to create something like dotnet-ef cli tool, feel free to do so and submit a pull request 😃

License

LiteDB.Migration is released under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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)
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
0.0.10 1,830 2/26/2024
0.0.9 224 2/20/2024
0.0.8 236 2/20/2024
0.0.7 308 2/20/2024
0.0.6 240 2/20/2024
0.0.5 236 2/20/2024
0.0.4 211 2/19/2024
0.0.3 218 2/19/2024
0.0.2 230 2/19/2024
0.0.1 240 2/16/2024