Coverage for toardb/timeseries/models_annotation.py: 100%

16 statements  

« 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 

3 

4""" 

5class TimeseriesAnnotation(Base) 

6================================ 

7""" 

8from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, text, String, \ 

9 Text, Boolean, CheckConstraint, Table, Sequence 

10from sqlalchemy.orm import relationship 

11from toardb.auth_user.models import AuthUser 

12from toardb.base import Base 

13 

14# many-to-many relationships 

15timeseries_timeseries_annotations_table = Table('timeseries_timeseries_annotations', Base.metadata, 

16 Column('timeseries_id', Integer, ForeignKey('timeseries.id')), 

17 Column('annotation_id', Integer, ForeignKey('timeseries_annotations.id')) 

18) 

19 

20 

21TIMESERIES_ANNOTATIONS_ID_SEQ = Sequence('timeseries_annotations_id_seq') # define sequence explicitly 

22class TimeseriesAnnotation(Base): 

23 """ 

24 Table "public.timeseries_annotations" 

25 

26 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

27 | Column | Type | Collation | Nullable | Default | 

28 +================+==========================+===========+==========+====================================================+ 

29 | id | integer | | not null | nextval('timeseries_annotations_id_seq'::regclass) | 

30 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

31 | kind | integer | | not null | | 

32 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

33 | text | text | | not null | | 

34 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

35 | date_added | timestamp with time zone | | not null | | 

36 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

37 | approved | boolean | | not null | | 

38 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

39 | contributor_id | integer | | not null | | 

40 +----------------+--------------------------+-----------+----------+----------------------------------------------------+ 

41 

42 Indexes: 

43 "timeseries_annotations_pkey" PRIMARY KEY, btree (id) 

44 "timeseries_annotations_contributor_id_7a1758f6" btree (contributor_id) 

45 Check constraints: 

46 "timeseries_annotations_kind_check" CHECK (kind >= 0) 

47 Foreign-key constraints: 

48 "timeseries_annotations_contributor_id_7a1758f6_fk_auth_user_id" FOREIGN KEY (contributor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED 

49 """ 

50 __tablename__ = 'timeseries_annotations' 

51 __table_args__ = ( 

52 CheckConstraint('kind >= 0'), 

53 ) 

54 

55 id = Column(Integer, TIMESERIES_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=TIMESERIES_ANNOTATIONS_ID_SEQ.next_value()) 

56 kind = Column(Integer, nullable=False) 

57 text = Column(Text, nullable=False) 

58 date_added = Column(DateTime(True), nullable=False) 

59 approved = Column(Boolean, 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 contributor_id = Column(ForeignKey(AuthUser.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True) 

64# how to reactivate the following two lines?! 

65# contributor = relationship('AuthUser') 

66# timeseries = relationship('Timeseries') 

67 

68 timeseries = relationship("Timeseries", 

69 secondary=timeseries_timeseries_annotations_table, 

70 backref="annotations") 

71