Skip to content

Automatic handling of backlinks when migrating to EmbeddedObject #4729

@DominicFrei

Description

@DominicFrei

Summary

Migrating a table from non-embedded to embedded is not really easy and obvious in the user-facing SDKs.
This could be improved by automating the main problems and making the migration easier for the user.

Motivation

When migrating a table from non-embedded to embedded users do struggle to get it right because they have to deal with two cases:

The struggle itself has two reasons:

While allowing the latter for the special case of migration would partial solve this, I'd like to propose the following changes to solve all those problems at once.

Goals

When applying the post migration changes we ensure the following during https://github.com/realm/realm-core/blob/master/src/realm/object-store/object_store.cpp#L832:

  • Objects with too many backlinks get duplicated and assigned one to each backlink so that we automatically end up with objects with only one backlink.
  • Orphaned objects will be deleted. This will only happen when a flag is explicitly set to make sure users consciously confirm that data should be deleted.

User-facing API

  • Adding a new option deleteOrphanedObjects to the migration, type bool. In the SDKs this would probably make most sense in RealmConfiguration since the MigrationBlock and the DeleteFilesOnMigration flag already live there. In Core this might probably be best situated in ObjectSchema next to IsEmbedded itself.
  • Default would be false so that it does not influence any existing migrations.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions