Build properties db

This is a full rewrite of #1380 (only the db part), as my git-foo is not good enough to let me do that kind of magic. So please review it carefully.

All data and process stuff has been left out.

I'm keeping #1380 around as reference.
Write performance.
With this, you can do all the inserts in one query instead of 2*n queries.
Even if this is not used in the first impl, this would allow the optimization without yet another migration script.