realm / realm-browser-osx

DEPRECATED - Realm Browser for Mac OS X has been replaced by realm-studio which is cross platform.
https://realm.io
503 stars 54 forks source link

Create Realm based on schema #306

Open astigsen opened 7 years ago

astigsen commented 7 years ago

It would be super useful if you could optimally specify a schema when opening a Realm (local or remote), and realm either opened with the new schema (possibly changing the existing schema) or if it did not already exist, a new realm created with the given schema.

The schema could be defined in the js JSON format.

TimOliver commented 7 years ago

I've been wondering about this for a long time. Being able to create Realm files from scratch in the Browser would be a huge step in making Realm like SQLite in being able to ship pre-built database files.

The thing that's been holding me back is that it feels like it would be a really weird user experience if users could create a Realm initially in the Browser, but then couldn't change the schema; not without deleting the Realm and recreating it. If the goal is to be able for users to craft a Realm file with precompiled data, it would be extremely irritating to have to create a new Realm from scratch when iterating over the schema.

In one of our prior app proofs-of-concepts, we 'solved' this problem by creating a duplicate Realm with the new schema, copying the data across from the old Realm and then overwriting the old Realm with the new Realm.

But I wonder if there's an easier way. Even if it's as simple as performing a Realm migration and then resetting the schema version back to 0.

astigsen commented 7 years ago

It would be preferable if you could dynamically change the schema in the browser, but until that is supported, you could solve the problem by being able to (re)open the realm with new schema (thus forcing a migration).