Groom migration scripts.

### Motivation
Fix issue #956. Jump on the ocassion and do some general cleanup and testing.

### Changelog
* Use context managers aggressively.
* Install a `main` function in every script.
* Process `sys.argv` through `argparse` (by @lolosk). Test the parser.
* Include `db` package in coverage testing.
* Fix the `update_db` shell script to work with the new argument format.

@lolosk: Please review. If you like to do some of the `TODO` work, do a PR on my PR.