Database migration functions

Completing work in progress