-
-
Notifications
You must be signed in to change notification settings - Fork 332
Add "--check-heads" option to "current" command #1739
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -681,11 +681,16 @@ def branches(config: Config, verbose: bool = False) -> None: | |
| ) | ||
|
|
||
|
|
||
| def current(config: Config, verbose: bool = False) -> None: | ||
| def current( | ||
| config: Config, check_heads: bool = False, verbose: bool = False | ||
| ) -> None: | ||
| """Display the current revision for a database. | ||
|
|
||
| :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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| :param verbose: output in verbose mode. | ||
|
|
||
| """ | ||
|
|
@@ -698,6 +703,10 @@ def display_version(rev, context): | |
| "Current revision(s) for %s:", | ||
| util.obfuscate_url_pw(context.connection.engine.url), | ||
| ) | ||
| if check_heads and ( | ||
| set(context.get_current_heads()) != set(script.get_heads()) | ||
| ): | ||
| raise util.CommandError("Database is not on all head revisions") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Michael Bayer (zzzeek) wrote: like View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265 |
||
| for rev in script.get_all_current(rev): | ||
| config.print_stdout(rev.cmd_format(verbose)) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import shutil | ||
| from typing import cast | ||
|
|
||
| import pytest | ||
|
zzzeek marked this conversation as resolved.
Outdated
|
||
| from sqlalchemy import exc as sqla_exc | ||
| from sqlalchemy import text | ||
| from sqlalchemy import VARCHAR | ||
|
|
@@ -345,6 +346,35 @@ def test_heads_upg(self): | |
| with self._assert_lines(["a2", "b3"]): | ||
| command.current(self.cfg) | ||
|
|
||
| def test_check_if_head_success(self): | ||
| """ | ||
| "--check-if-head" succeeds if all head revisions are applied. | ||
| """ | ||
| command.stamp(self.cfg, ()) | ||
| command.stamp(self.cfg, (self.a3.revision, self.b3.revision)) | ||
| with self._assert_lines(["a3", "b3"]): | ||
| command.current(self.cfg, check_heads=True) | ||
|
|
||
| @pytest.mark.parametrize( | ||
|
sscherfke marked this conversation as resolved.
Outdated
|
||
| "revs", [("a2",), ("a3",), ("b3",), ("a2", "b3"), ("a3", "b2")] | ||
| ) | ||
| def test_check_if_head_fail(self, revs): | ||
| """ | ||
| "--check-if-head" succeeds if all head revisions are applied. | ||
| """ | ||
| command.stamp(self.cfg, ()) | ||
| command.stamp( | ||
| self.cfg, tuple(getattr(self, rev).revision for rev in revs) | ||
| ) | ||
| assert_raises_message( | ||
| util.CommandError, | ||
| "Database is not on all head revisions", | ||
| command.current, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| self.cfg, | ||
| check_heads=True, | ||
| ) | ||
| command.stamp(self.cfg, ()) | ||
|
|
||
|
|
||
| class RevisionTest(TestBase): | ||
| def setUp(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.