diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-01 12:29:03 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-02-01 12:29:03 -0500 |
commit | eac8e7393b9fc7d21396bd755aa94f9b55ea2739 (patch) | |
tree | 3645ce4c04dbfd979548eb61b85ba72352a82590 /alembic/autogenerate | |
parent | 4bd2739ec9fb3b789880bea096522d36fb4c4b01 (diff) | |
download | alembic-eac8e7393b9fc7d21396bd755aa94f9b55ea2739.tar.gz |
- Added new argument
:paramref:`.EnvironmentContext.configure.user_module_prefix`.
This prefix is applied when autogenerate renders a user-defined type,
which here is defined as any type that is from a module outside of the
``sqlalchemy.`` hierarchy. This prefix defaults to ``None``, in
which case the :paramref:`.EnvironmentContext.configure.sqlalchemy_module_prefix`
is used, thus preserving the current behavior. #171
- added new documentation sections regarding rendering of types
- improved CSS so that deprecations/version changes are highlighted
- cleanup of some configure paramter docs
Diffstat (limited to 'alembic/autogenerate')
-rw-r--r-- | alembic/autogenerate/render.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/alembic/autogenerate/render.py b/alembic/autogenerate/render.py index 38e953c..4c7b4f5 100644 --- a/alembic/autogenerate/render.py +++ b/alembic/autogenerate/render.py @@ -204,7 +204,6 @@ def _modify_col(tname, cname, existing_nullable=None, existing_server_default=False, schema=None): - sqla_prefix = _sqlalchemy_autogenerate_prefix(autogen_context) indent = " " * 11 text = "%(prefix)salter_column(%(tname)r, %(cname)r" % { 'prefix': _alembic_autogenerate_prefix( @@ -212,7 +211,7 @@ def _modify_col(tname, cname, 'tname': tname, 'cname': cname} text += ",\n%sexisting_type=%s" % (indent, - _repr_type(sqla_prefix, existing_type, autogen_context)) + _repr_type(existing_type, autogen_context)) if server_default is not False: rendered = _render_server_default( server_default, autogen_context) @@ -220,7 +219,7 @@ def _modify_col(tname, cname, if type_ is not None: text += ",\n%stype_=%s" % (indent, - _repr_type(sqla_prefix, type_, autogen_context)) + _repr_type(type_, autogen_context)) if nullable is not None: text += ",\n%snullable=%r" % ( indent, nullable,) @@ -238,6 +237,13 @@ def _modify_col(tname, cname, text += ")" return text +def _user_autogenerate_prefix(autogen_context): + prefix = autogen_context['opts']['user_module_prefix'] + if prefix is None: + return _sqlalchemy_autogenerate_prefix(autogen_context) + else: + return prefix + def _sqlalchemy_autogenerate_prefix(autogen_context): return autogen_context['opts']['sqlalchemy_module_prefix'] or '' @@ -277,8 +283,7 @@ def _render_column(column, autogen_context): return "%(prefix)sColumn(%(name)r, %(type)s, %(kw)s)" % { 'prefix': _sqlalchemy_autogenerate_prefix(autogen_context), 'name': column.name, - 'type': _repr_type(_sqlalchemy_autogenerate_prefix(autogen_context), - column.type, autogen_context), + 'type': _repr_type(column.type, autogen_context), 'kw': ", ".join(["%s=%s" % (kwname, val) for kwname, val in opts]) } @@ -302,7 +307,7 @@ def _render_server_default(default, autogen_context): else: return None -def _repr_type(prefix, type_, autogen_context): +def _repr_type(type_, autogen_context): rendered = _user_defined_render("type", type_, autogen_context) if rendered is not False: return rendered @@ -314,7 +319,11 @@ def _repr_type(prefix, type_, autogen_context): if imports is not None: imports.add("from sqlalchemy.dialects import %s" % dname) return "%s.%r" % (dname, type_) + elif mod.startswith("sqlalchemy"): + prefix = _sqlalchemy_autogenerate_prefix(autogen_context) + return "%s%r" % (prefix, type_) else: + prefix = _user_autogenerate_prefix(autogen_context) return "%s%r" % (prefix, type_) def _render_constraint(constraint, autogen_context): |