Source code for toardb.stationmeta.models_annotation

# SPDX-FileCopyrightText: 2021 Forschungszentrum Jülich GmbH
# SPDX-License-Identifier: MIT

"""
class StationmetaAnnotation (Base)
==================================
"""
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \
                       Text, Boolean, CheckConstraint, Table, Sequence, text
from sqlalchemy.orm import relationship
from toardb.auth_user.models import AuthUser
from toardb.base import Base
from toardb.generic import models


# many-to-many relationships
stationmeta_core_stationmeta_annotations_table = Table('stationmeta_core_stationmeta_annotations', Base.metadata,
    Column('station_id', Integer, ForeignKey('stationmeta_core.id')),
    Column('annotation_id', Integer, ForeignKey('stationmeta_annotations.id'))
)


STATIONMETA_ANNOTATIONS_ID_SEQ = Sequence('stationmeta_annotations_id_seq')  # define sequence explicitly
[docs]class StationmetaAnnotation(Base): """ Table "public.stationmeta_annotations" +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | Column | Type | Collation | Nullable | Default | +================+==========================+===========+==========+========================================================+ | id | integer | | not null | nextval('stationmeta_annotations_id_seq'::regclass) | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | kind | integer | | not null | 0 | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | text | text | | not null | | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | date_added | timestamp with time zone | | not null | | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | approved | boolean | | not null | | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ | contributor_id | integer | | not null | | +----------------+--------------------------+-----------+----------+--------------------------------------------------------+ Indexes: "stationmeta_annotations_pkey" PRIMARY KEY, btree (id) "stationmeta_annotations_contributor_id_a5009820" btree (contributor_id) Check constraints: "stationmeta_annotations_kind_check" CHECK (kind >= 0) Foreign-key constraints: "stationmeta_annotations_contributor_id_a5009820_fk_auth_user_id" FOREIGN KEY (contributor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED "stationmeta_annotations_kind_fk_ak_vocabulary_enum_val" FOREIGN KEY (kind) REFERENCES ak_vocabulary(enum_val) """ __tablename__ = 'stationmeta_annotations' __table_args__ = ( CheckConstraint('kind >= 0'), ) id = Column(Integer, STATIONMETA_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=STATIONMETA_ANNOTATIONS_ID_SEQ.next_value()) kind = Column(ForeignKey('ak_vocabulary.enum_val'), nullable=False, server_default=text("0::integer")) text = Column(Text, nullable=False) date_added = Column(DateTime(True), nullable=False) approved = Column(Boolean, 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 contributor_id = Column(ForeignKey(AuthUser.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True) # how to reactivate the following two lines?! # contributor = relationship('AuthUser') station = relationship("StationmetaCore", secondary=stationmeta_core_stationmeta_annotations_table, backref="annotations")