Move intial setup into middleware file

This will get loaded earlier than models for WSGI workers. In particular it
will not be loaded between a request starting and finishing.