-
Sabine Schröder authored
#7: default values for stationmeta_global were defined; #4: nested upload tested for 'stationmeta_global' (not defining all metadata -- getting the rest from default values)
Sabine Schröder authored#7: default values for stationmeta_global were defined; #4: nested upload tested for 'stationmeta_global' (not defining all metadata -- getting the rest from default values)
models_global.py 9.15 KiB
# coding: utf-8
"""
class StationmetaGlobal (Base)
==============================
"""
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \
Text, text, CheckConstraint, Sequence
from geoalchemy2.types import Geometry
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import JSONB, ARRAY
from .models_core import StationmetaCore
from toardb.base import Base
STATIONMETA_GLOBAL_ID_SEQ = Sequence('stationmeta_global_id_seq') # define sequence explicitly
class StationmetaGlobal(Base):
""" Table "public.stationmeta_global"
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| Column | Type | Collation | Nullable | Default |
+======================================+==================+===========+==========+================================================+
| id | integer | | not null | nextval('stationmeta_global_id_seq'::regclass) |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| population_density_year2010 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| max_population_density_25km_year2010 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| climatic_zone | integer | | not null | '-1'::integer |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| nightlight_1km_year2013 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| nightlight_5km_year2013 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| max_nightlight_25km_year2013 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| wheat_production_year2000 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| rice_production_year2000 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| edgar_htap_v2_nox_emissions_year2010 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| omi_no2_column_years2011to2015 | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| htap_region_tier1 | integer | | not null | '-1'::integer |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| etopo_alt | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| etopo_min_alt_5km | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| etopo_relative_alt | double precision | | not null | '-1.0'::numeric |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| dominant_landcover_year2012 | integer | | not null | '-1'::integer |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| toar1_category | integer | | not null | '-1'::integer |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
| station_id | integer | | not null | |
+--------------------------------------+------------------+-----------+----------+------------------------------------------------+
Indexes:
"stationmeta_global_pkey" PRIMARY KEY, btree (id)
"stationmeta_global_station_id_key" UNIQUE CONSTRAINT, btree (station_id)
Check constraints:
"stationmeta_global_climatic_zone_check" CHECK (climatic_zone >= 0)
"stationmeta_global_dominant_landcover_year2012_check" CHECK (dominant_landcover_year2012 >= 0)
"stationmeta_global_htap_region_tier1_check" CHECK (htap_region_tier1 >= 0)
"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
"""
__tablename__ = 'stationmeta_global'
# Default values do not fit CheckConstraints == > Check, how both can be done!!
# __table_args__ = (
# CheckConstraint('climatic_zone >= 0'),
# CheckConstraint('dominant_landcover_year2012 >= 0'),
# CheckConstraint('htap_region_tier1 >= 0'),
# CheckConstraint('toar1_category >= 0')
# )
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"))
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"))
wheat_production_year2000 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
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"))
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"))
# 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
# station_id = Column(ForeignKey('stationmeta_core.id', deferrable=True, initially='DEFERRED'), nullable=False, unique=True)
station_id = Column(ForeignKey(StationmetaCore.id))
#uselist=False ==> 1:1 relationship
# station = relationship('StationmetaCore', uselist=False)
station = relationship('StationmetaCore', back_populates='globalmeta')