[FIX] Check database and get last stored ids from each table.