objectbox/objectbox-generator

Deleting an entity from an existing model

vaind opened this issue · 1 comments

vaind commented

When an entity definition is removed (e.g. from a .go file, or the .go file defining an entity is removed altogether), the user might want to delete the entity from the model. Currently, the generator doesn't recognize this situation because it's executed for each individual input file, combining all of them into the same model - therefore it doesn't distinguish between missing entities and the ones that haven't been processed yet.

There are a couple of ways to approach this, the simplest would probably be adding a new CLI argument/action, sth. like --remove=EntityName. Alternatively, we could change the way the generator is launched so that it has the complete list of files to include in the model.

vaind commented

The current workaround, if someone really really wants to remove the entity from the model, is to manually update the objectbox-model.json, removing the entity JSON code block defining it and adding its uid to the retiredEntityUids list to avoid reuse of the same UID (which would break things). Additionally, the same has to be done for the removed properties, indexes, and relations (each has its retired*Uids list). After the generator is re-run, the entity would be removed from the objectbox-model.go.

I don't recommend doing this as it's easy to make an error when manually editing the model JSON file, potentially causing a loss of data. If you can, wait for the generator to support the removal.