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

27 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 StationmetaCore (Base) 

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

7""" 

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

9 Text, text, CheckConstraint, Sequence 

10from geoalchemy2.types import Geometry 

11from sqlalchemy.orm import relationship 

12from sqlalchemy.dialects.postgresql import JSONB, ARRAY 

13from shapely import wkt 

14from toardb.auth_user.models import AuthUser 

15from toardb.base import Base 

16 

17STATIONMETA_CORE_ID_SEQ = Sequence('stationmeta_core_id_seq') # define sequence explicitly 

18# coordinates are giving problems in nested views (from timeseries -- now try this approach) 

19# ==> unfortunately, there will be no coordinates shown in timeseries nested views 

20# still to be investigated! 

21# ValueError: [ValueError('dictionary update sequence element #0 has length 1; 2 is required',), TypeError('vars() argument must have __dict__ attribute',)] 

22class StationmetaCore(Base): 

23 """ 

24 Table "public.stationmeta_core" 

25 

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

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

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

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

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

31 | codes | character varying(16)[] | | | | 

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

33 | name | character varying(128) | | not null | | 

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

35 | coordinates | geometry(PointZ,4326) | | not null | | 

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

37 | coordinate_validation_status | integer | | not null | 0 | 

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

39 | country | integer | | not null | -1 | 

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

41 | state | character varying(128) | | not null | | 

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

43 | type | integer | | not null | | 

44 +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ 

45 | type_of_area | integer | | not null | | 

46 +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ 

47 | timezone | integer | | not null | 588 | 

48 +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ 

49 | additional_metadata | jsonb | | not null | | 

50 +------------------------------+--------------------------+-----------+----------+----------------------------------------------+ 

51 

52 Indexes: 

53 "stationmeta_core_pkey" PRIMARY KEY, btree (id) 

54 "stationmeta_core_coordinates_id" gist (coordinates gist_geometry_ops_nd) 

55 "stationmeta_core_state_85025a96" btree (state) 

56 "stationmeta_core_state_85025a96_like" btree (state varchar_pattern_ops) 

57 Check constraints: 

58 "stationmeta_core_type_of_area_check" CHECK (type_of_area >= 0) 

59 "stationmeta_core_type_check" CHECK (type >= 0) 

60 "stationmeta_core_coordinate_validation_status_check" CHECK (coordinate_validation_status >= 0) 

61 Foreign-key constraints: 

62 "stationmeta_core_type_of_area_fk_ta_vocabulary_enum_val" FOREIGN KEY (type_of_area) REFERENCES ta_vocabulary(enum_val) 

63 "stationmeta_core_type_fk_st_vocabulary_enum_val" FOREIGN KEY (type) REFERENCES st_vocabulary(enum_val) 

64 "stationmeta_core_country_fk_cn_vocabulary_enum_val" FOREIGN KEY (country) REFERENCES cn_vocabulary(enum_val) 

65 "stationmeta_core_timezone_fk_tz_vocabulary_enum_val" FOREIGN KEY (timezone) REFERENCES tz_vocabulary(enum_val) 

66 Referenced by: 

67 TABLE "station_roles" CONSTRAINT "station_roles_station_id_f31f80fc_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

68 TABLE "stationmeta_annotations" CONSTRAINT "stationmeta_annotati_station_id_9d3fe3d0_fk_stationme" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

69 TABLE "stationmeta_aux_doc" CONSTRAINT "stationmeta_aux_doc_station_id_17bdb5f2_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

70 TABLE "stationmeta_aux_image" CONSTRAINT "stationmeta_aux_imag_station_id_fbfbdb29_fk_stationme" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

71 TABLE "stationmeta_aux_url" CONSTRAINT "stationmeta_aux_url_station_id_727571bd_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

72 TABLE "stationmeta_global" CONSTRAINT "stationmeta_global_station_id_29ff53dd_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

73 TABLE "timeseries" CONSTRAINT "timeseries_station_id_0f4fed9c_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED 

74 """ 

75 

76 __tablename__ = 'stationmeta_core' 

77 __table_args__ = ( 

78 CheckConstraint('type_of_area >= 0'), 

79 CheckConstraint('type >= 0'), 

80 CheckConstraint('coordinate_validation_status >= 0') 

81 ) 

82 

83 id = Column(Integer, STATIONMETA_CORE_ID_SEQ, primary_key=True, server_default=STATIONMETA_CORE_ID_SEQ.next_value()) 

84 codes = Column(ARRAY(String(16))) 

85 name = Column(String(128), nullable=False) 

86 coordinates = Column(Geometry('POINTZ', 4326)) 

87 coordinate_validation_status = Column(ForeignKey('cv_vocabulary.enum_val'), nullable=False, server_default=text("'0'::integer")) 

88 country = Column(ForeignKey('cn_vocabulary.enum_val'), nullable=False) 

89 state = Column(String(128), nullable=False, index=True) 

90 type = Column(ForeignKey('st_vocabulary.enum_val'), nullable=False) 

91 type_of_area = Column(ForeignKey('ta_vocabulary.enum_val'), nullable=False) 

92 timezone = Column(ForeignKey('tz_vocabulary.enum_val'), nullable=False) 

93 additional_metadata = Column(JSONB(astext_type=Text()), nullable=True) 

94 

95 aux_images = relationship('StationmetaAuxImage', back_populates='station') 

96 aux_docs = relationship('StationmetaAuxDoc', back_populates='station') 

97 aux_urls = relationship('StationmetaAuxUrl', back_populates='station') 

98 globalmeta = relationship('StationmetaGlobal', uselist=False, back_populates='station') 

99 changelog = relationship('StationmetaChangelog', back_populates='station') 

100 

101 # for nested view 

102# timeseries = relationship("Timeseries", back_populates="station") 

103# timeseries = relationship("Timeseries") 

104 

105# cv_vocabulary = relationship('CvVocabulary') 

106# ta_vocabulary = relationship('TaVocabulary') 

107# st_vocabulary = relationship('StVocabulary')