Port to Flask-SQLAlchemy

This resolves a lot of issues around setting up the test DB and handling
multithreading in a much more sensible way.

While we're solving threading/concurrency issues, don't use RK as a
global.