After some time, you may want to begin tracking how long each Ticket takes so that you can better plan future work. Let’s add a new field to track that. Note that in addition to adding the field to the model itself, we also have to register the new field so that you can continue to read data written with the old schema:
With enough tickets, you’ll probably want to be able to search quickly and to do some server-side analytics. Let’s update the model to support queries by team and done and aggregations on hoursWorked:
After making changes to indexes or projections, you must update the persisted data in TwiceDB itself. This is not necessary to add or remove fields that are neither indexed nor projected.
it:=NewTicketIterator(
client,
shared.BatchSize(100),
client.Lsqt().Tt())
for {
hn, _:=it.HasNext()
if !hn {
break
}
ticket, _:=it.Next()
_, _ = ticket.ReindexObject(client)
}
It’s not necessary to lock Ticket while reindexing, but queries on indexes and projections will return incomplete results until all Tickets originally written with the old schema have been reindexed. Tickets written for the first time with the new indexes and projections do not need to be reindexed. However, since reindexing is idempotent, the data will remain consistent even if you do reindex them.