Skip to content

Commit

Permalink
Issue 374 allow storing the recording time of annotations (#375)
Browse files Browse the repository at this point in the history
Prepare the database to support users in adding multiple annotations (such as labels) for the same chain of events.


* Amend database migration for 0.9.0

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Add belief_time column to annotation table

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Expand UniqueConstraint

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Allow storing longer annotations, and change the default order of columns to get clearer output for SELECT statements

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Feb 25, 2022
1 parent b6f4b17 commit 2e035c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -142,19 +142,20 @@ def create_annotation_table():
sa.Column(
"id", sa.Integer(), nullable=False, autoincrement=True, primary_key=True
),
sa.Column("content", sa.String(255), nullable=False),
sa.Column("start", sa.DateTime(timezone=True), nullable=False),
sa.Column("end", sa.DateTime(timezone=True), nullable=False),
sa.Column("belief_time", sa.DateTime(timezone=True), nullable=True),
sa.Column("source_id", sa.Integer(), nullable=False),
sa.Column(
"type",
sa.Enum("alert", "holiday", "label", name="annotation_type"),
nullable=False,
),
sa.Column("content", sa.String(1024), nullable=False),
sa.ForeignKeyConstraint(("source_id",), ["data_source.id"]),
)
op.create_unique_constraint(
op.f("annotation_content_key"),
"annotation",
["content", "start", "source_id", "type"],
["content", "start", "belief_time", "source_id", "type"],
)
4 changes: 3 additions & 1 deletion flexmeasures/data/models/annotations.py
Expand Up @@ -15,20 +15,22 @@ class Annotation(db.Model):
"""

id = db.Column(db.Integer, nullable=False, autoincrement=True, primary_key=True)
content = db.Column(db.String(255), nullable=False)
start = db.Column(db.DateTime(timezone=True), nullable=False)
end = db.Column(db.DateTime(timezone=True), nullable=False)
belief_time = db.Column(db.DateTime(timezone=True), nullable=True)
source_id = db.Column(db.Integer, db.ForeignKey("data_source.id"))
source = db.relationship(
"DataSource",
foreign_keys=[source_id],
backref=db.backref("annotations", lazy=True),
)
type = db.Column(db.Enum("alert", "holiday", "label", name="annotation_type"))
content = db.Column(db.String(1024), nullable=False)
__table_args__ = (
db.UniqueConstraint(
"content",
"start",
"belief_time",
"source_id",
"type",
name="annotation_content_key",
Expand Down

0 comments on commit 2e035c6

Please sign in to comment.