Added code to generate sql for automatically creating/dropping the history table when running migrations.
Fixed a few issues with migrations discovered recently.