Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

geerizzle's avatar

How/where do you deploy one-time scripts?

Lately I've had the need to e.g. run an eloquent query, and if certain conditions are met, update all of the rows with a value, or send an email, or do something else. These have ended up being quite complex, so I've been running them first in development to make sure everything works OK.

So then I'm left with a script, which I've been running on production in one of two ways: 1) pasting into tinker, but I'm always a bit wary of this because it often pastes weirdly or runs before I've had a chance to give it the once over. or 2) putting it into a migration, but then it logs it in the migrations table which seems a bit unnecessary or 3) it doesn't seem worth going to the bother of creating a command for it either.

Is there a better way?

0 likes
6 replies
joefusco's avatar

I usually stick these kind of things in a migration. I like this approach because it keeps it in version control, should I ever need to review when/what changed, and a migration ensures it runs only once.

tykus's avatar

Why would a command/job not be preferable to a manually working with production data in tinker or (ab)using a migration? Especially if these tasks " ended up being quite complex"; I would prefer that there was some structure to the logic being executed and where/how it is being executed.

geerizzle's avatar

Well that's essentially my question. I don't like running it in tinker. And migrations don't seem right. So is creating a command the way to do it?

tykus's avatar

That would certainly be my approach, yes. I know it might seem like overkill, but you have the capability to map out exactly the steps you want/need to take.

geerizzle's avatar

OK great. Thinking about it I could create & register the command and then edit & deploy it whenever I wanted to do this sort of thing.

tykus's avatar

Correct. Best of luck with it!

If my answer above helped you, please consider marking the Best Reply

Please or to participate in this conversation.