Coverage for toardb/stationmeta/models_role.py: 100%
15 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-03 20:32 +0000
« 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
4"""
5class StationmetaRole (Base)
6============================
7"""
8from sqlalchemy import Column, ForeignKey, Integer, \
9 CheckConstraint, UniqueConstraint, Table, Sequence
10from sqlalchemy.orm import relationship
11from toardb.contacts.models import Contact
12from toardb.base import Base
15# many-to-many relationships
16stationmeta_core_stationmeta_roles_table = Table('stationmeta_core_stationmeta_roles', Base.metadata,
17 Column('station_id', Integer, ForeignKey('stationmeta_core.id')),
18 Column('role_id', Integer, ForeignKey('stationmeta_roles.id'))
19)
22STATIONMETA_ROLES_ID_SEQ = Sequence('stationmeta_roles_id_seq') # define sequence explicitly
23class StationmetaRole(Base):
24 """
25 Table "public.stationmeta_roles"
27 +------------+---------+-----------+----------+-----------------------------------------------+
28 | Column | Type | Collation | Nullable | Default |
29 +============+=========+===========+==========+===============================================+
30 | id | integer | | not null | nextval('stationmeta_roles_id_seq'::regclass) |
31 +------------+---------+-----------+----------+-----------------------------------------------+
32 | role | integer | | not null | |
33 +------------+---------+-----------+----------+-----------------------------------------------+
34 | status | integer | | not null | |
35 +------------+---------+-----------+----------+-----------------------------------------------+
36 | contact_id | integer | | not null | |
37 +------------+---------+-----------+----------+-----------------------------------------------+
39 Indexes:
40 "stationmeta_roles_pkey" PRIMARY KEY, btree (id)
41 "stationmeta_roles_contact_id_3bd9c160" btree (contact_id)
42 Check constraints:
43 "stationmeta_roles_role_check" CHECK (role >= 0)
44 "stationmeta_roles_status_check" CHECK (status >= 0)
45 Foreign-key constraints:
46 "stationmeta_roles_contact_id_3bd9c160_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED
47 "stationmeta_roles_role_fk_rc_vocabulary_enum_val" FOREIGN KEY (role) REFERENCES rc_vocabulary(enum_val)
48 "stationmeta_roles_status_fk_rs_vocabulary_enum_val" FOREIGN KEY (status) REFERENCES rs_vocabulary(enum_val)
49 """
51 __tablename__ = 'stationmeta_roles'
52 __table_args__ = (
53 CheckConstraint('role >= 0'),
54 CheckConstraint('status >= 0')
55 )
57 id = Column(Integer, STATIONMETA_ROLES_ID_SEQ, primary_key=True, server_default=STATIONMETA_ROLES_ID_SEQ.next_value())
58 role = Column(ForeignKey('rc_vocabulary.enum_val'), nullable=False)
59 status = Column(ForeignKey('rs_vocabulary.enum_val'), nullable=False)
60# do not use string declaration here (not working for pytest)
61# use the explicit class name here,
62# see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U
63 contact_id = Column(ForeignKey(Contact.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True)
64 contact = relationship(Contact)
66 station = relationship("StationmetaCore",
67 secondary=stationmeta_core_stationmeta_roles_table,
68 backref="roles")
70# rc_vocabulary = relationship('RcVocabulary')
71# rs_vocabulary = relationship('RsVocabulary')