Heat the oil in a large pan and add the onion, celery and carrot. Fry over a medium heat for 10 mins, stirring now and then, until softened and starting to colour.
Stir in the mince and cook, breaking up any clumps of meat with a wooden spoon, until browned.
Add the tomato purée, garlic and thyme, and cook for 1-2 mins more. Pour in the wine, if using, and increase the heat to boil off most of the alcohol. Reduce the heat, stir in the stock and season. Cover with a tight-fitting lid and leave to cook gently for 1 hr-1 hr 15 mins until the meat is tender and the sauce has thickened.
Remove the lid and continue cooking for 15 mins. Meanwhile, cook the pasta following pack instructions. Reserve a mugful of the cooking water, then drain the spaghetti and add to the ragu with the Parmesan. Toss well and add a little pasta water to help the sauce coat the spaghetti. Serve with a side salad and extra cheese, if you like.