I have inherited a large EE site (upgraded to 2.9.2) that is, frankly, a mess on the backend (EE CP). There are many template groups and templates that appear to have been left behind from multiple site redesign iterations over the past 6 years and I am not sure if they are used any more, and even if they are, where they are used. Additionally they are not saved to disk - they are just stored in the db - and I want to version control all the templates, but only what is current, not the legacy junk, so I need to turn back on template writing to disk, at the very least to initially dump out the used templates so I can get them into Git.
I want to clean it up for both my and my content creators sanity. Is there a simple way (I don't care whether it is via the EE CP, PHP, or MySQL CLI - I am fluent in all) that I can easily determine if a template is used on any Pages in the site? If I used the MySQL CLI which EE table(s) should I be searching for? Are templates stored in the db by name, or as key-value pairs (PK integer and name), and are the templates names/PK integer used as foreign keys in other tables? I need to know how to isolate everything unused.
Thanks in advance.