happs-tutorial-0.8: src/migrationexample/README
== The following is a demo of HAppS migrations
In this directory you'll find the following files:
-- StateVersions/AppState1.hs
Our first state. Fairly basic.
-- StateVersions/AppState2.hs
The next iteration, moving from a lookup list to a Map, containing the code
for the migration and the reference to the previous version.
-- StateVersions.AppState3.hs
The next iteration, adding a Header field.
-- CreateState1.hs
Run the 'main' function of this file to create the state in the first
format (State1). This will also create a checkpoint.
-- MigrateToState2.hs
Run this to test the migration. The old version of HAppS will return the
inital state (empty map), not loading the old checkpoint. Using a patched
version will give you the data created with CreateState1, but now as a Map.
Note that if we hadn't created the checkpoint, it would have worked out
fine, since we would replay the 'InsertPage' action, but now for the new
state. In the long run, you'll likely to want to use checkpoints, rename
event functions, etc, so this is not a feasable approach.
-- MigrateToState3.hs
Do the third migration, which adds a Header field.
The demo is as follows:
$ runghc CreateState1.hs
[("index",Page {title = Title "Home3 ", body = Body "hello, world 3"}),("index",Page {title = Title "Home 2", body = Body "hello, world 2"}),("index",Page {title = Title "Home", body = Body "hello, world"})]
$ runghc MigrateToState2.hs
fromList [("index",Page {title = Title "Home", body = Body "hello, world"}),("index2",Page {title = Title "Home 2", body = Body "hello, world 2"}),("index3",Page {title = Title "Home 3", body = Body "hello, world 3"}),("index4",Page {title = Title "Home 4", body = Body "hello, world 4"})]
$ runghc MigrateToState3.hs
fromList [("index",Page (Title "Home") (Header "") (Body "hello, world")),("index2",Page (Title "Home 2") (Header "") (Body "hello, world 2")),("index3",Page (Title "Home 3") (Header "") (Body "hello, world 3")),("index4",Page (Title "Home 4") (Header "") (Body "hello, world 4")),("index5",Page (Title "Home 5") (Header "Header5") (Body "hello, world 5")),("index6",Page (Title "Home 6") (Header "Header5") (Body "hello, world 6"))]
Of course, for this to run, you need to have HAppS installed.
This migration demo is included as part of the happstutorial distribution, which is cabal installable.
With happstutorial installed, you should be able to run the migration demo too.