objectbox

Objectbox-go: deleting model class


Unfortunately, ObjectBox Go's docs provide no information about deletion of entire type structure "powered" by ObjectBox.

Let's say we have a struct

//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen

type Test struct {
    Id            uint64
    Name          string
}

After some time, I decide remove entire Test from the project (deleted test.go and test.obx.go). Unfortunately, go generate still "remembers" this phantom class and keeps adding it to objectbox-model.go

model.RegisterBinding(TestBinding)

How can I safely delete this struct (and its data)?


Solution

  • Update: this is outdated information. The ObjectBox code generator now supports this automatically.

    Currently, the ObjectBox code generator doesn't delete entities because it works with partial input information (a single file at a time) and therefore it doesn't know whether you have removed an entity or it will be in the next file the generator is called for.

    I've created a follow-up issue/feature request on GH: https://github.com/objectbox/objectbox-generator/issues/22

    If you really needed to remove the entity NOW, until the removal feature is added to the generator: the current workaround, would be 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.