Coverage for toardb/stationmeta/models_changelog.py: 100%
16 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-03 20:32 +0000
« 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
4"""
5class StationmetaChangelog(Base)
6================================
7"""
8from sqlalchemy import Column, DateTime, BigInteger, ForeignKey, String, text, \
9 Text, CheckConstraint, Table, Sequence
10from sqlalchemy.orm import relationship
11from .models_core import StationmetaCore
12from toardb.auth_user.models import AuthUser
13from toardb.base import Base
15class StationmetaChangelog(Base):
16 """
17 Table "public.stationmeta_changelog"
19 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
20 | Column | Type | Collation | Nullable | Default |
21 +================+==========================+===========+==========+========================================================+
22 | datetime | timestamp with time zone | | not null | now() |
23 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
24 | station_id | bigint | | not null | |
25 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
26 | type_of_change | integer | | not null | |
27 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
28 | description | text | | not null | |
29 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
30 | old_value | character varying(256) | | not null | |
31 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
32 | new_value | character varying(256) | | not null | |
33 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
34 | author_id | integer | | not null | |
35 +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
37 Indexes:
38 "stationmeta_changelog_pkey" PRIMARY KEY, btree (datetime)
39 Foreign-key constraints:
40 "stationmeta_changelog_author_id_fk_auth_user_id" FOREIGN KEY (author_id) REFERENCES auth_user(id)
41 "stationmeta_changelog_station_id_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id)
42 "stationmeta_changelog_type_of_change_fk_cl_vocabulary_enum_val" FOREIGN KEY (type_of_change) REFERENCES cl_vocabulary(enum_val)
43 """
44 __tablename__ = 'stationmeta_changelog'
46 datetime = Column(DateTime(True), primary_key=True, nullable=False, server_default=text("now()"))
47 description = Column(Text, nullable=False)
48 old_value = Column(String(256), nullable=False)
49 new_value = Column(String(256), nullable=False)
50# do not use string declaration here (not working for pytest)
51# use the explicit class name here,
52# see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U
53 station_id = Column(ForeignKey(StationmetaCore.id, deferrable=True, initially='DEFERRED'), nullable=False)
54 author_id = Column(ForeignKey(AuthUser.id), nullable=False)
55# still to check for some pytest solution for controlled vocabulary
56 type_of_change = Column(ForeignKey('cl_vocabulary.enum_val'), nullable=False)
58 author = relationship('AuthUser')
59 station = relationship('StationmetaCore')
61# cl_vocabulary = relationship('ClVocabulary')