Add basic realm migration support

This commit is contained in:
Dean Herbert 2021-01-07 15:41:29 +09:00
parent 5d7ab4a7f1
commit ae76eca564
1 changed files with 14 additions and 1 deletions

View File

@ -43,6 +43,15 @@ public RealmContextFactory(Storage storage, Scheduler scheduler)
this.storage = storage;
this.scheduler = scheduler;
recreateThreadContexts();
using (CreateContext())
{
// ensure our schema is up-to-date and migrated.
}
}
private void onMigration(Migration migration, ulong oldschemaversion)
{
}
private static readonly GlobalStatistic<int> reads = GlobalStatistics.Get<int>("Realm", "Get (Read)");
@ -158,7 +167,11 @@ private void recreateThreadContexts()
protected virtual Realm CreateContext()
{
contexts.Value++;
return Realm.GetInstance(new RealmConfiguration(storage.GetFullPath($"{database_name}.realm", true)));
return Realm.GetInstance(new RealmConfiguration(storage.GetFullPath($"{database_name}.realm", true))
{
SchemaVersion = 2,
MigrationCallback = onMigration
});
}
public void ResetDatabase()