flatten db structure