From: Mike Bayer Date: Wed, 28 Apr 2010 22:54:10 +0000 (-0400) Subject: this actually ran something X-Git-Tag: rel_0_1_0~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=859843a2a22861d6b1c22294c505fddbe02bc5b7;p=thirdparty%2Fsqlalchemy%2Falembic.git this actually ran something --- diff --git a/alembic/command.py b/alembic/command.py index 57c8072e..1e6ea016 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -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): diff --git a/alembic/context.py b/alembic/context.py index a89da743..8565695e 100644 --- a/alembic/context.py +++ b/alembic/context.py @@ -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 diff --git a/alembic/op.py b/alembic/op.py index ebd4b56f..c7b5d100 100644 --- a/alembic/op.py +++ b/alembic/op.py @@ -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 diff --git a/alembic/script.py b/alembic/script.py index 9c83af84..65fef669 100644 --- a/alembic/script.py +++ b/alembic/script.py @@ -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): diff --git a/templates/generic/env.py b/templates/generic/env.py index b6a389f2..cf025bf6 100644 --- a/templates/generic/env.py +++ b/templates/generic/env.py @@ -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)