I added a new attribute to Go struct, persisted in a datastore entity kind.
I tried to load entities using a filter on the new attribute:
q := datastore.NewQuery("Person").Filter("Employed =", false)
This only worked as intended for persons created after the new attribute was added.
I had expected persons created before the attribute was added to be incleded in the filter, but they didnt have the attribute at all, so they were be excluded by the filter.
I have thought of two ways to handle this:
- First load all entities and filter in a second step with a loop. This adds complexity to the code.
- Batch load and resave all entities, which adds the property and sets it to false. I have to remember to do this every time I add a new attribute.
Is there a batter way to handle these types of entity schema changes?