migrate; adopt DB config and SQL queries, create needed user DBs on demand

Change-Id: I5d511b02fef2c0976706dfab8686a6ba090e4f06