From 1377465a7d9f374500576b35683763c2cc29afe8 Mon Sep 17 00:00:00 2001 From: Ajay M Date: Fri, 3 Dec 2021 10:28:25 -0800 Subject: [PATCH] feat(alerts): Column for select tabs to send (#17604) * init * init * Modify migration * Modify migration * revert config, delete test file * Rename column, modify migration * rename a column * Make extra non-nullable * Fix typo --- ...f93db_add_extra_config_column_to_alerts.py | 50 +++++++++++++++++++ superset/models/alerts.py | 2 +- superset/models/reports.py | 3 ++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 superset/migrations/versions/abe27eaf93db_add_extra_config_column_to_alerts.py diff --git a/superset/migrations/versions/abe27eaf93db_add_extra_config_column_to_alerts.py b/superset/migrations/versions/abe27eaf93db_add_extra_config_column_to_alerts.py new file mode 100644 index 0000000000000..c0cce0ac9e650 --- /dev/null +++ b/superset/migrations/versions/abe27eaf93db_add_extra_config_column_to_alerts.py @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""add_extra_config_column_to_alerts + +Revision ID: abe27eaf93db +Revises: aea15018d53b +Create Date: 2021-12-02 12:03:20.691171 + +""" + +# revision identifiers, used by Alembic. +revision = "abe27eaf93db" +down_revision = "aea15018d53b" + +import sqlalchemy as sa +from alembic import op +from sqlalchemy import String +from sqlalchemy.sql import column, table + +connection = op.get_bind() + +report_schedule = table("report_schedule", column("extra", String)) + + +def upgrade(): + with op.batch_alter_table("report_schedule") as batch_op: + batch_op.add_column( + sa.Column("extra", sa.Text(), nullable=True, default="{}",), + ) + connection.execute(report_schedule.update().values({"extra": "{}"})) + with op.batch_alter_table("report_schedule") as batch_op: + batch_op.alter_column("extra", existing_type=sa.Text(), nullable=False) + + +def downgrade(): + op.drop_column("report_schedule", "extra") diff --git a/superset/models/alerts.py b/superset/models/alerts.py index 85bad4e16d74b..163dcf027de0e 100644 --- a/superset/models/alerts.py +++ b/superset/models/alerts.py @@ -126,7 +126,7 @@ def __str__(self) -> str: @property def pretty_config(self) -> str: - """ String representing the comparison that will trigger a validator """ + """String representing the comparison that will trigger a validator""" config = json.loads(self.validator_config) if self.validator_type.lower() == "operator": diff --git a/superset/models/reports.py b/superset/models/reports.py index 6ed769dd49400..a0dc59917a42c 100644 --- a/superset/models/reports.py +++ b/superset/models/reports.py @@ -145,6 +145,9 @@ class ReportSchedule(Model, AuditMixinNullable): # (Alerts/Reports) Unlock a possible stalled working state working_timeout = Column(Integer, default=60 * 60 * 1) + # Store the selected dashboard tabs etc. + extra = Column(Text, default="{}") + def __repr__(self) -> str: return str(self.name)