Some database related fixes from redheadedrod

These should squash a few issues, such as the group permissions not deleted
bug.