byjg / php-migration-cli

Command Line Interface for Database Migration
MIT License
8 stars 3 forks source link

Exit with code 1 on failure #9

Closed mikaellanger closed 3 years ago

mikaellanger commented 3 years ago

Getting an error code on failure is pretty important when running migrations from a script. For example, I would like to apply migrations in an init script in the official postgresql docker image in our CI, and also want to automate it in our deploy scripts. In both of these use-cases detecting that the migration failed is necessary.

byjg commented 3 years ago

Hey, that's a good catch. Thank you for PR.

Quick Question - Instead of add "return" command everywhere isn't better to add in the method handleError the exit(1)?

mikaellanger commented 3 years ago

The Symphony Command class wants the exit status returned from execute so I thought I'd better stick to that. No idea if it really matters though. 😄

byjg commented 3 years ago

All right, it is good to me. We need to handle the parent::execute though.

mikaellanger commented 3 years ago

Not quite sure I understand what you mean with "handle the parent::execute"?

byjg commented 3 years ago

Something like this:

$result = parent::execute($input, $output);
if ($result == 0) {
   // Do what have to do
}
return $result;
mikaellanger commented 3 years ago

Ok, updated. WDYT? Didn't have time to even run this yet though.

byjg commented 3 years ago

I am merging to branch 4.1.1 while I am doing some tests.

Meanwhile, you can download the version 4.1.1.x-dev to use this code.