Source code for toardb.timeseries.models_annotation

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

"""
class TimeseriesAnnotation(Base)
================================
"""
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, text, String, \
                       Text, Boolean, CheckConstraint, Table, Sequence
from sqlalchemy.orm import relationship
from toardb.auth_user.models import AuthUser
from toardb.base import Base

# many-to-many relationships
timeseries_timeseries_annotations_table = Table('timeseries_timeseries_annotations', Base.metadata,
    Column('timeseries_id', Integer, ForeignKey('timeseries.id')),
    Column('annotation_id', Integer, ForeignKey('timeseries_annotations.id'))
)


TIMESERIES_ANNOTATIONS_ID_SEQ = Sequence('timeseries_annotations_id_seq')  # define sequence explicitly
[docs]class TimeseriesAnnotation(Base): """ Table "public.timeseries_annotations" +----------------+--------------------------+-----------+----------+----------------------------------------------------+ | Column | Type | Collation | Nullable | Default | +================+==========================+===========+==========+====================================================+ | id | integer | | not null | nextval('timeseries_annotations_id_seq'::regclass) | +----------------+--------------------------+-----------+----------+----------------------------------------------------+ | kind | integer | | not null | | +----------------+--------------------------+-----------+----------+----------------------------------------------------+ | text | text | | not null | | +----------------+--------------------------+-----------+----------+----------------------------------------------------+ | date_added | timestamp with time zone | | not null | | +----------------+--------------------------+-----------+----------+----------------------------------------------------+ | approved | boolean | | not null | | +----------------+--------------------------+-----------+----------+----------------------------------------------------+ | contributor_id | integer | | not null | | +----------------+--------------------------+-----------+----------+----------------------------------------------------+ Indexes: "timeseries_annotations_pkey" PRIMARY KEY, btree (id) "timeseries_annotations_contributor_id_7a1758f6" btree (contributor_id) Check constraints: "timeseries_annotations_kind_check" CHECK (kind >= 0) Foreign-key constraints: "timeseries_annotations_contributor_id_7a1758f6_fk_auth_user_id" FOREIGN KEY (contributor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED """ __tablename__ = 'timeseries_annotations' __table_args__ = ( CheckConstraint('kind >= 0'), ) id = Column(Integer, TIMESERIES_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=TIMESERIES_ANNOTATIONS_ID_SEQ.next_value()) kind = Column(Integer, nullable=False) text = Column(Text, nullable=False) date_added = Column(DateTime(True), nullable=False) approved = Column(Boolean, 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 contributor_id = Column(ForeignKey(AuthUser.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True) # how to reactivate the following two lines?! # contributor = relationship('AuthUser') # timeseries = relationship('Timeseries') timeseries = relationship("Timeseries", secondary=timeseries_timeseries_annotations_table, backref="annotations")