From 5e3f8332c4b6bcba15f06725ddb6295d703db94a Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Fri, 31 Aug 2018 10:06:27 -0700 Subject: [PATCH] Update annotation model to have JSON Metadata field (#5745) * add column to annotation model * update migration file * change to Text * remove old migration file * add migration file * remove JSON * add new column to view * add comma back * linting * lint some more * missing comma * rename columns * add degrade and new migration file * update version * fixe changed name * remove json from list columns --- ...dd_metadata_column_to_annotation_model_.py | 22 +++++++++++++++++++ superset/models/annotations.py | 1 + superset/views/annotations.py | 10 ++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 superset/migrations/versions/55e910a74826_add_metadata_column_to_annotation_model_.py diff --git a/superset/migrations/versions/55e910a74826_add_metadata_column_to_annotation_model_.py b/superset/migrations/versions/55e910a74826_add_metadata_column_to_annotation_model_.py new file mode 100644 index 0000000000..17c24194df --- /dev/null +++ b/superset/migrations/versions/55e910a74826_add_metadata_column_to_annotation_model_.py @@ -0,0 +1,22 @@ +"""add_metadata_column_to_annotation_model.py + +Revision ID: 55e910a74826 +Revises: 1a1d627ebd8e +Create Date: 2018-08-29 14:35:20.407743 + +""" + +# revision identifiers, used by Alembic. +revision = '55e910a74826' +down_revision = '1a1d627ebd8e' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('annotation', sa.Column('json_metadata', sa.Text(), nullable=True)) + + +def downgrade(): + op.drop_column('annotation', 'json_metadata') diff --git a/superset/models/annotations.py b/superset/models/annotations.py index 82619fdd49..b7640baaa9 100644 --- a/superset/models/annotations.py +++ b/superset/models/annotations.py @@ -42,6 +42,7 @@ class Annotation(Model, AuditMixinNullable): layer = relationship( AnnotationLayer, backref='annotation') + json_metadata = Column(Text) __table_args__ = ( Index('ti_dag_state', layer_id, start_dttm, end_dttm), diff --git a/superset/views/annotations.py b/superset/views/annotations.py index 648be25881..c1d45512ed 100644 --- a/superset/views/annotations.py +++ b/superset/views/annotations.py @@ -24,7 +24,9 @@ class AnnotationModelView(SupersetModelView, DeleteMixin): # noqa list_columns = ['layer', 'short_descr', 'start_dttm', 'end_dttm'] edit_columns = [ - 'layer', 'short_descr', 'long_descr', 'start_dttm', 'end_dttm'] + 'layer', 'short_descr', 'long_descr', 'start_dttm', 'end_dttm', + 'json_metadata'] + add_columns = edit_columns label_columns = { @@ -33,6 +35,12 @@ class AnnotationModelView(SupersetModelView, DeleteMixin): # noqa 'start_dttm': _('Start Dttm'), 'end_dttm': _('End Dttm'), 'long_descr': _('Long Descr'), + 'json_metadata': _('JSON Metadata'), + } + + description_columns = { + 'json_metadata': 'This JSON represents any additional metadata this \ + annotation needs to add more context.', } def pre_add(self, obj):