-
-
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .. change:: | ||
| :tags: usecase, commands | ||
| :tickets: 1705 | ||
|
|
||
| Added ``--check-heads`` option to ``current`` command which | ||
| checks if all head revisions are applied to the database. | ||
|
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: will mention the cookbook recipe here View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265 |
||
| The command exists with a non-zero exit code if this is not the | ||
|
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: typo exists View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265 |
||
| 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: pull request courtesy Stefan Scherfke View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,6 +345,40 @@ def test_heads_upg(self): | |
| with self._assert_lines(["a2", "b3"]): | ||
| command.current(self.cfg) | ||
|
|
||
| def test_check_heads_success(self): | ||
| """ | ||
| "--check-heads" 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) | ||
|
|
||
| @testing.combinations( | ||
| ["a2"], | ||
| ["a3"], | ||
| ["b3"], | ||
| ["a2", "b3"], | ||
| ["a3", "b2"], | ||
| argnames="revs", | ||
| ) | ||
| def test_check_heads_fail(self, revs): | ||
|
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: nice job View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/6265 |
||
| """ | ||
| "--check-heads" 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.