]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Add --head-only option to current command
authorCharles-Axel Dein <ca@d3in.org>
Wed, 6 Mar 2013 18:31:09 +0000 (10:31 -0800)
committerCharles-Axel Dein <ca@d3in.org>
Wed, 6 Mar 2013 18:31:09 +0000 (10:31 -0800)
alembic/command.py
alembic/config.py

index 0ed984357cebdfd7bc93615bda0e769abbb57a9d..d326943d21b3c6e60e305073b5f8bd287e1bc4f3 100644 (file)
@@ -169,15 +169,21 @@ def branches(config):
                     script.get_revision(rev)
                 )
 
-def current(config):
+def current(config, head_only=False):
     """Display the current revision for each database."""
 
     script = ScriptDirectory.from_config(config)
     def display_version(rev, context):
-        config.print_stdout("Current revision for %s: %s",
-                            util.obfuscate_url_pw(
-                                context.connection.engine.url),
-                            script.get_revision(rev))
+        rev = script.get_revision(rev)
+
+        if head_only:
+            config.print_stdout(str(rev.revision))
+
+        else:
+            config.print_stdout("Current revision for %s: %s",
+                                util.obfuscate_url_pw(
+                                    context.connection.engine.url),
+                                rev)
         return []
 
     with EnvironmentContext(
@@ -219,5 +225,3 @@ def splice(config, parent, child):
 
     """
     raise NotImplementedError()
-
-
index 71f2731b14faa39b786900d261e17c6cb8cc0021..ca233e16df7238eb13123bc59d9ae38586fa5d8b 100644 (file)
@@ -192,6 +192,11 @@ class CommandLine(object):
                                 help="Populate revision script with candidate "
                                     "migration operations, based on comparison "
                                     "of database to model.")
+            # "current" command
+            if 'head_only' in kwargs:
+                parser.add_argument("--head-only",
+                                    action="store_true",
+                                    help="Only show head version")
 
             positional_help = {
                 'directory': "location of scripts directory",
@@ -257,4 +262,3 @@ def main(argv=None, prog=None, **kwargs):
     """The console runner function for Alembic."""
 
     CommandLine(prog=prog).main(argv=argv)
-