More SQL backend stuff, i'll push more later but perhaps somebody is bored and wants to review code

although now that I'm reworking exit code checking I'm starting to wonder if we even need the local db
cascade*