Skip to content
Snippets Groups Projects
Commit 870ac743 authored by Sabine Schröder's avatar Sabine Schröder
Browse files

#7: controlled vocabulary for kind of annotation was introduced (changes in...

#7: controlled vocabulary for kind of annotation was introduced (changes in crud.py and schemas.py to be found in commit for #17)
parent a3f62ebd
No related branches found
No related tags found
No related merge requests found
Pipeline #48007 passed with warnings
...@@ -47,6 +47,26 @@ INSERT INTO RS_vocabulary (enum_val, enum_str, enum_display_str) VALUES ...@@ -47,6 +47,26 @@ INSERT INTO RS_vocabulary (enum_val, enum_str, enum_display_str) VALUES
(1, 'inactive', 'inactive'), (1, 'inactive', 'inactive'),
(2, 'unknown', 'unknown'); (2, 'unknown', 'unknown');
-- Annotation
-- ==========
-- Kind of Annotation
CREATE TABLE IF NOT EXISTS AK_vocabulary (
enum_val INT NOT NULL,
enum_str character varying(128) NOT NULL,
enum_display_str character varying(128) NOT NULL,
PRIMARY KEY(enum_val, enum_str),
CONSTRAINT ak_enum_val_unique UNIQUE (enum_val)
);
INSERT INTO AK_vocabulary (enum_val, enum_str, enum_display_str) VALUES
(0, 'User', 'user comment'),
(1, 'Provider', 'provider comment');
-- Contacts -- Contacts
-- ======== -- ========
......
...@@ -5,6 +5,8 @@ from toardb.base import Base ...@@ -5,6 +5,8 @@ from toardb.base import Base
# controlled vocabulary # controlled vocabulary
## Roles
# Role Status # Role Status
RS_enum_table = Table("rs_vocabulary", RS_enum_table = Table("rs_vocabulary",
Base.metadata, Base.metadata,
...@@ -58,3 +60,20 @@ CL_enum = ( ...@@ -58,3 +60,20 @@ CL_enum = (
Enumdict(6, 'Flagging', 'data value flagging') Enumdict(6, 'Flagging', 'data value flagging')
) )
## Annotations
# Kind of Annotations
AK_enum_table = Table("ak_vocabulary",
Base.metadata,
Column("enum_val", Integer, primary_key=True),
Column("enum_str", String),
Column("enum_display_str", String)
)
# The following code is just a workaround (see stationmeta/models.py):
from collections import namedtuple
Enumdict=namedtuple("Dict",["value","string","display_str"])
AK_enum = (
Enumdict(0, 'User', 'user comment'),
Enumdict(1, 'Provider', 'provider comment')
)
...@@ -4,7 +4,7 @@ class StationmetaAnnotation (Base) ...@@ -4,7 +4,7 @@ class StationmetaAnnotation (Base)
================================== ==================================
""" """
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \ from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \
Text, Boolean, CheckConstraint, Table, Sequence Text, Boolean, CheckConstraint, Table, Sequence, text
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from toardb.auth_user.models import AuthUser from toardb.auth_user.models import AuthUser
from toardb.base import Base from toardb.base import Base
...@@ -26,7 +26,7 @@ class StationmetaAnnotation(Base): ...@@ -26,7 +26,7 @@ class StationmetaAnnotation(Base):
+================+==========================+===========+==========+========================================================+ +================+==========================+===========+==========+========================================================+
| id | integer | | not null | nextval('stationmeta_annotations_id_seq'::regclass) | | id | integer | | not null | nextval('stationmeta_annotations_id_seq'::regclass) |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+ +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| kind | integer | | not null | | | kind | integer | | not null | 0 |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+ +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| text | text | | not null | | | text | text | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+ +----------------+--------------------------+-----------+----------+--------------------------------------------------------+
...@@ -43,6 +43,7 @@ class StationmetaAnnotation(Base): ...@@ -43,6 +43,7 @@ class StationmetaAnnotation(Base):
"stationmeta_annotations_kind_check" CHECK (kind >= 0) "stationmeta_annotations_kind_check" CHECK (kind >= 0)
Foreign-key constraints: 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_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' __tablename__ = 'stationmeta_annotations'
__table_args__ = ( __table_args__ = (
...@@ -50,7 +51,7 @@ class StationmetaAnnotation(Base): ...@@ -50,7 +51,7 @@ class StationmetaAnnotation(Base):
) )
id = Column(Integer, STATIONMETA_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=STATIONMETA_ANNOTATIONS_ID_SEQ.next_value()) id = Column(Integer, STATIONMETA_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=STATIONMETA_ANNOTATIONS_ID_SEQ.next_value())
kind = Column(Integer, nullable=False) kind = Column(ForeignKey('ak_vocabulary.enum_val'), nullable=False, server_default=text("0'::integer"))
text = Column(Text, nullable=False) text = Column(Text, nullable=False)
date_added = Column(DateTime(True), nullable=False) date_added = Column(DateTime(True), nullable=False)
approved = Column(Boolean, nullable=False) approved = Column(Boolean, nullable=False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment