Coverage for toardb/timeseries/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 TimeseriesRole (Base)
6===========================
7"""
8from sqlalchemy import Column, ForeignKey, Integer, text, \
9 CheckConstraint, UniqueConstraint, \
10 Table, Sequence
11from sqlalchemy.orm import relationship
12from toardb.contacts.models import Contact
13from toardb.base import Base
16# many-to-many relationships
17timeseries_timeseries_roles_table = Table('timeseries_timeseries_roles', Base.metadata,
18 Column('timeseries_id', Integer, ForeignKey('timeseries.id')),
19 Column('role_id', Integer, ForeignKey('timeseries_roles.id'))
20)
22TIMESERIES_ROLES_ID_SEQ = Sequence('timeseries_roles_id_seq') # define sequence explicitly
23class TimeseriesRole(Base):
24 """
25 Table "public.timeseries_roles"
27 +---------------+---------+-----------+----------+----------------------------------------------+
28 | Column | Type | Collation | Nullable | Default |
29 +===============+=========+===========+==========+==============================================+
30 | id | integer | | not null | nextval('timeseries_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 "timeseries_roles_pkey" PRIMARY KEY, btree (id)
41 "timeseries_roles_role_status_contact_id_uniq" UNIQUE CONSTRAINT, btree (role, status, contact_id)
42 "timeseries_roles_contact_id" btree (contact_id)
43 Check constraints:
44 "timeseries_roles_role_check" CHECK (role >= 0)
45 "timeseries_roles_status_check" CHECK (status >= 0)
46 Foreign-key constraints:
47 "timeseries_roles_contact_id_fk_contacts_id" FOREIGN KEY (contact_id) REFERENCES contacts(id) DEFERRABLE INITIALLY DEFERRED
48 """
50 __tablename__ = 'timeseries_roles'
51 __table_args__ = (
52 CheckConstraint('role >= 0'),
53 CheckConstraint('status >= 0'),
54 UniqueConstraint('role', 'status', 'contact_id')
55 )
57 id = Column(Integer, TIMESERIES_ROLES_ID_SEQ, primary_key=True, server_default=TIMESERIES_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)
65# rc_vocabulary = relationship('RcVocabulary')
66# rs_vocabulary = relationship('RsVocabulary')
68 timeseries = relationship("Timeseries",
69 secondary=timeseries_timeseries_roles_table,
70 backref="roles")