Heat oil in a large soup pot.
Sauté onion and garlic until softened.
Add carrots and celery to the pot.
Cook vegetables for 5 minutes.
Place the ham bone in the pot.
Add water or broth until fully covered.
Stir in thyme and bay leaf.
Bring to a boil, then reduce heat.
Simmer the soup for 1.5 to 2 hours.
Remove ham bone and let cool.
Shred meat from the bone.
Return meat to the pot.
Add potatoes or beans if using.
Season with salt and pepper.
Simmer for 20 more minutes.
Remove bay leaf before serving.