preupgrade hook
mafintosh opened this issue · comments
Mathias Buus commented
I think we need a "preupgrade" hook that, if set, runs when the user calls update, allowing them to ensure certain conditions around the upgrade. this would just be a view, like non-sparse mode (infact non-sparse could be implemented as a hook).
For example:
const s = core.session({
preupgrade (latest) { // where latest is a session that is on the latest length
await latest.get(latest.length - 1) // always ensure the latest block is there
return latest.length // can optionally return the length we're upgraded to
}
})
// calls above
await s.update()
We might wanna allow simple naming of the hooks also so users can define a couple, but let's defer that to after we have one working. The pointer a preupgrade session is on should also be stored in the oplog, so we can checkout the current existing one on restart