"""Create a new revision file."""
script = ScriptDirectory.from_config(config)
- template_args = {}
+ template_args = {
+ 'config': config # Let templates use config for e.g. multiple databases
+ }
imports = set()
+
+ environment = util.asbool(
+ config.get_main_option("revision_environment")
+ )
+
if autogenerate:
+ environment = True
util.requires_07("autogenerate")
def retrieve_migrations(rev, context):
if script.get_revision(rev) is not script.get_revision("head"):
if self.as_sql and not rev:
self._version.drop(self.connection)
- def execute(self, sql):
+ def execute(self, sql, execution_options=None):
"""Execute a SQL construct or string statement.
-
+
The underlying execution mechanics are used, that is
- if this is "offline mode" the SQL is written to the
+ if this is "offline mode" the SQL is written to the
output buffer, otherwise the SQL is emitted on
the current SQLAlchemy connection.
- USE_TWOPHASE = False
-
+ from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
+ from logging.config import fileConfig
+ import logging
import re
- import sys
- import logging
- logging.fileConfig(options.config_file)
+ USE_TWOPHASE = False
+
+ # this is the Alembic Config object, which provides
+ # access to the values within the .ini file in use.
+ config = context.config
+
+ # Interpret the config file for Python logging.
+ # This line sets up loggers basically.
+ fileConfig(config.config_file_name)
+ logger = logging.getLogger(__name__)
-# gather section names referring to different
+# gather section names referring to different
# databases. These are named "engine1", "engine2"
# in the sample .ini file.
- db_names = options.get_main_option('databases')
+ db_names = config.get_main_option('databases')
# add your model's MetaData objects here
-# for 'autogenerate' support. These must be set
-# up to hold just those tables targeting a
-# particular database. table.tometadata() may be
+# for 'autogenerate' support. These must be set
+# up to hold just those tables targeting a
+# particular database. table.tometadata() may be
# helpful here in case a "copy" of
# a MetaData is needed.
# from myapp import mymodel