Migrations fixes

Fixed a few issues with migrations discovered recently.
Added code to generate sql for automatically creating/dropping the history table when running migrations.
I can change to MigrationId instead if that is what we want but that shouldn't stop this from going in. Maurycy needs it for his change.