LiteDB.Migration 0.0.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package LiteDB.Migration --version 0.0.7                
NuGet\Install-Package LiteDB.Migration -Version 0.0.7                
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.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteDB.Migration --version 0.0.7                
#r "nuget: LiteDB.Migration, 0.0.7"                
#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.7

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

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.
// Original model
public class ModelV1
{
    public int Id { get; set; }
    public string OldProperty { get; set; }
}

// Updated model
public class ModelV2
{
    public int Id { get; set; }
    public string NewProperty { get; set; }
}
  1. Implement Migrations: Create a migration class for each model transformation. Inherit from MigrationBase<TFrom, TTo> and implement the migration logic.
public class ModelV1_to_ModelV2_Mapper : MigrationBase<ModelV1, ModelV2>
{
    public override int? From => 1; // Original version
    public override int To => 2;   // New version

    public override ModelV2 Migrate(ModelV1 model)
    {
        return new ModelV2
        {
            Id = model.Id,
            NewProperty = $"New-{model.OldProperty}"
        };
    }
}
  1. Create a Migration Set: Create a migration set to group your migrations together. Implement the IMigrationSet interface and return a list of your migrations.
public class MigrationSet_1_to_2 : IMigrationSet
{
    public MigrationSetItem[] Items => new[]
    {
        // ModelV2 is the marker class, The Mapper will be used to migrate Model to ModelV2
        new MigrationSetItem(nameof(ModelV2), new ModelX_to_ModelY_Mapper())
    };
}
  1. Configure and Apply Migrations: Use the MigrationContainer to configure and apply your migrations.
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var container = new MigrationContainer(config =>
    {
        config.WithSet<YourMigrationSet>();
        
        // The generic type is the type of the marker class
        config.Collection<ModelV2>("YourCollectionName");
    });

    container.Apply(db);
}

Contributing

Contributions are welcome! Feel free to submit pull requests, report issues, or suggest new features.

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,771 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