Refactor database initialization

Also, bring back debug-server.py's --debug flag, so that it's possible
to run Flask's server in non-debug mode.