Refactored migration for compatibility with databases other than MySQL.

Code provided by https://github.com/relu

Signed-off-by: William <william@amovens.com>