Fix db constraints and connect handlers