Various DB script fixes

Applies some fixes to the db scripts. Mostly to the migration scripts.