Fix database and add test for rules generation.