Newer
Older
# coding: utf-8
"""
class StationmetaChangelog(Base)
================================
"""

Sabine Schröder
committed
from sqlalchemy import Column, DateTime, BigInteger, ForeignKey, String, text, \
Text, CheckConstraint, Table, Sequence
from sqlalchemy.orm import relationship
from .models_core import StationmetaCore
from toardb.auth_user.models import AuthUser
from toardb.base import Base
STATIONMETA_CHANGELOG_ID_SEQ = Sequence('stationmeta_changelog_id_seq') # define sequence explicitly
class StationmetaChangelog(Base):
""" Table "public.stationmeta_changelog"
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| Column | Type | Collation | Nullable | Default |
+================+==========================+===========+==========+========================================================+
| id | bigint | | not null | nextval('stationmeta_changelog_id_seq'::regclass) |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+

Sabine Schröder
committed
| datetime | timestamp with time zone | | not null | now() |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| station_id | bigint | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| type_of_change | integer | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| description | text | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| old_value | character varying(256) | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| new_value | character varying(256) | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| author_id | integer | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
Indexes:
"stationmeta_changelog_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"stationmeta_changelog_author_id_fk_auth_user_id" FOREIGN KEY (author_id) REFERENCES auth_user(id)
"stationmeta_changelog_station_id_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id)
"stationmeta_changelog_type_of_change_fk_cl_vocabulary_enum_val" FOREIGN KEY (type_of_change) REFERENCES cl_vocabulary(enum_val)
"""
__tablename__ = 'stationmeta_changelog'
id = Column(BigInteger, STATIONMETA_CHANGELOG_ID_SEQ, primary_key=True, server_default=STATIONMETA_CHANGELOG_ID_SEQ.next_value())

Sabine Schröder
committed
datetime = Column(DateTime(True), nullable=False, server_default=text("now()"))
description = Column(Text, nullable=False)
old_value = Column(String(256), nullable=False)
new_value = Column(String(256), 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

Sabine Schröder
committed
station_id = Column(ForeignKey(StationmetaCore.id, deferrable=True, initially='DEFERRED'), nullable=False)
author_id = Column(ForeignKey(AuthUser.id), nullable=False)
# still to check for some pytest solution for controlled vocabulary

Sabine Schröder
committed
type_of_change = Column(ForeignKey('cl_vocabulary.enum_val'), nullable=False)
author = relationship('AuthUser')
station = relationship('StationmetaCore')
# cl_vocabulary = relationship('ClVocabulary')