Refactor migrations so they work for other databases as well

Here's a pull request for #4