I need to add a @PrimaryKey
to two Realm models that are missing it due to idiocy. The models are referenced in multiple other models via direct relationships or RealmLists, one of both models also references the other model.
My first thought was to rename the schemas in a migration and copy over the data by hand, but then Realm complains that the schema is linked in other schemas and can't be renamed.
Both schemas contain around 15000 objects that can be condensed to about 100, they are absolutely identical and have been duplicated due to the missing @PrimaryKey
.
The models themselves are kinda simple:
class ModelA extends RealmObject {
String primaryKey; // Is missing the @PrimaryKey annotation
String someField;
String someOtherField;
Date someDate;
ModelB relationToTheOtherProblematicModel;
}
class ModelB extends RealmObject {
String primaryKey; // Is also missing the @PrimaryKey annotation
// this class only contains String fields and one Date field
}
How can I migrate the data when I add @PrimaryKey
to both classes' primaryKey
field?
Edit to clarify:
Both schemas contain multiple completely identical items.
primaryKey | someField | someOtherField
------ | ------ | ------
A | foo | bar
A | foo | bar
A | foo | bar
A | foo | bar
B | bar | foo
B | bar | foo
B | bar | foo
C | far | boo
C | far | boo
C | far | boo
These duplicates can be removed since primaryKey uniquely identifies them. When I add the @PrimaryKey annotation and do a migration Realm obviously complains about the duplicate values. I need to remove those duplicates without destroying the links in other models.