jtong - make db migration happened on start, and refactor code