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

Diff command throws Exception instead of message #833

Closed
jawira opened this issue Jun 25, 2019 · 2 comments
Closed

Diff command throws Exception instead of message #833

jawira opened this issue Jun 25, 2019 · 2 comments

Comments

@jawira
Copy link
Contributor

jawira commented Jun 25, 2019

BC Break Report

Q A
BC Break yes
Version v1.8

Summary

In Migration v1.8, diff command throws Exception instead of message. This is a problem for pipelines (CI) and also for build tools (make, Phing, ...) since they rely on return values.

This is new for me since, in older projects, diff command only returned a nice message (same kind of message that migrate command returns).

Digging into the code I found out where this change was made: cbe1b7f

As you can see, in this commit the following code was removed...:

// lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php
if ($up === '' && $down === '') {
	$output->writeln('No changes detected in your mapping information.');
	return;
}

and was moved as an exception:

// lib/Doctrine/Migrations/MigrationDiffGenerator.php
if ($up === '' && $down === '') {
    throw new RuntimeException('No changes detected in your mapping information.');
}

IMHO a refactoring should not transform a message into an Exception.

Later, in commit d9c1b0c this exception was refactored as:

// lib/Doctrine/Migrations/MigrationDiffGenerator.php
if ($up === '' && $down === '') {
	throw NoChangesDetected::new();
}

Previous behaviour

When there's no changes is mapping, the diff command displays a message as output:

No changes detected in your mapping information.

Current behaviour

When there's no changes is mapping, the diff command throws an Exception:

In NoChangesDetected.php line 13:
No changes detected in your mapping information.  

How to reproduce

Run diff command when you have no changes in your mapping:

// I'm using symfony console
$ bin/console doctrine:migrations:diff

I though in two possible solutions to solve this:

  1. Either NoChangesDetected exception is removed and a message is displayed (this was the behaviour before v1.8).
  2. Or, it's also possible to add an option --allow-no-diff to mute the NoChangesDetected exception. Please note that migration command has a --allow-no-migration option which has a similar behaviour.

I'm more than happy to help with this if you can give some advices and tell me what to do and where to start :)

@jwage
Copy link
Member

jwage commented Jul 1, 2019

This change was made in 2.0 right? Your version says 1.8 but I thought it was done in 2.0 refactoring.

Can you help me understand the use case for running diff in your CI?

@jawira
Copy link
Contributor Author

jawira commented Jul 2, 2019

Before v1.8.0, Diff displayed a message only, not an Exception. You can see this change in the provided link: cbe1b7f , please search for "No changes detected in your mapping information". This commit is from May 10 2018, while v1.8.0 was released on June 6 2018.

About my use case, in older projects I used to have a Makefile like:

db: db-migrate db-diff db-migrate
.PHONY: db

db-migrate:
	bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
.PHONY: db-migrate

db-diff:
	bin/console doctrine:migrations:diff --formatted
.PHONY: db-diff

# other targets here

Running make db will guarantee that my database is up-to-date. db target will run db-migrate a first time to apply any forgotten and not yet executed migration (created by myself or by other devs after a git pull). Then db-diff is called to create new migration files and then db-migrate is called once again to apply the migration files that have just been created.

Please note that db target can be chained, for example: make vendor db fixtures warm-up. When migrate command returns a non-zero value all the execution is stopped.

I use make db all the time, and also use that command in my pipelines to avoid any blocking.

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

No branches or pull requests

2 participants