if rendered is not False:
return rendered
+ if hasattr(autogen_context.migration_context, 'impl'):
+ impl_rt = autogen_context.migration_context.impl.render_type(
+ type_, autogen_context)
+
mod = type(type_).__module__
imports = autogen_context.imports
if mod.startswith("sqlalchemy.dialects"):
dname = re.match(r"sqlalchemy\.dialects\.(\w+)", mod).group(1)
if imports is not None:
imports.add("from sqlalchemy.dialects import %s" % dname)
- return "%s.%r" % (dname, type_)
+ if impl_rt:
+ return impl_rt
+ else:
+ return "%s.%r" % (dname, type_)
elif mod.startswith("sqlalchemy."):
prefix = _sqlalchemy_autogenerate_prefix(autogen_context)
return "%s%r" % (prefix, type_)
"""
self.static_output("COMMIT" + self.command_terminator)
+ def render_type(self, type_obj, autogen_context):
+ return False
+
def _string_compare(t1, t2):
return \
format_type, AlterColumn, RenameTable
from .impl import DefaultImpl
from sqlalchemy.dialects.postgresql import INTEGER, BIGINT
+from ..autogenerate import render
from sqlalchemy import text, Numeric, Column
from sqlalchemy import types as sqltypes
**kw)
-
def autogen_column_reflect(self, inspector, table, column_info):
if column_info.get('default') and \
isinstance(column_info['type'], (INTEGER, BIGINT)):
)
metadata_indexes.discard(idx)
+ def render_type(self, type_, autogen_context):
+ if hasattr(self, '_render_%s_type' % type_.__visit_name__):
+ meth = getattr(self, '_render_%s_type' % type_.__visit_name__)
+ return meth(type_, autogen_context)
+
+ return False
+
+ def _render_ARRAY_type(self, type_, autogen_context):
+ sub_type = render._repr_type(type_.item_type, autogen_context)
+ outer_type = repr(type_).replace(repr(type_.item_type), sub_type)
+ return "%s.%s" % ("postgresql", outer_type)
+
class PostgresqlColumnType(AlterColumn):
:version: 0.9.0
:released:
+ .. change:: 85
+ :tags: bug, postgresql
+ :tickets: 85
+
+ Fixed bug where Postgresql ARRAY type would not render the import prefix
+ for the inner type; additionally, user-defined renderers take place
+ for the inner type as well as the outer type. Pull request courtesy
+ Paul Brackin.
+
.. change:: fk_schema_compare
:tags: bug, operations
from sqlalchemy import DateTime, MetaData, Table, Column, text, Integer, \
String, Interval, Sequence, Numeric, BigInteger, Float, Numeric
-from sqlalchemy.dialects.postgresql import ARRAY, UUID
+from sqlalchemy.dialects.postgresql import ARRAY, UUID, BYTEA
from sqlalchemy.engine.reflection import Inspector
from alembic.operations import Operations
from sqlalchemy.sql import table, column
'nullable=False)'
)
+ @config.requirements.sqlalchemy_09
+ def test_array_type(self):
+
+ eq_ignore_whitespace(
+ autogenerate.render._repr_type(
+ ARRAY(Integer), self.autogen_context),
+ "postgresql.ARRAY(sa.Integer())"
+ )
+
+ eq_ignore_whitespace(
+ autogenerate.render._repr_type(
+ ARRAY(DateTime(timezone=True)), self.autogen_context),
+ "postgresql.ARRAY(sa.DateTime(timezone=True))"
+ )
+
+ eq_ignore_whitespace(
+ autogenerate.render._repr_type(
+ ARRAY(BYTEA, as_tuple=True, dimensions=2),
+ self.autogen_context),
+ "postgresql.ARRAY(postgresql.BYTEA(), as_tuple=True, dimensions=2)"
+ )
+
+ assert 'from sqlalchemy.dialects import postgresql' in \
+ self.autogen_context.imports
+
+ @config.requirements.sqlalchemy_09
+ def test_array_type_user_defined_inner(self):
+ def repr_type(typestring, object_, autogen_context):
+ if typestring == 'type' and isinstance(object_, String):
+ return "foobar.MYVARCHAR"
+ else:
+ return False
+
+ self.autogen_context.opts.update(
+ render_item=repr_type
+ )
+
+ eq_ignore_whitespace(
+ autogenerate.render._repr_type(
+ ARRAY(String), self.autogen_context),
+ "postgresql.ARRAY(foobar.MYVARCHAR)"
+ )