LiteDB.Migration
0.0.6
See the version list below for details.
dotnet add package LiteDB.Migration --version 0.0.6
NuGet\Install-Package LiteDB.Migration -Version 0.0.6
<PackageReference Include="LiteDB.Migration" Version="0.0.6" />
paket add LiteDB.Migration --version 0.0.6
#r "nuget: LiteDB.Migration, 0.0.6"
// Install LiteDB.Migration as a Cake Addin #addin nuget:?package=LiteDB.Migration&version=0.0.6 // Install LiteDB.Migration as a Cake Tool #tool nuget:?package=LiteDB.Migration&version=0.0.6
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
- 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; }
}
- 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}"
};
}
}
- 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())
};
}
- 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 | Versions 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. |
-
.NETStandard 1.3
- LiteDB (>= 5.0.7)
- NETStandard.Library (>= 1.6.1)
-
net5.0
- LiteDB (>= 5.0.7)
-
net6.0
- LiteDB (>= 5.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.