Never run a migration again using PHPs Composer

Every get tired of running database migrations after updating your application? Let composer do it for you! In this example we will use Yii2's migration command as an example:

  "name": "Application Name",
  "description": "Some desciption text",
  "scripts": {
    "post-install-cmd": [
      "php console/yii app/setup --interactive=0"
    "post-update-cmd": [
      "php console/yii app/setup --interactive=0"

If you write your migrations in an atomic fashion (once changed, do not over write) the migration can be run over and over without causing errors. You can even run multiple commands after a composer action via the command hooks.

Did you find this post useful? Show some love!
Classic DEV Post from Oct 21

Developer is the next blue collar job

People who generally do not have a college education, and go straight into a physical, or modest working-class job after high school.

David J Eddy
AWS Certified (x4), Automated Testing / Continuous Integration / Delivery /Deployment (CI/CDs), Cloud, Containers, Dev(Sec)Ops, Software Engineer. is where software developers stay in the loop and avoid career stagnation.

Sign up (for free)