[database] Improve protocol template lookup for prototype

Rather than blindingly selecting the first protocol template
found, look for the first valid one.
4 jobs for improve_database_prototype_generation in 22 minutes and 14 seconds (queued for 6 seconds)
Status Job ID Name Coverage
  Build
passed #180717
docker-build
build_linux_36

00:22:03

64.0%
passed #180718
docker-build
build_linux_37

00:21:56

64.0%
passed #180715
macosx
build_macosx_36

00:22:13

64.0%
passed #180716
macosx
build_macosx_37

00:22:04

64.0%