Hello,
You do lose the possibility of auto-migration across the component
changes. I have not thought about it very hard, but I believe that is
mostly due to no one having writing code to handle this case yet. I
don't believe it is a fundamentally undoable thing.
You could use external migrators if you want. The solution I proposed
is really just an external migrator I believe?
Figuring out how to manage your migration history over large, long-
term projects is an area that could use more brain power. Happstack
provides the low-level functionality needed (though it is missing the
cross component migration), but effective policies and helpers for
making state migration easier are still needed. I know of 3 different
policies/systems, but none of them make me happy at the moment.
Back in the day, the checkpoint files were actually serialized as XML.
But that code has disappeared. If you use deriveNewData or deriveAll
so that all your State types are instances of Default and syb-with-
class then there are a few ways you could go about export XML or
JSON.
For XML you can use the existing toXml functionality:
{-# LANGUAGE DeriveDataTypeable, FlexibleInstances,
MultiParamTypeClasses, FlexibleContexts, TemplateHaskell,
UndecidableInstances #-}
module X where
import Happstack.Data
import Happstack.State
$(deriveAll [''Eq, ''Ord, ''Read, ''Show, ''Default]
[d|
data Foo = Foo X | Bar Int
data X = X String
|])
export :: Foo -> IO ()
export foo = putStrLn $ toString $ toXml foo
example output:
*X Control.Monad> export (Foo (X "hi"))
<foo haskellTypeVersion="0" haskellType="Foo"
><x haskellTypeVersion="0" haskellType="X"
><![CDATA[hi]]></x></foo>
*X Control.Monad>
Should be possible to implement a similar thing for JSON as well. You
would then just add something to your app which does an 'ask' on the
current state, and then calls export to save it.
The other option is to implement a new saver which saves the data as
XML instead of serialized byte strings. It would be similar to:
happstack/happstack-state/src/Happstack/State/Saver/Impl/File.hs
except that it would use XML instead of Binary.
Hope this gets you started! Thanks for your help!
- jeremy