import StateVersions.AppState1
import Happstack.State
import System.Environment
   
entryPoint :: Proxy AppState
entryPoint = Proxy

{- First, we're using withProgName "migration-demo" with both CreateState1 and MigrateState2
   in order to make sure that both executables are looking at the same state
   under _local.

   Second, in this example we're using the state
   contained in AppState1, which is just
   AppState Int, and we increment it before creating
   our checkpoint.

   Why create a checkpoint?  Well that goes to something
   fairly important about how migrations work.  If you
   _don't_ create a checkpoint, then when you start
   MigrateState2.hs it will attempt to replay back the
   set of events recorded in _local and it won't be able
   to handle them because the actual state module, and thus
   namespace, has changed.  Instead, we need to create
   a checkpoint and serialize the actual state itself
   rather than the events.  The Migrate instance will
   then handle the rest.
-}

main :: IO ()
main = withProgName "migration-demo" $ do
  control <- startSystemState entryPoint
  update IncVal
  query AskVal >>= print
  createCheckpoint control
  shutdownSystem control

