Source code for toardb.stationmeta.models_role

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

"""
class StationmetaRole (Base)
============================
"""
from sqlalchemy import Column, ForeignKey, Integer, \
                       CheckConstraint, UniqueConstraint, Table, Sequence
from sqlalchemy.orm import relationship
from toardb.contacts.models import Contact
from toardb.base import Base


# many-to-many relationships
stationmeta_core_stationmeta_roles_table = Table('stationmeta_core_stationmeta_roles', Base.metadata,
    Column('station_id', Integer, ForeignKey('stationmeta_core.id')),
    Column('role_id', Integer, ForeignKey('stationmeta_roles.id'))
)


STATIONMETA_ROLES_ID_SEQ = Sequence('stationmeta_roles_id_seq')  # define sequence explicitly
[docs]class StationmetaRole(Base): """ Table "public.stationmeta_roles" +------------+---------+-----------+----------+-----------------------------------------------+ | Column | Type | Collation | Nullable | Default | +============+=========+===========+==========+===============================================+ | id | integer | | not null | nextval('stationmeta_roles_id_seq'::regclass) | +------------+---------+-----------+----------+-----------------------------------------------+ | role | integer | | not null | | +------------+---------+-----------+----------+-----------------------------------------------+ | status | integer | | not null | | +------------+---------+-----------+----------+-----------------------------------------------+ | contact_id | integer | | not null | | +------------+---------+-----------+----------+-----------------------------------------------+ Indexes: "stationmeta_roles_pkey" PRIMARY KEY, btree (id) "stationmeta_roles_contact_id_3bd9c160" btree (contact_id) Check constraints: "stationmeta_roles_role_check" CHECK (role >= 0) "stationmeta_roles_status_check" CHECK (status >= 0) Foreign-key constraints: "stationmeta_roles_contact_id_3bd9c160_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED "stationmeta_roles_role_fk_rc_vocabulary_enum_val" FOREIGN KEY (role) REFERENCES rc_vocabulary(enum_val) "stationmeta_roles_status_fk_rs_vocabulary_enum_val" FOREIGN KEY (status) REFERENCES rs_vocabulary(enum_val) """ __tablename__ = 'stationmeta_roles' __table_args__ = ( CheckConstraint('role >= 0'), CheckConstraint('status >= 0') ) id = Column(Integer, STATIONMETA_ROLES_ID_SEQ, primary_key=True, server_default=STATIONMETA_ROLES_ID_SEQ.next_value()) role = Column(ForeignKey('rc_vocabulary.enum_val'), nullable=False) status = Column(ForeignKey('rs_vocabulary.enum_val'), nullable=False) # do not use string declaration here (not working for pytest) # use the explicit class name here, # see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U contact_id = Column(ForeignKey(Contact.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True) contact = relationship(Contact) station = relationship("StationmetaCore", secondary=stationmeta_core_stationmeta_roles_table, backref="roles")
# rc_vocabulary = relationship('RcVocabulary') # rs_vocabulary = relationship('RsVocabulary')