diff --git a/sqlalchemy_utils/types/__init__.py b/sqlalchemy_utils/types/__init__.py index 5586b7c..5cf5c49 100644 --- a/sqlalchemy_utils/types/__init__.py +++ b/sqlalchemy_utils/types/__init__.py @@ -1,6 +1,7 @@ from functools import wraps from sqlalchemy.orm.collections import InstrumentedList as _InstrumentedList from sqlalchemy import types +from sqlalchemy.dialects.postgresql.base import ischema_names from .color import ColorType from .email import EmailType from .ip_address import IPAddressType @@ -37,6 +38,9 @@ class TSVectorType(types.UserDefinedType): return 'tsvector' +ischema_names['tsvector'] = TSVectorType + + class InstrumentedList(_InstrumentedList): """Enhanced version of SQLAlchemy InstrumentedList. Provides some additional functionality.""" diff --git a/tests/test_tsvector_type.py b/tests/test_tsvector_type.py index b6b4b76..cfcfbb6 100644 --- a/tests/test_tsvector_type.py +++ b/tests/test_tsvector_type.py @@ -4,6 +4,8 @@ from tests import TestCase class TestTSVector(TestCase): + dns = 'postgres://postgres@localhost/sqlalchemy_utils_test' + def create_models(self): class User(self.Base): __tablename__ = 'user' @@ -18,3 +20,13 @@ class TestTSVector(TestCase): def test_generates_table(self): assert 'search_index' in self.User.__table__.c + + def test_type_autoloading(self): + reflected_metadata = sa.schema.MetaData() + table = sa.schema.Table( + 'user', + reflected_metadata, + autoload=True, + autoload_with=self.engine + ) + assert isinstance(table.c['search_index'].type, TSVectorType)