dpgaspar commented on a change in pull request #13983: URL: https://github.com/apache/superset/pull/13983#discussion_r613885773
########## File path: superset/migrations/versions/fc3a3a8ff221_migrate_filter_sets_to_new_format.py ########## @@ -0,0 +1,192 @@ +# 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. +"""migrate filter sets to new format + +Revision ID: fc3a3a8ff221 +Revises: 085f06488938 +Create Date: 2021-04-12 12:38:03.913514 + +""" + +# revision identifiers, used by Alembic. +revision = "fc3a3a8ff221" +down_revision = "085f06488938" + +import json +from typing import Any, Dict, List + +from alembic import op +from sqlalchemy import Column, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +from superset import db + +Base = declarative_base() + + +class Dashboard(Base): + """Declarative class to do query in upgrade""" + + __tablename__ = "dashboards" + id = Column(Integer, primary_key=True) + json_metadata = Column(Text) + + +# these are copied over from `superset/constants.py` to make sure they stay unchanged +EXTRA_FORM_DATA_APPEND_KEYS = [ + "adhoc_filters", + "filters", + "interactive_groupby", + "interactive_highlight", + "interactive_drilldown", + "custom_form_data", +] + +EXTRA_FORM_DATA_OVERRIDE_KEYS = [ + "druid_time_origin", + "relative_start", + "relative_end", + "time_grain_sqla", + "time_range_endpoints", + "granularity", + "granularity_sqla", + "time_column", + "time_grain", + "time_range", +] + + +def _update_select_filters(native_filters: List[Dict[str, Any]]) -> None: + for native_filter in native_filters: + filter_type = native_filter.get("filterType") + if filter_type == "filter_select": + control_values = native_filter.get("controlValues", {}) + value = control_values.get("defaultToFirstItem", False) + control_values["defaultToFirstItem"] = value + + +def upgrade(): + bind = op.get_bind() Review comment: There's some complexity here, would be nice to place the entire logic here: https://github.com/apache/superset/tree/master/superset/migrations/shared Then add some tests to assert that the migrations works has expected https://github.com/apache/superset/issues/13351 ########## File path: superset/constants.py ########## @@ -117,3 +117,33 @@ class RouteMethod: # pylint: disable=too-few-public-methods "get_charts": "read", "get_datasets": "read", } + +EXTRA_FORM_DATA_APPEND_KEYS = [ + "adhoc_filters", + "filters", + "interactive_groupby", + "interactive_highlight", + "interactive_drilldown", + "custom_form_data", +] + +EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS = { + "granularity": "granularity", + "granularity_sqla": "granularity", + "time_column": "time_column", + "time_grain": "time_grain", + "time_range": "time_range", +} + +EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS = [ Review comment: nit: we could use a `set` here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
