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 May 16

What are the unwritten rules of development?

What underlying rules govern our work?

READ POST
Follow @ben to see more of their posts in your feed.
David J Eddy
Raised by a loving pair of 1's and 0's.
Trending on dev.to
What is your routine for staying fit and healthy?
#discuss
Quick Advice For Junior Devs
#discuss
What image-hosting sites do you use?
#discuss #webdev #imagehosting
Discussion: Would you consider building new framework or not
#discuss #developer #services #framework
How Art School Prepared Me for Programming
#art #career
What kind of breaks do you take throughout the work day?
#discuss
Front End Development automation with Puppeteer. Part 1
#webdev #automation #javascript #node
What was your first ever contribution to Open Source?
#discuss #opensource #contributing