cmelchior / realmfieldnameshelper

Realm extension library used to create more type-safe queries.
Apache License 2.0
173 stars 21 forks source link

Add class name #27

Closed mgohin closed 6 years ago

mgohin commented 7 years ago

For migration we need to use the class name and not the .class as explained here : Realm migration

if (oldVersion == 0) {
        schema.create("Person")
            .addField("name", String.class)
            .addField("age", int.class);
        oldVersion++;
     }

Can you add a field like you do for lists with the $ to avoid errors when user the class name as a plain string in code ?

mgohin commented 7 years ago

I'm migrating all my current code to use your lib, could be very nice to add this feat, I guess it's not that complicated.

cmelchior commented 6 years ago

Using a constant that changes for a name used in Migrations are a very bad idea. If you ever rename that class, your migrations might stop working.

E.g

if (oldVersion == 0) {
  // Create Foo
  oldVersion++;
}

if (oldVersion == 1) {
  // Rename to Bar
  oldVersion++;
}

if(oldVersion == 2) {
  // Rename to Baz
  // If anyone ever upgrades directly from V1 to V3, the step in V2 will break with a generated 
  // constant name
  oldVersion++;
}

For that reason, adding the class name doesn't make a lot of sense, especially since any name for it could potentially clash with a field name.

mgohin commented 6 years ago

It's same for fields, when you rename/delete a field you have to update the migration.