Fixed database migration code