Replies: 4 comments 9 replies
-
Hi @softlion, If you are just migrating to Regarding strings:
Would it possible for you to post here some of the classes before/after? So that we can take a look and understand what is happening. |
Beta Was this translation helpful? Give feedback.
-
Ok, I see your point. I think that the issue here is that in the previous schema you had How are you checking that there is no more data in the table? |
Beta Was this translation helpful? Give feedback.
-
Here the unit test using xUnit. [Fact]
public async Task TestMigrateUserInfo()
{
var path = Path.GetTempFileName();
try
{
{
using var oldDb = Realm.GetInstance(new RealmConfiguration(path)
{
SchemaVersion = 1,
Schema = new RealmSchema.Builder().Add(typeof(OldDbUserInfo))
});
oldDb.Error += (sender, args) => output.WriteLine(args.Exception.ToLongString());
oldDb.Write(() => { oldDb.Add(new OldDbUserInfo { Login = "[email protected]", Authorization = "ok" }); });
var allItems = oldDb.All<OldDbUserInfo>().ToList();
Assert.Single(allItems);
Assert.Equal("[email protected]", allItems[0].Login);
Assert.Equal("ok", allItems[0].Authorization);
}
using var db = Realm.GetInstance(new RealmConfiguration(path)
{
SchemaVersion = 2,
Schema = new RealmSchema.Builder().Add(typeof(DbUserInfo)),
MigrationCallback = (migration, version) =>
{
//var allItems = migration.OldRealm.All<DbUserInfo>().ToList(); //Unable to get OldDbUserInfo nor DbUserInfo
var newItems = migration.NewRealm.All<DbUserInfo>().ToList();
var i = 0;
}
});
output.WriteLine("waiting initial notification");
}
finally
{
if(File.Exists(path))
File.Delete(path);
}
} [MapTo("DbUserInfo")]
public class OldDbUserInfo : RealmObject
{
public string Login { get; set; }
public string Authorization { get; set; }
}
public class DbUserInfo : IRealmObject
{
public string Login { get; set; }
public string? Authorization { get; set; }
} |
Beta Was this translation helpful? Give feedback.
-
The reason why it's nulla it's because it goes from being nullable to non-nullable, so we can't really say what should happen if you have a null string in one of your objects, for instance. Regarding iOS, you can actually use dynamic, but you can't do any kind of code generation (that are not doing behind the scenes), so you should be fine. |
Beta Was this translation helpful? Give feedback.
-
Hello, I switched to IRealmObject in an existing app that was using RealmObject.
When I run the app, it triggers a migration.
It looks like it's loosing everything.
I switched some fields from "string" to "string?" after migrating to IRealmObject.
What is the correct way to migrate, keep the old object definition using RealmObject and use it to read from old realm and transfer to the new during the migration ?
Beta Was this translation helpful? Give feedback.
All reactions