Magento 2 script for setup upgrade

Posted on August 12, 2016

To determine whether your current Magento 2 instance needs upgrade scripts to run you can use the following CLI command:

$ bin/magento setup:db:status

The output can either be something like this (if upgrade is needed):

The module code base doesn't match the DB schema and data.

or like this (if no upgrade is needed):

All modules are up to date.    

Unfortunately, at date, the Magento 2 CLI doesn’t return different exit codes in case of different outcomes, that’s something that can be useful especially if you use some CI or deploy tools.

Thus I wrote a simple bash script that converts different text outputs in different exit codes:

# use --no-ansi to avoid color characters
message=$(bin/magento setup:db:status --no-ansi)
if [[ ${message:0:3} == "All" ]];
  exit 0 # 0 not required being default exit code; used for clarity
  exit 1

You can also download it from here.


Photo credits: Christiaan Colen - Creative Commons license

Posted with : Magento2, Tools