-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version field doesn't work with inheritance #17
Comments
Another potential workaround that doesn't require changes: override the version number in the derived class, but call the appropriate migration methods from the parent class in the derived class migration method. Example: [Migratable("")]
public class ParentClass
{
public virtual int Version { get; } = 2;
protected static JObject Migrate_1(JObject data, JsonSerializer serializer)
{
// do migration
}
protected static JObject Migrate_2(JObject data, JsonSerializer serializer)
{
// do migration
}
}
[Migratable("")]
public class ChildClass : ParentClass
{
public virtual int Version { get; } = 3;
protected static JObject Migrate_1(JObject data, JsonSerializer serializer)
{
data = ParentClass.Migrate_1(data, serializer);
// do child class migration
}
protected static JObject Migrate_2(JObject data, JsonSerializer serializer)
{
// do child class migration that doesn't include up-revving parent class
}
protected static JObject Migrate_3(JObject data, JsonSerializer serializer)
{
data = ParentClass.Migrate_2(data, serializer);
// do child class migration
}
} If I'm thinking through this correctly:
|
@gregmeess hey mate, I rewrote this plugin and made it from 5 to 10 times faster: According to your recommendations I wrote test cases to be support inheritance without pain) Also you can check It has been a while since your comment but I hope you will find the time to check it ;) Don't hesitate to create an issue or PR! |
I'm trying to support migrations for a collection of classes that inherit from each other.
If a class with migrations inherits from another class with migrations, currently they both try and use the same version number. Unless I am missing something, it doesn't seem possible to have migrations for both a parent and child class.
Thinking about solutions, it seems like adding custom version name would allow a workaround where each class can specify a different version number.
The code would look as follows:
Corresponding JSON would have all version numbers:
The text was updated successfully, but these errors were encountered: