setup improvements

major goal was to be able to setup database schema to empty database without needing to sort out files in setup dir and in patches dir
secondary goal was to get rid of ext/mysql and use already existing db abstraction layer

i've made changes microscopic to make it easier to review and spot errors.