LiteDB.Migration
0.0.9
See the version list below for details.
dotnet add package LiteDB.Migration --version 0.0.9
NuGet\Install-Package LiteDB.Migration -Version 0.0.9
<PackageReference Include="LiteDB.Migration" Version="0.0.9" />
paket add LiteDB.Migration --version 0.0.9
#r "nuget: LiteDB.Migration, 0.0.9"
// Install LiteDB.Migration as a Cake Addin #addin nuget:?package=LiteDB.Migration&version=0.0.9 // Install LiteDB.Migration as a Cake Tool #tool nuget:?package=LiteDB.Migration&version=0.0.9
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; }
}
// Current model (Should always be ModelV[n])
public class Model
{
public int Id { get; set; }
public string NewProperty { get; set; }
}
- 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" });
}
- Define and apply Migrations: Define your migrations using the
MigrationContainer
class and apply them using theMigrationContainer
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);
}
- 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 | 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.