realm / realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
https://realm.io
293 stars 42 forks source link

Migrating from 1.x to 2.0 with shared root realms #303

Closed gogoalsoft closed 6 years ago

gogoalsoft commented 6 years ago

Goals

I have a working Realm 1.x deployment. Each user has their own realm, plus access to a few shared "root" realms (not associated with any user, read only to most users except a few admins, resides in original root user_data directory). I have a custom auth setup with FB account kit. This works on a 1.x server.

Trying to migrate to 2.0.

Used the ros migrate command with --copyrealms, which seems to copy the user realms, but not the root realms. Server starts without the (important) root realms.

Start over again, this time I copied the root realms manually to the new user_data directory after the migration is done, then started the server. I got the following error:

info: [sync] Migrating racingRealm.realm (10/10) info: [http] 119.247.19.139 - POST /auth HTTP/1.1 404 144 - 0.265 ms info: [sync] Migration completed successfully info: [sync] Realm sync server started ([realm-core-4.0.2], [realm-sync-2.1.0]) info: [sync] Directory holding persistent state: /var/lib/realm-new/sync/user_data info: [sync] Operating mode: master_with_no_slave info: [sync] Listening on 127.0.0.1:33967 (sync protocol version 22) error: [sync] ServerFile[/__admin]: Bad changeset received: Schema mismatch: 'RealmFile' has primary key 'path' on one side,but primary key 'id' on the other. (message_type='upload') error: Open error for realm at /__admin: [object Object] Bad changeset (DOWNLOAD)

Subsequent starting gives me the last bad changeset error.

What am I doing wrong here? There was no error on the first migration (without the root realms).

On a side note, I suppose I need to rewrite my custom auth module for it to work with ROS 2.0?

kvap commented 6 years ago

@gogoalsoft thanks for reporting this. Indeed, the migration command does not copy non-user realms, we are working on fixing that.

Schema mismatch: 'RealmFile' has primary key 'path' on one side,but primary key 'id' on the other.

You probably copied the __admin.realm along with other non-user realms. The migration tool transforms it in a special way. It will not work if you just copy it from the old ROS. There are other special system realms like that (basically, everything starting with double underscore).

gogoalsoft commented 6 years ago

Thanks for your reply. I removed the whole directory and tried again.

Copied the realms after the migration, and before starting the server.

Server starts, and migrates the realms successfully as shown on the screen.

I start up Realm Studio, connects fine to my server, but the non-user realms are not shown.

What gives? How do I get them back?

kvap commented 6 years ago

That is caused by the fact that the migration tool does not copy the metadata about those realms. So, from the point of view of ROS, they do not exist, until someone opens them. When a user connects, the metadata will get created and the user will own the realm (which is not what you want). So, as a quick workaround until we release the fix, if there is not very many of those, open them using the admin token (as when you created the realms) and grant permissions.

kvap commented 6 years ago

Copying global realms is now supported by the migration tool in 2.0.17.