john-bodley commented on code in PR #23269: URL: https://github.com/apache/superset/pull/23269#discussion_r1167322383
########## superset/cli/native_filters.py: ########## @@ -0,0 +1,398 @@ +# 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. +import json +from copy import deepcopy +from textwrap import dedent +from typing import Set, Tuple + +import click +from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup +from flask.cli import with_appcontext +from sqlalchemy import Column, ForeignKey, Integer, String, Table, Text +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import relationship + +from superset import db, is_feature_enabled + +Base = declarative_base() + + +dashboard_slices = Table( + "dashboard_slices", + Base.metadata, + Column("id", Integer, primary_key=True), + Column("dashboard_id", Integer, ForeignKey("dashboards.id")), + Column("slice_id", Integer, ForeignKey("slices.id")), +) + + +slice_user = Table( + "slice_user", + Base.metadata, + Column("id", Integer, primary_key=True), + Column("slice_id", Integer, ForeignKey("slices.id")), +) + + +class Dashboard(Base): # type: ignore # pylint: disable=too-few-public-methods + __tablename__ = "dashboards" + + id = Column(Integer, primary_key=True) + json_metadata = Column(Text) + slices = relationship("Slice", secondary=dashboard_slices, backref="dashboards") + position_json = Column() + + def __repr__(self) -> str: + return f"Dashboard<{self.id}>" + + +class Slice(Base): # type: ignore # pylint: disable=too-few-public-methods + __tablename__ = "slices" + + id = Column(Integer, primary_key=True) + datasource_id = Column(Integer) + params = Column(Text) + slice_name = Column(String(250)) + viz_type = Column(String(250)) + + def __repr__(self) -> str: + return f"Slice<{self.id}>" + + [email protected]() +def native_filters() -> None: + """ + Perform native filter operations. + """ + + +@native_filters.command() +@with_appcontext [email protected]( + "Grouped options", + cls=RequiredMutuallyExclusiveOptionGroup, +) [email protected]( + "--all", + "all_", + default=False, + help="Upgrade all dashboards", + is_flag=True, +) [email protected]( + "--id", + "dashboard_ids", + help="Upgrade the specific dashboard. Can be supplied multiple times.", + multiple=True, + type=int, +) +def upgrade( Review Comment: These commands aren't significantly large (in terms of lines of code) combined with the fact that they're somewhat related, thus I think they can reside in the same file. This is somewhat akin to Alembic migrations where the `upgrade` and `downgrade` functions coexist. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
