Add db upgrade logic for the fix introduced with the previous commit.

Fixes #711.