]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
ui
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 Apr 2010 00:23:08 +0000 (20:23 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 30 Apr 2010 00:23:08 +0000 (20:23 -0400)
alembic/command.py
alembic/context.py
alembic/ddl/__init__.py
alembic/ddl/postgresql.py
alembic/script.py

index a2253185c512d099116d9ecafdc6b97eb20a7723..050111a571c2672eb6628b8274c69dddec03fac4 100644 (file)
@@ -85,22 +85,18 @@ def history(config):
     """List changeset scripts in chronological order."""
 
     script = ScriptDirectory.from_config(config)
-    heads = set(script._get_heads())
-    base = script._get_rev("base")
-    while heads:
-        todo = set(heads)
-        heads = set()
-        for head in todo:
-            print 
-            if head in heads:
-                break
-            for sc in script._revs(head, base):
-                if sc.is_branch_point and sc.revision not in todo:
-                    heads.add(sc.revision)
-                    break
-                else:
-                    print sc
+    for sc in script.walk_revisions():
+        if sc.is_head:
+            print
+        print sc
 
+def branches(config):
+    """Show current un-spliced branch points"""
+    script = ScriptDirectory.from_config(config)
+    for sc in script.walk_revisions():
+        if sc.is_branch_point:
+            print sc
+    
 def current(config):
     """Display the current revision for each database."""
     
@@ -120,5 +116,3 @@ def splice(config, parent, child):
     """'splice' two branches, creating a new revision file."""
     
     
-def branches(config):
-    """Show current un-spliced branch points"""
\ No newline at end of file
index cc1a6325a578c5a9afc7ac49e6caf197ac8ec698..96941902aa00ec0aea14771e62cced2c440f2eb7 100644 (file)
@@ -23,6 +23,8 @@ class DefaultContext(object):
     __metaclass__ = ContextMeta
     __dialect__ = 'default'
     
+    transactional_ddl = False
+    
     def __init__(self, connection, fn):
         self.connection = connection
         self._migrations_fn = fn
@@ -43,13 +45,20 @@ class DefaultContext(object):
             self.connection.execute(_version.update(), {'version_num':new})
             
     def run_migrations(self, **kw):
+        log.info("Context class %s.", self.__class__.__name__)
+        log.info("Will assume %s DDL.", 
+                        "transactional" if self.transactional_ddl 
+                        else "non-transactional")
         current_rev = prev_rev = rev = self._current_rev()
         for change, rev in self._migrations_fn(current_rev):
             log.info("Running %s %s -> %s", change.__name__, prev_rev, rev)
             change(**kw)
+            if not self.transactional_ddl:
+                self._update_current_rev(prev_rev, rev)
             prev_rev = rev
-        
-        self._update_current_rev(current_rev, rev)
+            
+        if self.transactional_ddl:
+            self._update_current_rev(current_rev, rev)
         
     def _exec(self, construct):
         self.connection.execute(construct)
index 232d538b4fa6c0e0f69c3555395153866b65c92b..20bb6d77f5291d1cc9f298f1d374b8ffbbc7f3f7 100644 (file)
@@ -1 +1 @@
-import base, postgresql
\ No newline at end of file
+import base, postgresql, mysql, sqlite
\ No newline at end of file
index 894a30269e0df72c424490189ed29d0b82573e36..ebd2f00cc0b1fbbff5a32ce68bd872dc8f4a376a 100644 (file)
@@ -2,5 +2,5 @@ from alembic.context import DefaultContext
 
 class PostgresqlContext(DefaultContext):
     __dialect__ = 'postgresql'
-    
+    transactional_ddl = True
     
\ No newline at end of file
index f5766a8220592eb20683406bbd378a882a6a5f91..d0de004c9faf2f5d4abf085d57b6ef3c4a0647dd 100644 (file)
@@ -23,6 +23,28 @@ class ScriptDirectory(object):
         return ScriptDirectory(
                     config.get_main_option('script_location'))
     
+    def walk_revisions(self):
+        """Iterate through all revisions.
+        
+        This is actually a breadth-first tree traversal,
+        with leaf nodes being heads.
+        
+        """
+        heads = set(self._get_heads())
+        base = self._get_rev("base")
+        while heads:
+            todo = set(heads)
+            heads = set()
+            for head in todo:
+                if head in heads:
+                    break
+                for sc in self._revs(head, base):
+                    if sc.is_branch_point and sc.revision not in todo:
+                        heads.add(sc.revision)
+                        break
+                    else:
+                        yield sc
+        
     def _get_rev(self, id_):
         if id_ == 'head':
             id_ = self._current_head()