LiteDB.Migration 0.0.8

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

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

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; }
}

// Current model (Should always be ModelV[n])
public class Model
{
    public int Id { get; set; }
    public string NewProperty { get; set; }
}
  1. Seed Data: Seed your database with the original model.
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var collection = db.GetCollection<ModelV1>("YourCollectionName");
    collection.Insert(new ModelV1 { Id = 1, OldProperty = "Old" });
}
  1. Define and apply Migrations: Define your migrations using the MigrationContainer class and apply them using the MigrationContainer class.
 // apply migration
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var container = new MigrationContainer(config =>
    {
        config.Collection<Model>("modelA", x => x
            .WithMigrationStart<ModelV1>()
            .WithInlineMigration(model => new ModelV2
            {
                Id = model.Id,
                NewProperty = $"New-{model.OldProperty}"
            })
            // You can add more migrations here
        );
    });

    container.Apply(db);
}
  1. Query Data: Query your database using the new model.
using (var db = new LiteDatabase("YourDatabase.db"))
{
    var collection = db.GetCollection<Model>("modelA");
    var result = collection.FindAll().First();
    Console.WriteLine(result.NewProperty); // Output: New-Old
}

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