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

This is more-or-less the same logic we used in EF6.