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

This is more-or-less the same logic we used in EF6.
What happens if something goes wrong within the catch{} section?