So rake task might be your goto solution. That’s purposely designed for ad hoc script running. I would still put that into a plugin though, as you can then manage it nicely on GitHub and you’d never forget where you put it or delete it accidentally.
Here’s a load of examples: discourse/lib/tasks at 1472e47aae5bfdfb6fd9abfe89beb186c751f514 · discourse/discourse · GitHub