Restructure migration code to allow easy changing of database