"""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."""
"""'splice' two branches, creating a new revision file."""
-def branches(config):
- """Show current un-spliced branch points"""
\ No newline at end of file
__metaclass__ = ContextMeta
__dialect__ = 'default'
+ transactional_ddl = False
+
def __init__(self, connection, fn):
self.connection = connection
self._migrations_fn = fn
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)
-import base, postgresql
\ No newline at end of file
+import base, postgresql, mysql, sqlite
\ No newline at end of file
class PostgresqlContext(DefaultContext):
__dialect__ = 'postgresql'
-
+ transactional_ddl = True
\ No newline at end of file
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()