Perform upgrades and creation of database in transaction

If an error occurs during creation or update no change is commited to
the database. This allows us to re-try from the beginning the operation
next time. This will protect us in case of broken schema updates during
development and (hopefully never) when a broken update of the app is
distributed.