DataVersion icon indicating copy to clipboard operation
DataVersion copied to clipboard

Go up/down non-destructively

Open flip111 opened this issue 1 year ago • 0 comments

Would it be possible to add to the library something like this

-- Simple version, up/down grade is blocked when there are losses
data Up
  = Up (a -> b)
  | UpLoss (a -> b) -- Don't care about the removed data

data Down
  = Down (b -> a)
  | DownLoss -- Operation is blocked, need to take a different database backup in that point of time

With matching functions

up :: 
upReversible :: -- no data loss. Return `Nothing` or some other error indication when `UpLoss` was encountered
down :: -- Can only run when there is no `DownLoss` in the chain

Or a more advanced version that produces data dump files of removed data (think patch files). JSON used in the example but the type can be polymorphic

data Up
  = Up (a -> b)
  | UpLoss (a -> (b, JSON)) -- Returns removed data

data Down
  = Down (b -> a)
  | DownLoss (b -> JSON -> a) -- Takes removed data (need to load this yourself from previously dumped patch file on disk)

flip111 avatar Mar 05 '24 14:03 flip111