Make Stacks the owners of their own DB representation
Change the way that Stack objects are initialised, so that they know how to
load and store themselves in the database (they were already updating their
own data, but the actual creation was being done externally). This
consolidates a lot of existing Stack database creation code (in the
manager, nested stacks and unit tests) into one place.
Also, split the template and parameter handling out into separate classes,
and pass these through the constructor for easier testing.