1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515# ===============================================================================
16- from sqlalchemy import Column , Integer , ForeignKey , String
16+ from sqlalchemy import Integer , ForeignKey , String
1717from sqlalchemy .ext .associationproxy import association_proxy
18- from sqlalchemy .orm import relationship
18+ from sqlalchemy .orm import relationship , Mapped , mapped_column
1919from sqlalchemy_utils import TSVectorType
20+ from typing import List
2021
2122from db .base import Base , AutoBaseMixin , ReleaseMixin , lexicon_term
2223
2324
2425class ThingContactAssociation (Base , AutoBaseMixin ):
25- thing_id = Column (
26+ thing_id : Mapped [ int ] = mapped_column (
2627 Integer , ForeignKey ("thing.id" , ondelete = "CASCADE" ), nullable = False
2728 )
28- contact_id = Column (
29+ contact_id : Mapped [ int ] = mapped_column (
2930 Integer , ForeignKey ("contact.id" , ondelete = "CASCADE" ), nullable = False
3031 )
3132
32- contact = relationship ("Contact" )
33- thing = relationship ("Thing" )
33+ contact : Mapped [ List [ "Contact" ]] = relationship ("Contact" )
34+ thing : Mapped [ List [ "Thing" ]] = relationship ("Thing" ) # noqa: F821
3435
3536
3637class Contact (Base , AutoBaseMixin , ReleaseMixin ):
37- name = Column (String (100 ), nullable = True )
38- role = lexicon_term (nullable = False )
39- organization = Column (String (100 ), nullable = True )
40- nma_pk_owners = Column (String (100 ), nullable = True )
41-
42- phones = relationship ("Phone" , back_populates = "contact" , passive_deletes = True )
43- emails = relationship ("Email" , back_populates = "contact" , passive_deletes = True )
44- addresses = relationship ("Address" , back_populates = "contact" , passive_deletes = True )
38+ name : Mapped [str | None ] = mapped_column (String (100 ))
39+ organization : Mapped [str | None ] = mapped_column (String (100 ))
40+ role : Mapped [str ] = lexicon_term ()
41+ contact_type : Mapped [str ] = lexicon_term ()
42+ nma_pk_owners : Mapped [str | None ] = mapped_column (String (100 ))
43+
44+ phones : Mapped [List ["Phone" ]] = relationship (
45+ "Phone" , back_populates = "contact" , passive_deletes = True
46+ )
47+ emails : Mapped [List ["Email" ]] = relationship (
48+ "Email" , back_populates = "contact" , passive_deletes = True
49+ )
50+ addresses : Mapped [List ["Address" ]] = relationship (
51+ "Address" , back_populates = "contact" , passive_deletes = True
52+ )
4553
46- search_vector = Column (
54+ search_vector : Mapped [ TSVectorType ] = mapped_column (
4755 TSVectorType ("name" , "role" , "organization" , "nma_pk_owners" )
4856 )
4957
50- author_associations = relationship (
51- "AuthorContactAssociation" ,
52- back_populates = "contact" ,
53- cascade = "all, delete-orphan" ,
58+ author_associations : Mapped [List ["AuthorContactAssociation" ]] = ( # noqa: F821
59+ relationship (
60+ "AuthorContactAssociation" ,
61+ back_populates = "contact" ,
62+ cascade = "all, delete-orphan" ,
63+ )
5464 )
5565 authors = association_proxy ("author_associations" , "author" )
56- thing_associations = relationship (
66+ thing_associations : Mapped [ List [ "ThingContactAssociation" ]] = relationship (
5767 "ThingContactAssociation" ,
5868 back_populates = "contact" ,
5969 cascade = "all, delete-orphan" ,
@@ -63,42 +73,48 @@ class Contact(Base, AutoBaseMixin, ReleaseMixin):
6373
6474
6575class Phone (Base , AutoBaseMixin , ReleaseMixin ):
66- contact_id = Column (
76+ contact_id : Mapped [ int ] = mapped_column (
6777 Integer , ForeignKey ("contact.id" , ondelete = "CASCADE" ), nullable = False
6878 )
69- phone_number = Column (String (20 ), nullable = False )
70- phone_type = lexicon_term (nullable = False )
79+ phone_number : Mapped [ str ] = mapped_column (String (20 ), nullable = False )
80+ phone_type : Mapped [ str ] = lexicon_term (nullable = False )
7181
72- contact = relationship ("Contact" , back_populates = "phones" , passive_deletes = True )
73- search_vector = Column (TSVectorType ("phone_number" ))
82+ contact : Mapped ["Contact" ] = relationship (
83+ "Contact" , back_populates = "phones" , passive_deletes = True
84+ )
85+ search_vector : Mapped [TSVectorType ] = mapped_column (TSVectorType ("phone_number" ))
7486
7587
7688class Email (Base , AutoBaseMixin , ReleaseMixin ):
77- contact_id = Column (
89+ contact_id : Mapped [ int ] = mapped_column (
7890 Integer , ForeignKey ("contact.id" , ondelete = "CASCADE" ), nullable = False
7991 )
80- email = Column (String (100 ), nullable = False )
81- email_type = lexicon_term (nullable = False )
92+ email : Mapped [ str ] = mapped_column (String (100 ), nullable = False )
93+ email_type : Mapped [ str ] = lexicon_term (nullable = False )
8294
83- contact = relationship ("Contact" , back_populates = "emails" , passive_deletes = True )
95+ contact : Mapped ["Contact" ] = relationship (
96+ "Contact" , back_populates = "emails" , passive_deletes = True
97+ )
8498
85- search_vector = Column (TSVectorType ("email" ))
99+ search_vector : Mapped [ TSVectorType ] = mapped_column (TSVectorType ("email" ))
86100
87101
88102class Address (Base , AutoBaseMixin , ReleaseMixin ):
89- contact_id = Column (
103+ contact_id : Mapped [ int ] = mapped_column (
90104 Integer , ForeignKey ("contact.id" , ondelete = "CASCADE" ), nullable = False
91105 )
92- address_line_1 = Column (String (255 ), nullable = False )
93- address_line_2 = Column (String (255 ), nullable = True )
94- city = Column (String (100 ), nullable = False )
95- state = Column (String (50 ), nullable = False )
96- postal_code = Column (String (20 ), nullable = False )
97- country = lexicon_term (nullable = False , default = "United States" )
98- address_type = lexicon_term (nullable = False )
99-
100- contact = relationship ("Contact" , back_populates = "addresses" , passive_deletes = True )
101- search_vector = Column (
106+ address_line_1 : Mapped [str ] = mapped_column (String (255 ), nullable = False )
107+ address_line_2 : Mapped [str | None ] = mapped_column (String (255 ), nullable = True )
108+ city : Mapped [str ] = mapped_column (String (100 ), nullable = False )
109+ state : Mapped [str ] = mapped_column (String (50 ), nullable = False )
110+ postal_code : Mapped [str ] = mapped_column (String (20 ), nullable = False )
111+ country : Mapped [str ] = lexicon_term (nullable = False , default = "United States" )
112+ address_type : Mapped [str ] = lexicon_term (nullable = False )
113+
114+ contact : Mapped ["Contact" ] = relationship (
115+ "Contact" , back_populates = "addresses" , passive_deletes = True
116+ )
117+ search_vector : Mapped [TSVectorType ] = mapped_column (
102118 TSVectorType (
103119 "address_line_1" ,
104120 "address_line_2" ,
0 commit comments