core: refactor database creation on site init.

(cherry picked from commit 46b20abcaccb29ec8b4ebd18a1182940d0de4d47)