Fixed script to run on any db