Skip to content

feat(Console): Add --check option to diff command#1535

Closed
ahmed-bhs wants to merge 1 commit intodoctrine:3.9.xfrom
ahmed-bhs:feature/diff-check-option
Closed

feat(Console): Add --check option to diff command#1535
ahmed-bhs wants to merge 1 commit intodoctrine:3.9.xfrom
ahmed-bhs:feature/diff-check-option

Conversation

@ahmed-bhs
Copy link

Q A
Type feature
BC Break no
Fixed issues N/A

Summary

This pull request introduces a new --check option to the doctrine:migrations:diff command to improve its usability in CI/CD environments.

Currently, verifying that no pending migrations exist requires using fragile and complex shell scripts that check for the creation of new migration files. This approach is not ideal as it's not explicit and can be brittle. This PR proposes a cleaner, integrated solution.

The new --check flag allows you to verify the database schema status without generating a migration file.

  • If the database schema is in sync with the mapping, the command will output a success message and exit with a 0 status code.
  • If the database schema is not in sync, the command will output a clear, actionable error message (suggesting the diff command to run) and exit with a 1 status code.

This makes CI configuration much simpler, more readable, and improves the overall developer experience by providing a robust, self-documenting way to ensure schema consistency in automated workflows.

This option allows checking for schema differences in a CI/CD environment without generating a file.

It exits with a non-zero status code if changes are detected, providing a clear signal for CI workflows and actionable feedback for developers.
@ahmed-bhs ahmed-bhs force-pushed the feature/diff-check-option branch from 7dddfc6 to 5b3e769 Compare October 26, 2025 15:19
@greg0ire
Copy link
Member

verifying that no pending migrations

In what situations is this needed? I mean, if there are migrations, you probably want to run them at some point, and you probably want to do so inside your CI, right?

@thePanz
Copy link
Contributor

thePanz commented Feb 26, 2026

@ahmed-bhs is your intent to check if "pending migrations exists"?

Currently, verifying that no pending migrations exist requires using fragile and complex shell scripts that check for the creation of new migration files.

Why not using the https://github.com/doctrine/migrations/blob/3.9.x/src/Tools/Console/Command/UpToDateCommand.php command?
It is described as:

The UpToDateCommand class outputs if your database is up to date or if there are new migrations that need to be executed.

@stof
Copy link
Member

stof commented Feb 26, 2026

If the goal is to detect cases where you forgot to generate your migration after changing your mapping, this is already covered by the doctrine:schema:validate command.

Thre is no reason to reimplement the same command in doctrine/migrations.

@ahmed-bhs
Copy link
Author

Thank you @stof and @thePanz for your help — this is already covered by doctrine:schema:validate.

@ahmed-bhs ahmed-bhs closed this Mar 25, 2026
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

Successfully merging this pull request may close these issues.

4 participants