context: I have an app for both iOS and Android; where the iOS version is native and the Android version is in React-Native. I started with two individual object schemes, but now I want to modify the Android (React-Native) scheme so that all entities are equal to my iOS version. I want to do this so I can easily exchange database files while testing, and because I want to implement cross-platform cloud sync.
What's happening
Say I have these two entities:
static schema: Realm.ObjectSchema = {
name: 'DBGame',
primaryKey: 'id',
properties: {
id: 'string',
players: 'DBPlayer[]',
},
};
static schema: Realm.ObjectSchema = {
name: 'DBPlayer',
primaryKey: 'id',
properties: {
id: 'string',
games: {type: 'linkingObjects', objectType: 'DBGame', property: 'players'},
},
};
If I want to rename these entities from DBGame & DBPlayer to RSGame and RSPlayer, I would:
- up my schema version number
- add a migration function when opening the realm
.. and then what? When I rename the schema names, Realm will fail to open at all since it can't find a table with the new schema names (which makes sense, because they're not migrated yet).
Question Right now it seems like the only way to rename Realm tables in JS is to just create new schema's besides the old ones and keep them all alive until ALL USERS have migrated. However, this seems ugly and hacky.
What is the proper way to rename tables/entities in Realm JS / Realm React-Native?
A couple of things:
Realm Migrations do not apply to Realm Sync - they are for local only Realms.
At the moment, the process for Realm Sync is to update your code, delete all local data and allow Realm Sync to re-download all of the data.
The other thing is that Realm has no tables - Realm is an Object database, not SQL. There are only objects, so once your local data is deleted and Objects updated, you are all set.