Migrate db

Closes #707.