diff -r 1c42381a7a34 alembic/ddl/__init__.py --- a/alembic/ddl/__init__.py Mon Jan 02 17:26:00 2012 -0500 +++ b/alembic/ddl/__init__.py Tue Jan 03 11:42:46 2012 -0500 @@ -1,2 +1,2 @@ import postgresql, mysql, sqlite, mssql -from impl import DefaultImpl \ No newline at end of file +from impl import DefaultImpl, ops_for_connection \ No newline at end of file diff -r 1c42381a7a34 alembic/ddl/impl.py --- a/alembic/ddl/impl.py Mon Jan 02 17:26:00 2012 -0500 +++ b/alembic/ddl/impl.py Tue Jan 03 11:42:46 2012 -0500 @@ -217,6 +217,37 @@ """ self.static_output("COMMIT;") +def ops_for_connection(connection, impl_opts=None, transactional_ddl=None): + """Return a :class:`.DefaultImpl` for the given + :class:`sqlalchemy.engine.base.Connection`. + + Once retrieved, the object can be used to emit + the various "ops" defined in :mod:`alembic.op` + without a usual Alembic configuration in place. + + :param connection: a :class:`sqlalchemy.engine.base.Connection`. + This will be used to invoke DDL statements and also + to determine the type of dialect in use. + :param impl_opts: optional dictionary which can + contain options normally passed to + :func:`.context.configure`. Some implementations + respond to various options here such as + ``mssql_batch_separator``. + :param transactional_ddl: Force the "transactional DDL" + flag to ``True`` or ``False``. Leave as ``None`` + to use the default. + + """ + engine = connection.engine + if not impl_opts: + impl_opts = {} + return DefaultImpl.get_by_dialect(engine.dialect)( + engine.dialect, connection, + as_sql=False, + transactional_ddl=transactional_ddl, + output_buffer=None, + context_opts=impl_opts) + class _literal_bindparam(_BindParamClause): pass diff -r 1c42381a7a34 tests/test_op.py --- a/tests/test_op.py Mon Jan 02 17:26:00 2012 -0500 +++ b/tests/test_op.py Tue Jan 03 11:42:46 2012 -0500 @@ -1,6 +1,6 @@ """Test against the builders in the op.* module.""" -from tests import op_fixture +from tests import op_fixture, db_for_dialect from alembic import op from sqlalchemy import Integer, Column, ForeignKey, \ UniqueConstraint, Table, MetaData, String,\ @@ -273,3 +273,10 @@ "UPDATE account SET name='account 2' WHERE account.name = 'account 1'", "UPDATE account SET id=2 WHERE account.id = 1" ) + +def test_standalone_ops_sqlite(): + eng = db_for_dialect("sqlite") + conn = eng.connect() + impl = ops_for_connection(conn) + assert impl.transactional_ddl is False + assert impl.connection is conn