Source code for toardb.contacts.models

# SPDX-FileCopyrightText: 2021 Forschungszentrum Jülich GmbH
# SPDX-License-Identifier: MIT

"""
class Contact(Base)
===================
"""

from toardb.base import Base

from .models_person import Person
from .models_organisation import Organisation

from sqlalchemy import Table, Column, Integer, String, \
                       ForeignKey, text, CheckConstraint, UniqueConstraint, Sequence
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship

# controlled vocabulary

# Kind of Organizations
OK_enum_table = Table("ok_vocabulary",
                Base.metadata,
                Column("enum_val", Integer, primary_key=True),
                Column("enum_str", String),
                Column("enum_display_str", String)
          )

CONTACTS_ID_SEQ = Sequence('contacts_id_seq')  # define sequence explicitly
[docs]class Contact(Base): """ Table "public.contacts" +-----------------+---------+-----------+----------+----------------------------------------+ | Column | Type | Collation | Nullable | Default | +=================+=========+===========+==========+========================================+ | id | integer | | not null | nextval('contacts_id_seq'::regclass) | +-----------------+---------+-----------+----------+----------------------------------------+ | person_id | integer | | | | +-----------------+---------+-----------+----------+----------------------------------------+ | organisation_id | integer | | | | +-----------------+---------+-----------+----------+----------------------------------------+ Indexes: "contacts_pkey" PRIMARY KEY, btree (id) "contacts_person_id_organisation_id" UNIQUE CONSTRAINT, btree (person_id, organisation_id) Foreign-key constraints: "contacts_organisation_id_fkey" FOREIGN KEY (organisation_id) REFERENCES organisations(id) "contacts_person_id_fkey" FOREIGN KEY (person_id) REFERENCES persons(id) Referenced by: TABLE "stationmeta_roles" CONSTRAINT "stationmeta_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED TABLE "timeseries_roles" CONSTRAINT "timeseries_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED """ __tablename__ = 'contacts' __table_args__ = ( UniqueConstraint('person_id', 'organisation_id'), ) id = Column(Integer, CONTACTS_ID_SEQ, primary_key=True, server_default=CONTACTS_ID_SEQ.next_value()) person_id = Column(ForeignKey('persons.id')) organisation_id = Column(ForeignKey('organisations.id')) organisation = relationship('Organisation') person = relationship('Person')