Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding: utf-8
"""
class StationmetaChangelog(Base)
================================
"""
from sqlalchemy import Column, DateTime, BigInteger, ForeignKey, String, \
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) |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| datetime | timestamp with time zone | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| 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())
datetime = Column(DateTime(True), nullable=False)
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
station_id = Column(ForeignKey(StationmetaCore.id), nullable=False)
author_id = Column(ForeignKey(AuthUser.id), nullable=False)
# still to check for some pytest solution for controlled vocabulary
type_of_change = Column(ForeignKey('cl_Vocabulary.enum_val'), nullable=False)
author = relationship('AuthUser')
station = relationship('StationmetaCore')
# cl_vocabulary = relationship('ClVocabulary')