Migrations: Write script to .sql file (Fixes #420)