]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
this actually ran something
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Apr 2010 22:54:10 +0000 (18:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 28 Apr 2010 22:54:10 +0000 (18:54 -0400)
alembic/command.py
alembic/context.py
alembic/op.py
alembic/script.py
templates/generic/env.py

index 57c8072e2481487fec398dd1ed1d87bd6c939f5b..1e6ea0169d4d9f67c4382b09a8ff717f8c615c4f 100644 (file)
@@ -1,5 +1,5 @@
 from alembic.script import ScriptDirectory
-from alembic import util
+from alembic import util, ddl, context
 import os
 import functools
 
@@ -70,6 +70,7 @@ def upgrade(config):
 
     script = ScriptDirectory.from_config(config)
     context._migration_fn = script.upgrade_from
+    context.config = config
     script.run_env()
     
 def revert(config, revision):
index a89da7432a53a8b9bc27ce3bf646170493acf09c..8565695e4ff8b6a251186b1b4b9919e004cf2c5f 100644 (file)
@@ -36,12 +36,15 @@ class DefaultContext(object):
             
     def run_migrations(self, **kw):
         current_rev = self._current_rev()
-        for change in self._migrations_fn(current_rev):
-            change.execute()            
-        self._update_current_rev(current_rev, change.upgrade)
+        for change, rev in self._migrations_fn(current_rev):
+            change.execute(**kw)
+        self._update_current_rev(current_rev, rev)
         
     def _exec(self, construct):
         pass
+    
+    def execute(self, sql):
+        self._exec(sql)
         
     def alter_column(self, table_name, column_name, 
                         nullable=util.NO_VALUE,
@@ -63,9 +66,8 @@ class DefaultContext(object):
 
 def configure_connection(connection):
     global _context
-    _context = _context_impls[connection.dialect.name](connection, _migration_fn)
+    _context = _context_impls.get(connection.dialect.name, DefaultContext)(connection, _migration_fn)
     
 def run_migrations(**kw):
-    global _context
     _context.run_migrations(**kw)
     
\ No newline at end of file
index ebd4b56f49982a1b1e95b8b10b1cf93787fa36c5..c7b5d10043691f7940fe1ac71a8c0f88322eaac2 100644 (file)
@@ -49,3 +49,6 @@ def create_unique_constraint(name, source, local_cols):
     context.add_constraint(
                 _unique_constraint(name, source, local_cols)
             )
+
+def execute(sql):
+    context.execute(sql)
\ No newline at end of file
index 9c83af84414a5064984d52e636b4c24743acb922..65fef66964438e7a7fc44971ec1cfd79b9741737 100644 (file)
@@ -23,13 +23,16 @@ class ScriptDirectory(object):
                     options.get_main_option('script_location'))
 
     def upgrade_from(self, current_rev):
-        return []
+        script = self._revision_map[current_rev]
+        while script:
+            yield script.module.upgrade, script.upgrade
+            script = script.nextrev
 
     def downgrade_to(self, destination, current_rev):
         return []
-
+        
     def run_env(self):
-        pass
+        util.load_python_file(self.dir, 'env.py')
 
     @util.memoized_property
     def _revision_map(self):
index b6a389f2beca5a0f31491773bb8a9331cf0aecaa..cf025bf612670a46b15bcf1209332125458f0d08 100644 (file)
@@ -1,10 +1,11 @@
-from alembic import options, context
+from alembic import context
 from sqlalchemy import engine_from_config
-import logging
+from logging.config import fileConfig
+config = context.config
 
-logging.fileConfig(options.config_file)
+fileConfig(config.config_file_name)
 
-engine = engine_from_config(options.get_section('alembic'), prefix='sqlalchemy.')
+engine = engine_from_config(config.get_section('alembic'), prefix='sqlalchemy.')
 
 connection = engine.connect()
 context.configure_connection(connection)