Patch for checking and initializing alembic environment

Move the alembic check and initialize if not exists to function, clean up.

Checked build passing:
https://travis-ci.org/qoelet/dagobah/jobs/16941565