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

17 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 StationmetaAnnotation (Base) 

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

7""" 

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

9 Text, Boolean, CheckConstraint, Table, Sequence, text 

10from sqlalchemy.orm import relationship 

11from toardb.auth_user.models import AuthUser 

12from toardb.base import Base 

13from toardb.generic import models 

14 

15 

16# many-to-many relationships 

17stationmeta_core_stationmeta_annotations_table = Table('stationmeta_core_stationmeta_annotations', Base.metadata, 

18 Column('station_id', Integer, ForeignKey('stationmeta_core.id')), 

19 Column('annotation_id', Integer, ForeignKey('stationmeta_annotations.id')) 

20) 

21 

22 

23STATIONMETA_ANNOTATIONS_ID_SEQ = Sequence('stationmeta_annotations_id_seq') # define sequence explicitly 

24class StationmetaAnnotation(Base): 

25 """ 

26 Table "public.stationmeta_annotations" 

27 

28 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ 

29 | Column | Type | Collation | Nullable | Default | 

30 +================+==========================+===========+==========+========================================================+ 

31 | id | integer | | not null | nextval('stationmeta_annotations_id_seq'::regclass) | 

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

33 | kind | integer | | not null | 0 | 

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

35 | text | text | | not null | | 

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

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

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

39 | approved | boolean | | not null | | 

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

41 | contributor_id | integer | | not null | | 

42 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ 

43 

44 Indexes: 

45 "stationmeta_annotations_pkey" PRIMARY KEY, btree (id) 

46 "stationmeta_annotations_contributor_id_a5009820" btree (contributor_id) 

47 Check constraints: 

48 "stationmeta_annotations_kind_check" CHECK (kind >= 0) 

49 Foreign-key constraints: 

50 "stationmeta_annotations_contributor_id_a5009820_fk_auth_user_id" FOREIGN KEY (contributor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED 

51 "stationmeta_annotations_kind_fk_ak_vocabulary_enum_val" FOREIGN KEY (kind) REFERENCES ak_vocabulary(enum_val) 

52 """ 

53 __tablename__ = 'stationmeta_annotations' 

54 __table_args__ = ( 

55 CheckConstraint('kind >= 0'), 

56 ) 

57 

58 id = Column(Integer, STATIONMETA_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=STATIONMETA_ANNOTATIONS_ID_SEQ.next_value()) 

59 kind = Column(ForeignKey('ak_vocabulary.enum_val'), nullable=False, server_default=text("0::integer")) 

60 text = Column(Text, nullable=False) 

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

62 approved = Column(Boolean, nullable=False) 

63# do not use string declaration here (not working for pytest) 

64# use the explicit class name here, 

65# see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U 

66 contributor_id = Column(ForeignKey(AuthUser.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True) 

67# how to reactivate the following two lines?! 

68# contributor = relationship('AuthUser') 

69 

70 station = relationship("StationmetaCore", 

71 secondary=stationmeta_core_stationmeta_annotations_table, 

72 backref="annotations") 

73