SQL alchemy file structure

partial solutions to #4163

Merge this into the sql branch so we can start incorporating bug fixes into the new file structure of ``sql.py`` / ``sql_legacy.py``.