Skip to content

Add "--check-heads" option to "current" command#1739

Closed
sscherfke wants to merge 3 commits into
sqlalchemy:mainfrom
sscherfke:check-if-head
Closed

Add "--check-heads" option to "current" command#1739
sscherfke wants to merge 3 commits into
sqlalchemy:mainfrom
sscherfke:check-if-head

Conversation

@sscherfke
Copy link
Copy Markdown
Contributor

Add --check-heads option to current commad to check if all head revisions are applied to the database.

Description

Fixes: #1705

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

@sscherfke
Copy link
Copy Markdown
Contributor Author

One test started to fail when I added additional tests. I don't know why and I don't think tests should be able to influence other tests in this way. I probably did something wrong, but don't know what. 🙈

@sscherfke
Copy link
Copy Markdown
Contributor Author

I was also considering to add a --check-loop SECONDS option which would indefinitely repeat the check every SECONDS seconds until it succeeds. What do you think of this?

@zzzeek
Copy link
Copy Markdown
Member

zzzeek commented Oct 27, 2025

I was also considering to add a --check-loop SECONDS option which would indefinitely repeat the check every SECONDS seconds until it succeeds. What do you think of this?

im not a huge fan of digging in that level of richness here, the idiomatic way to do that kind of thing would be:

until alembic current --check-heads; do echo "checking heads..."; sleep 5; done

why re-implement all that in some less full featured way

Copy link
Copy Markdown
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

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

thanks for the PR! minor changes

Comment thread docs/build/changelog.rst Outdated
Comment thread alembic/config.py
Comment thread alembic/command.py
@zzzeek zzzeek requested a review from sqla-tester October 27, 2025 15:09
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision f8c9a1f of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

New Gerrit review created for change f8c9a1f: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Comment thread tests/test_command.py Outdated
Comment thread tests/test_command.py Outdated
Comment thread docs/build/changelog.rst Outdated
@zzzeek zzzeek requested a review from sqla-tester October 28, 2025 12:06
Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 955f9b7 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Copy Markdown
Collaborator

Patchset 955f9b7 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

OK great, I've applied some last minute changes on this end.

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Comment thread alembic/command.py
:param config: a :class:`.Config` instance.

:param check_heads: Check if all head revisions are applied to the
database. Exit with an error if this is not the case.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

.. versionadded:: 1.17.1

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Comment thread alembic/command.py
if check_heads and (
set(context.get_current_heads()) != set(script.get_heads())
):
raise util.CommandError("Database is not on all head revisions")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

like alembic check, will add a subclass here

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

:tickets: 1705

Added ``--check-heads`` option to ``current`` command which
checks if all head revisions are applied to the database.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

will mention the cookbook recipe here

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265


Added ``--check-heads`` option to ``current`` command which
checks if all head revisions are applied to the database.
The command exists with a non-zero exit code if this is not the
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

typo exists

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Added ``--check-heads`` option to ``current`` command which
checks if all head revisions are applied to the database.
The command exists with a non-zero exit code if this is not the
case.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

pull request courtesy Stefan Scherfke

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Comment thread tests/test_command.py
["a3", "b2"],
argnames="revs",
)
def test_check_heads_fail(self, revs):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

nice job

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Comment thread tests/test_command.py
assert_raises_message(
util.CommandError,
"Database is not on all head revisions",
command.current,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

there might be some test cleanup error occurring, investigating

it looks like test_doesnt_create_alembic_version was relying on test ordering to work, fixed that test separately.

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

@sqla-tester
Copy link
Copy Markdown
Collaborator

Michael Bayer (zzzeek) wrote:

recheck

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

Federico Caselli (CaselIT) wrote:

code review left on gerrit

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

  • tests/test_command.py (line 1601): not sure if this was intended

Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

Michael Bayer (zzzeek) wrote:

code review left on gerrit

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

  • tests/test_command.py (line 1601): it was, I had a shutil.rmtree() there which was deleting the whole class-level fixture and only passing because of randomness. these new tests started throwing it all off, so i fixed this test to only delete the file that it created.

@sqla-tester
Copy link
Copy Markdown
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265 has been merged. Congratulations! :)

Copy link
Copy Markdown
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

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

Federico Caselli (CaselIT) wrote:

code review left on gerrit

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265

  • tests/test_command.py (line 1601): ok!

hswong3i pushed a commit to alvistack/sqlalchemy-alembic that referenced this pull request Oct 29, 2025
Added :paramref:`.command.current.check_heads` parameter to
:func:`.command.current` command, available from the command line via the
``--check-heads`` option to ``alembic current``.  This tests if all head
revisions are applied to the database and raises :class:`.DatabaseNotAtHead`
(or from the command line, exits with a non-zero exit code) if this is not
the case.  The parameter operates equvialently to the cookbook recipe
:ref:`cookbook_check_heads`. Pull request courtesy Stefan Scherfke.

Fixes: sqlalchemy#1705
Closes: sqlalchemy#1739
Pull-request: sqlalchemy#1739
Pull-request-sha: 955f9b7

Change-Id: I1173217ff6a4927226ec9e7b8c7ef67c6431d728
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.

Add command "check-if-head"

3 participants