Skip to content
Snippets Groups Projects
Commit e034d2a1 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

#3: added unique constraint to controlled vocabularies; added foreign keys...

#3: added unique constraint to controlled vocabularies; added foreign keys (controlled vocabularies) to models
parent c05d84d8
No related branches found
No related tags found
No related merge requests found
Pipeline #40000 passed
......@@ -20,7 +20,8 @@ CREATE TABLE IF NOT EXISTS RC_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT rc_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO RC_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -37,7 +38,8 @@ CREATE TABLE IF NOT EXISTS RS_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT rs_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO RS_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -54,7 +56,8 @@ CREATE TABLE IF NOT EXISTS OK_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT ok_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO OK_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -75,7 +78,8 @@ CREATE TABLE IF NOT EXISTS DA_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT da_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO DA_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -89,7 +93,8 @@ CREATE TABLE IF NOT EXISTS SF_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT sf_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO SF_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -109,7 +114,8 @@ CREATE TABLE IF NOT EXISTS AT_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT at_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO AT_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -127,7 +133,8 @@ CREATE TABLE IF NOT EXISTS DS_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT ds_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO DS_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -140,7 +147,8 @@ CREATE TABLE IF NOT EXISTS MM_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT mm_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO MM_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -157,7 +165,8 @@ CREATE TABLE IF NOT EXISTS CZ_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT cz_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO CZ_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -182,7 +191,8 @@ CREATE TABLE IF NOT EXISTS CV_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT cv_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO CV_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -198,7 +208,8 @@ CREATE TABLE IF NOT EXISTS ST_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT st_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO ST_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -214,7 +225,8 @@ CREATE TABLE IF NOT EXISTS TA_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT ta_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO TA_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -230,14 +242,16 @@ CREATE TABLE IF NOT EXISTS TC_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT tc_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO TC_vocabulary (enum_val, enum_str, enum_display_str) VALUES
(0, 'Unclassified', 'unclassified'),
(1, 'RuralLowElevation', 'rural low elevation'),
(2, 'RuralHighElevation', 'rural high elevation'),
(3, 'Urban', 'urban');
(-1, 'Unknown', 'unknown'),
( 0, 'Unclassified', 'unclassified'),
( 1, 'RuralLowElevation', 'rural low elevation'),
( 2, 'RuralHighElevation', 'rural high elevation'),
( 3, 'Urban', 'urban');
-- Station HTAP Regions (TIER1)
-- The integer denoting the “tier1” region defined in the task force on hemispheric transport of air pollution (TFHTAP) coordinated model studies.
......@@ -246,7 +260,8 @@ CREATE TABLE IF NOT EXISTS TR_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT tr_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO TR_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -276,7 +291,8 @@ CREATE TABLE IF NOT EXISTS DL_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT dl_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO DL_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -306,7 +322,8 @@ CREATE TABLE IF NOT EXISTS RT_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT rt_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO RT_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......@@ -323,7 +340,8 @@ CREATE TABLE IF NOT EXISTS DF_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str)
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT df_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO DF_vocabulary (enum_val, enum_str, enum_display_str) VALUES
......
......@@ -35,6 +35,8 @@ class Organisation(Base):
"organisations_pkey" PRIMARY KEY, btree (id)
Check constraints:
"organisations_kind_check" CHECK (kind >= 0)
Foreign-key constraints:
"organisations_kind_fk_ok_vocabulary_enum_val" FOREIGN KEY (kind) REFERENCES ok_vocabulary(enum_val)
"""
__tablename__ = 'organisations'
__table_args__ = (
......@@ -44,10 +46,11 @@ class Organisation(Base):
id = Column(Integer, ORGANISATIONS_ID_SEQ, primary_key=True, server_default=ORGANISATIONS_ID_SEQ.next_value())
name = Column(String(32), nullable=False)
longname = Column(String(128), nullable=False)
kind = Column(Integer, nullable=False)
kind = Column(ForeignKey('ok_vocabulary.enum_val'), nullable=False)
city = Column(String(64), nullable=False)
postcode = Column(String(16), nullable=False)
street_address = Column(String(128), nullable=False)
country = Column(String(64), nullable=False)
homepage = Column(String(200), nullable=False)
# ok_vocabulary = relationship('OkVocabulary')
......@@ -31,8 +31,9 @@ class Data(Base):
"data_value_idx" btree (value)
Check constraints:
"data_flags_check" CHECK (flags >= 0)
Foreign-key constraints:
"data_timeseries_id_fkey" FOREIGN KEY (timeseries_id) REFERENCES timeseries(id)
Foreign-key constraints:
"data_flags_fk_df_vocabulary_enum_val" FOREIGN KEY (flags) REFERENCES df_vocabulary(enum_val)
"data_timeseries_id_a38c5a1a_fk_timeseries_id" FOREIGN KEY (timeseries_id) REFERENCES timeseries(id) DEFERRABLE INITIALLY DEFERRED
"""
__tablename__ = 'data'
......@@ -42,7 +43,7 @@ class Data(Base):
datetime = Column(DateTime(True), nullable=False, index=True)
value = Column(Float(53), nullable=False, index=True)
flags = Column(Integer, nullable=False)
flags = Column(ForeignKey('df_vocabulary.enum_val'), 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
......
......@@ -61,6 +61,9 @@ class StationmetaCore(Base):
"stationmeta_core_type_of_environment_check" CHECK (type_of_environment >= 0)
Foreign-key constraints:
"stationmeta_core_coordinate_validator_38c0ef8d_fk_auth_user" FOREIGN KEY (coordinate_validator_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
"stationmeta_core_coord_valid_status_fk_cv_vocabulary_enum_val" FOREIGN KEY (coordinate_validation_status) REFERENCES cv_vocabulary(enum_val)
"stationmeta_core_type_of_area_fk_ta_vocabulary_enum_val" FOREIGN KEY (type_of_area) REFERENCES ta_vocabulary(enum_val)
"stationmeta_core_type_of_environment_fk_st_vocabulary_enum_val" FOREIGN KEY (type_of_environment) REFERENCES st_vocabulary(enum_val)
Referenced by:
TABLE "station_roles" CONSTRAINT "station_roles_station_id_f31f80fc_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED
TABLE "stationmeta_annotations" CONSTRAINT "stationmeta_annotati_station_id_9d3fe3d0_fk_stationme" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED
......@@ -84,10 +87,10 @@ class StationmetaCore(Base):
coordinates = Column(Geometry('POINTZ', 4326))
country = Column(String(128), nullable=False, index=True)
state = Column(String(128), nullable=False, index=True)
coordinate_validation_status = Column(Integer, nullable=False)
coordinate_validation_status = Column(ForeignKey('cv_vocabulary.enum_val'), nullable=False)
coordinate_validation_date = Column(DateTime(True), nullable=False)
type_of_environment = Column(Integer, nullable=False)
type_of_area = Column(Integer, nullable=False)
type_of_environment = Column(ForeignKey('st_vocabulary.enum_val'), nullable=False)
type_of_area = Column(ForeignKey('ta_vocabulary.enum_val'), nullable=False)
category = Column(String(128), nullable=False)
timezone = Column(String(64), nullable=False)
additional_metadata = Column(JSONB(astext_type=Text()), nullable=True)
......@@ -101,3 +104,6 @@ class StationmetaCore(Base):
globalmeta = relationship('StationmetaGlobal', uselist=False, back_populates='station')
globalservice = relationship('StationmetaGlobalService', uselist=False, back_populates='station')
# cv_vocabulary = relationship('CvVocabulary')
# ta_vocabulary = relationship('TaVocabulary')
# st_vocabulary = relationship('StVocabulary')
......@@ -64,6 +64,10 @@ class StationmetaGlobal(Base):
"stationmeta_global_toar1_category_check" CHECK (toar1_category >= 0)
Foreign-key constraints:
"stationmeta_global_station_id_29ff53dd_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED
"stationmeta_glob_dominant_landcover_year2012_fk_dl_voc_enum_val" FOREIGN KEY (dominant_landcover_year2012) REFERENCES dl_vocabulary(enum_val)
"stationmeta_global_climatic_zone_fk_cz_at_vocabulary_enum_val" FOREIGN KEY (climatic_zone) REFERENCES cz_vocabulary(enum_val)
"stationmeta_global_htap_region_tier1_fk_tr_vocabulary_enum_val" FOREIGN KEY (htap_region_tier1) REFERENCES tr_vocabulary(enum_val)
"stationmeta_global_toar1_category_fk_tc_vocabulary_enum_val" FOREIGN KEY (toar1_category) REFERENCES tc_vocabulary(enum_val)
"""
__tablename__ = 'stationmeta_global'
# Default values do not fit CheckConstraints == > Check, how both can be done!!
......@@ -77,7 +81,7 @@ class StationmetaGlobal(Base):
id = Column(Integer, STATIONMETA_GLOBAL_ID_SEQ, primary_key=True, server_default=STATIONMETA_GLOBAL_ID_SEQ.next_value())
population_density_year2010 = Column(Float(53), nullable=False, server_default=text("'-1.0'::numeric"))
max_population_density_25km_year2010 = Column(Float(53), nullable=False, server_default=text("'-1.0'::numeric"))
climatic_zone = Column(Integer, nullable=False, server_default=text("'-1'::integer"))
climatic_zone = Column(ForeignKey('cz_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
nightlight_1km_year2013 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
nightlight_5km_year2013 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
max_nightlight_25km_year2013 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
......@@ -85,12 +89,12 @@ class StationmetaGlobal(Base):
rice_production_year2000 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
edgar_htap_v2_nox_emissions_year2010 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
omi_no2_column_years2011to2015 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
htap_region_tier1 = Column(Integer, nullable=False, server_default=text("'-1'::integer"))
htap_region_tier1 = Column(ForeignKey('tr_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
etopo_alt = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
etopo_min_alt_5km = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
etopo_relative_alt = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
dominant_landcover_year2012 = Column(Integer, nullable=False, server_default=text("'-1'::integer"))
toar1_category = Column(Integer, nullable=False, server_default=text("'-1'::integer"))
dominant_landcover_year2012 = Column(ForeignKey('dl_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
toar1_category = Column(ForeignKey('tc_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
# 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
......@@ -100,3 +104,9 @@ class StationmetaGlobal(Base):
#uselist=False ==> 1:1 relationship
# station = relationship('StationmetaCore', uselist=False)
station = relationship('StationmetaCore', back_populates='globalmeta')
# cz_vocabulary = relationship('CzVocabulary')
# dl_vocabulary = relationship('DlVocabulary')
# tr_vocabulary = relationship('TrVocabulary')
# tc_vocabulary = relationship('TcVocabulary')
......@@ -35,6 +35,9 @@ class StationmetaGlobalService(Base):
"stationmeta_global_services_result_nvalues_check" CHECK (result_nvalues >= 0)
"stationmeta_global_services_result_type_check" CHECK (result_type >= 0)
"stationmeta_global_services_service_valid_year_check" CHECK (service_valid_year >= 0)
Foreign-key constraints:
"stationmeta_global_services_result_type_fk_rt_voc_enum_val" FOREIGN KEY (result_type) REFERENCES rt_vocabulary(enum_val)
"stationmeta_global_services_station_id_fkey" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id)
"""
__tablename__ = 'stationmeta_global_services'
......@@ -46,10 +49,12 @@ class StationmetaGlobalService(Base):
id = Column(Integer, STATIONMETA_GLOBAL_SERVICES_ID_SEQ, primary_key=True, server_default=STATIONMETA_GLOBAL_SERVICES_ID_SEQ.next_value())
variable_name = Column(String(64), nullable=False)
result_type = Column(Integer, nullable=False)
result_type = Column(ForeignKey('rt_vocabulary.enum_val'), nullable=False)
result_nvalues = Column(Integer, nullable=False)
service_valid_year = Column(Integer)
service_url = Column(String(200), nullable=False, unique=True)
station_id = Column(ForeignKey(StationmetaCore.id))
station = relationship('StationmetaCore', back_populates='globalservice')
# rt_vocabulary = relationship('RtVocabulary')
......@@ -40,6 +40,8 @@ class StationmetaRole(Base):
"stationmeta_roles_status_check" CHECK (status >= 0)
Foreign-key constraints:
"stationmeta_roles_person_id_3bd9c160_fk_persons_id" FOREIGN KEY (person_id) REFERENCES persons(id) DEFERRABLE INITIALLY DEFERRED
"stationmeta_roles_role_fk_rc_vocabulary_enum_val" FOREIGN KEY (role) REFERENCES rc_vocabulary(enum_val)
"stationmeta_roles_status_fk_rs_vocabulary_enum_val" FOREIGN KEY (status) REFERENCES rs_vocabulary(enum_val)
"""
__tablename__ = 'stationmeta_roles'
......@@ -49,8 +51,8 @@ class StationmetaRole(Base):
)
id = Column(Integer, STATIONMETA_ROLES_ID_SEQ, primary_key=True, server_default=STATIONMETA_ROLES_ID_SEQ.next_value())
role = Column(Integer, nullable=False)
status = Column(Integer, nullable=False)
role = Column(ForeignKey('rc_vocabulary.enum_val'), nullable=False)
status = Column(ForeignKey('rs_vocabulary.enum_val'), 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
......@@ -62,3 +64,5 @@ class StationmetaRole(Base):
secondary=stationmeta_core_stationmeta_roles_table,
backref="roles")
# rc_vocabulary = relationship('RcVocabulary')
# rs_vocabulary = relationship('RsVocabulary')
......@@ -77,3 +77,16 @@ DS_enum = (
Enumdict(1, 'Measurement', 'measurement')
)
# Measurement Methods
MM_enum_table = Table("mm_vocabulary",
Base.metadata,
Column("enum_val", Integer, primary_key=True),
Column("enum_str", String),
Column("enum_display_str", String)
)
# The following code is just a workaround (see stationmeta/models.py):
MM_enum = (
Enumdict(0, 'UVAbsorption', 'UV absorption'),
Enumdict(1, 'UnknownInstrument', 'unknown instrument')
)
......@@ -37,7 +37,7 @@ class Timeseries(Base):
+---------------------+--------------------------+-----------+----------+----------------------------------------+
| data_end_date | timestamp with time zone | | not null | |
+---------------------+--------------------------+-----------+----------+----------------------------------------+
| measurement_method | character varying(128) | | not null | |
| measurement_method | integer | | not null | 1 |
+---------------------+--------------------------+-----------+----------+----------------------------------------+
| sampling_height | double precision | | not null | |
+---------------------+--------------------------+-----------+----------+----------------------------------------+
......@@ -63,7 +63,12 @@ class Timeseries(Base):
"timeseries_sampling_frequency_check" CHECK (sampling_frequency >= 0)
Foreign-key constraints:
"timeseries_station_id_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED
"timeseries_variable_id_fk_variables_id" FOREIGN KEY (variable_id) REFERENCES variables(id) DEFERRABLE INITIALLY DEFERRED
"timeseries_variable_id_fk_variables_id" FOREIGN KEY (variable_id) REFERENCES variables(id) DEFERRABLE INITIALLY DEFERREDForeign-key constraints:
"timeseries_access_rights_fk_da_vocabulary_enum_val" FOREIGN KEY (access_rights) REFERENCES da_vocabulary(enum_val)
"timeseries_aggregation_fk_at_vocabulary_enum_val" FOREIGN KEY (aggregation) REFERENCES at_vocabulary(enum_val)
"timeseries_measurement_method_fk_mm_vocabulary_enum_val" FOREIGN KEY (measurement_method) REFERENCES mm_vocabulary(enum_val)
"timeseries_sampling_frequency_fk_sf_vocabulary_enum_val" FOREIGN KEY (sampling_frequency) REFERENCES sf_vocabulary(enum_val)
"timeseries_source_fk_ds_vocabulary_enum_val" FOREIGN KEY (source) REFERENCES ds_vocabulary(enum_val)
Referenced by:
TABLE "data" CONSTRAINT "data_timeseries_id_fk_timeseries_id" FOREIGN KEY (timeseries_id) REFERENCES timeseries(id) DEFERRABLE INITIALLY DEFERRED
TABLE "timeseries_timeseries_annotations" CONSTRAINT "timeseries_timeseries_annotations_timeseries_id_fk_timeseries_id" FOREIGN KEY (timeseries_id) REFERENCES timeseries(id) DEFERRABLE INITIALLY DEFERRED
......@@ -83,13 +88,13 @@ class Timeseries(Base):
id = Column(Integer, TIMESERIES_ID_SEQ, primary_key=True, server_default=TIMESERIES_ID_SEQ.next_value())
label = Column(String(128), nullable=False)
order = Column(Integer, nullable=False)
access_rights = Column(Integer, nullable=False)
sampling_frequency = Column(Integer, nullable=False)
aggregation = Column(Integer, nullable=False)
source = Column(Integer, nullable=False, server_default=text("1"))
access_rights = Column(ForeignKey('da_vocabulary.enum_val'), nullable=False)
sampling_frequency = Column(ForeignKey('sf_vocabulary.enum_val'), nullable=False)
aggregation = Column(ForeignKey('at_vocabulary.enum_val'), nullable=False)
source = Column(ForeignKey('ds_vocabulary.enum_val'), nullable=False, server_default=text("1"))
data_start_date = Column(DateTime(True), nullable=False)
data_end_date = Column(DateTime(True), nullable=False)
measurement_method = Column(String(128), nullable=False)
measurement_method = Column(ForeignKey('mm_vocabulary.enum_val'), nullable=False, server_default=text("1"))
sampling_height = Column(Float(53), nullable=False)
additional_metadata = Column(JSONB(astext_type=Text()), nullable=True)
date_added = Column(DateTime(True), nullable=False, server_default=text("now()"))
......@@ -99,7 +104,12 @@ class Timeseries(Base):
# see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U
station_id = Column(ForeignKey(StationmetaCore.id, deferrable=True, initially='DEFERRED'), index=True)
variable_id = Column(ForeignKey(Variable.id, deferrable=True, initially='DEFERRED'), index=True)
# how to reactivate the following two lines?!
# how to reactivate the following lines?!
# station = relationship('StationmetaCore')
# variable = relationship('Variable')
# da_vocabulary = relationship('DaVocabulary')
# at_vocabulary = relationship('AtVocabulary')
# mm_vocabulary = relationship('MmVocabulary')
# sf_vocabulary = relationship('SfVocabulary')
# ds_vocabulary = relationship('DsVocabulary')
......@@ -51,13 +51,15 @@ class TimeseriesRole(Base):
)
id = Column(Integer, TIMESERIES_ROLES_ID_SEQ, primary_key=True, server_default=TIMESERIES_ROLES_ID_SEQ.next_value())
role = Column(Integer, nullable=False)
status = Column(Integer, nullable=False)
role = Column(ForeignKey('rc_vocabulary.enum_val'), nullable=False)
status = Column(ForeignKey('rs_vocabulary.enum_val'), 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
person_id = Column(ForeignKey(Person.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True)
person = relationship(Person)
# person = relationship(Person)
# rc_vocabulary = relationship('RcVocabulary')
# rs_vocabulary = relationship('RsVocabulary')
timeseries = relationship("Timeseries",
secondary=timeseries_timeseries_roles_table,
......
......@@ -9,7 +9,7 @@ from typing import List
from pydantic import BaseModel, Json, validator
import datetime as dt
from toardb.generic.models import RS_enum, RC_enum
from .models import DA_enum, SF_enum, AT_enum, DS_enum
from .models import DA_enum, SF_enum, AT_enum, DS_enum, MM_enum
# ======== Timeseries =========
......@@ -47,6 +47,10 @@ class TimeseriesCoreBase(BaseModel):
def check_source(cls, v):
return tuple(filter(lambda x: x.value == int(v), DS_enum))[0].string
@validator('measurement_method')
def check_measurement_method(cls, v):
return tuple(filter(lambda x: x.value == int(v), MM_enum))[0].string
class TimeseriesCoreCreate(TimeseriesCoreBase):
pass
......@@ -79,6 +83,12 @@ class TimeseriesCoreCreate(TimeseriesCoreBase):
else:
raise ValueError(f"data source not known: {v}")
@validator('measurement_method')
def check_measurement_method(cls, v):
if tuple(filter(lambda x: x.string == v, MM_enum)):
return v
else:
raise ValueError(f"measurement method not known: {v}")
class TimeseriesCore(TimeseriesCoreBase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment