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

realtebo's avatar

Migration: how to execute only in development?

I'm creating a very specific use-case package for laravel. My package is adding a migration, but I absolutely must ensure that migration is NEVER executed if not in development environment.

Is there a way to allow a migration only on dev?

I think to test if .env === 'local', and do the migration only if this is true. In case of false, I simply return true to allow deploy flow to not be changed in any way.

Is there a more beautiful way? Or do you know any potential issues ?

0 likes
2 replies
jove's avatar

Checking for the environment variable is a clean way if you ask me. Is this some dev tool required table since you can't have it in production?

realtebo's avatar

Yes, I'm developing a local smtp acting as mailtrap.io. You can send mail through it, but it saves email in a db table and has a gui to inspect, delete...

I'm on a very early stage, but it works.

It's intended to be used only on development, but instead of create a standalone app we prefer to use per-project,.

Please or to participate in this conversation.