Coverage for toardb/contacts/models.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-03 20:32 +0000

1# SPDX-FileCopyrightText: 2021 Forschungszentrum Jülich GmbH 

2# SPDX-License-Identifier: MIT 

3 

4""" 

5class Contact(Base) 

6=================== 

7""" 

8 

9from toardb.base import Base 

10 

11from .models_person import Person 

12from .models_organisation import Organisation 

13 

14from sqlalchemy import Table, Column, Integer, String, \ 

15 ForeignKey, text, CheckConstraint, UniqueConstraint, Sequence 

16from sqlalchemy.ext.declarative import declarative_base 

17from sqlalchemy.orm import relationship 

18 

19# controlled vocabulary 

20 

21# Kind of Organizations 

22OK_enum_table = Table("ok_vocabulary", 

23 Base.metadata, 

24 Column("enum_val", Integer, primary_key=True), 

25 Column("enum_str", String), 

26 Column("enum_display_str", String) 

27 ) 

28 

29CONTACTS_ID_SEQ = Sequence('contacts_id_seq') # define sequence explicitly 

30class Contact(Base): 

31 """ 

32 Table "public.contacts" 

33 

34 +-----------------+---------+-----------+----------+----------------------------------------+ 

35 | Column | Type | Collation | Nullable | Default | 

36 +=================+=========+===========+==========+========================================+ 

37 | id | integer | | not null | nextval('contacts_id_seq'::regclass) | 

38 +-----------------+---------+-----------+----------+----------------------------------------+ 

39 | person_id | integer | | | | 

40 +-----------------+---------+-----------+----------+----------------------------------------+ 

41 | organisation_id | integer | | | | 

42 +-----------------+---------+-----------+----------+----------------------------------------+ 

43 

44 Indexes: 

45 "contacts_pkey" PRIMARY KEY, btree (id) 

46 "contacts_person_id_organisation_id" UNIQUE CONSTRAINT, btree (person_id, organisation_id) 

47 Foreign-key constraints: 

48 "contacts_organisation_id_fkey" FOREIGN KEY (organisation_id) REFERENCES organisations(id) 

49 "contacts_person_id_fkey" FOREIGN KEY (person_id) REFERENCES persons(id) 

50 Referenced by: 

51 TABLE "stationmeta_roles" CONSTRAINT "stationmeta_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED 

52 TABLE "timeseries_roles" CONSTRAINT "timeseries_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED 

53 """ 

54 

55 __tablename__ = 'contacts' 

56 __table_args__ = ( 

57 UniqueConstraint('person_id', 'organisation_id'), 

58 ) 

59 

60 id = Column(Integer, CONTACTS_ID_SEQ, primary_key=True, server_default=CONTACTS_ID_SEQ.next_value()) 

61 person_id = Column(ForeignKey('persons.id')) 

62 organisation_id = Column(ForeignKey('organisations.id')) 

63 

64 organisation = relationship('Organisation') 

65 person = relationship('Person') 

66