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

jakeryansmith's avatar

How to run migration on initial deployment

I have an interesting problem. I'm trying to deploy my app with Envoyer. The problem is that I have artisan commands that need access to the database, so when the "Install Composer Dependencies" task runs it tries to run artisan at the end for cleanup, but this throws an error because it's trying to load the artisan command which then looks for a database but can't find it. So, I thought I could fix this by running my migrations before the task using hooks, but that doesn't work because it can't seem to run artisan commands until the composer dependencies are installed. I'm guessing there is a simple solution to this, but I'm not seeing it. I would love anyones advice on how they typically handle initial deployments, or how I could resolve this issue. Thanks!

0 likes
1 reply
jakeryansmith's avatar

Never mind, I believe I figured it out. I was injecting a dependency vie the constructor into my command, it was this dependency that needed access to the database. I moved this dependency out of the constructor and everything works fine now.

Please or to participate in this conversation.