biobricks / bionet-2

The bionet web app
3 stars 2 forks source link

Undelete API #167

Closed Juul closed 6 years ago

Juul commented 6 years ago

All deleted materials (physicals or virtuals) should be copied to a sublevel before deletion. This should be done as a batch so it stays atomic. The key in this "list of deleted materials" sublevel should be datetime, sorted by newest first.

New API functions:

This sublevel should auto-delete anything older than 30 days.

Restore material should copy the material back to the normal sublevel from whence it was deleted and remove the entry from the list of deleted items. Again as an atomic batch operation.

Juul commented 6 years ago

Undeletion API is implemented but untested. I'm working on #182 and will then implement tests for this.

How it works

Anything deleted with delPhysical is automatically saved in a separate database before deletion.

There are three new calls: listDeleted, clearDeleted and undelete.

listDeleted(); // returns a stream of all deleted (keys and values)

listDeleted streams items like this:

{
  key: myKey // key used to undelete
  value: {
    db: dbName, // name of database from which the item was deleted, e.g. "physical"
    key: someKey, // full key, should not be used by client
    deletedAt: someTime, // deletion time in microseconds since unix epoch
    deletedBy: email, // email address of user that deleted this
    data: { ... } // the actual deleted object
  }
}
clearDeleted(callback); // permanently delete the deleted items (empty recycle bin)
undelete(key, callback); // undelete the item and remove it from the list of deleted items
Juul commented 6 years ago

Tested and working as of 3fed7df0b216557e4dfec28b99301c9d1b0fcb04