Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrate command #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add migrate command #7

wants to merge 6 commits into from

Conversation

jameshalsall
Copy link
Contributor

@jameshalsall jameshalsall commented Sep 7, 2018

  • create alternative solution for checking if setup:upgrade is required

Fixes #4

protected function configure()
{
$this
->setName('mx:migrate')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe phinx:db:migrate or mx:phinx:migrate would be a better name (in case any other inviqa/mx module introduces new commands under "mx:"

$dbStatusCommand = $this->getApplication()->get('setup:db:status');

$output->writeln('<info>Checking if setup:upgrade is required...</info>');
$exit = $dbStatusCommand->run(new ArrayInput([]), new NullOutput());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when we add a completely new module does this return the "upgrade required" status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does, but that’s OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it by creating a new module in the src folder and the setup:db:status says everything is up to date, while the new module is obviously not registered in the database yet. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I will investigate this further

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From testing you are right, the setup:db:status command only tells us if the DB has out-of-date modules and not if it is completely missing a module. Will have to look at something bespoke for this I think.

echo $buffer;
});

return $phinx->isSuccessful() ? 0 : 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magento\Framework\Console\Cli has constants for RETURN_SUCCESS and RETURN_FAILURE

Copy link
Contributor

@tkotosz tkotosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, but I have left some feedback. :)

if ($exit === DbStatusCommand::EXIT_CODE_UPGRADE_REQUIRED) {
$output->writeln('<info>A setup:upgrade is required, running...</info>');
$setupUpgradeCommand = $this->getApplication()->get('setup:upgrade');
$setupUpgradeCommand->run(new ArrayInput([]), $output);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally after a production deployment we need to run setup:upgrade with the "--keep-generated" option, because in production mode we compile the di and deploy it with the code to production which we don't want to loose ofc.

So this migrate command should be able to accept a "--keep-generated" option as well and pass it over to the setup:upgrade here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

$output->writeln('<info>No setup:upgrade required.</info>');
}

$phinx = new Process('bin/phinx migrate');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use vendor/robmorgan/phinx/bin/phinx migrate here in case "bin-dir": "bin" is not specified in the project json (so it won't appear in the bin folder) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants