Fix up all the database stuff