77
88from sqlalchemy import JSON , Computed , Index , String , UniqueConstraint
99from sqlalchemy .dialects .postgresql import TSVECTOR
10- from sqlalchemy .orm import Mapped , declared_attr , mapped_column , relationship
10+ from sqlalchemy .orm import Mapped , mapped_column , relationship
1111from sqlalchemy_utils import ChoiceType
1212
1313from syncmaster .db .mixins import ResourceMixin , TimestampMixin
@@ -33,6 +33,11 @@ class ConnectionType(StrEnum):
3333
3434
3535class Connection (Base , ResourceMixin , TimestampMixin ):
36+ __table_args__ = (
37+ UniqueConstraint ("name" , "group_id" ),
38+ Index ("idx_connection_search_vector" , "search_vector" , postgresql_using = "gin" ),
39+ )
40+
3641 type : Mapped [ConnectionType ] = mapped_column (ChoiceType (ConnectionType , impl = String (32 )), nullable = False )
3742 data : Mapped [dict [str , Any ]] = mapped_column (JSON , nullable = False , default = {})
3843
@@ -71,10 +76,3 @@ class Connection(Base, ResourceMixin, TimestampMixin):
7176
7277 def __repr__ (self ):
7378 return f"<Connection name={ self .name } description={ self .description } group_id={ self .group_id } >"
74-
75- @declared_attr
76- def __table_args__ (cls ) -> tuple :
77- return (
78- UniqueConstraint ("name" , "group_id" ),
79- Index ("idx_connection_search_vector" , "search_vector" , postgresql_using = "gin" ),
80- )
0 commit comments