john-bodley commented on code in PR #25304:
URL: https://github.com/apache/superset/pull/25304#discussion_r1327861809


##########
superset/migrations/shared/migrate_viz/base.py:
##########
@@ -156,9 +156,7 @@ def downgrade_slice(cls, slc: Slice) -> Slice:
         return slc
 
     @classmethod
-    def upgrade(cls) -> None:
-        bind = op.get_bind()
-        session = db.Session(bind=bind)
+    def upgrade(cls, session: Session) -> None:
         slices = session.query(Slice).filter(Slice.viz_type == 
cls.source_viz_type)

Review Comment:
   Can this not be `db.session` for all occurrences, i.e., CLI and Alembic 
migration?



##########
superset/cli/viz_migrations.py:
##########
@@ -0,0 +1,91 @@
+# 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.
+from enum import Enum
+
+import click
+from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
+from flask.cli import with_appcontext
+
+from superset import db
+
+
+class VizTypes(str, Enum):
+    TREEMAP = "treemap"
+    DUAL_LINE = "dual_line"
+    AREA = "area"
+    PIVOT_TABLE = "pivot_table"
+
+
+@click.group()
+def viz_migrations() -> None:
+    """
+    Migrates a viz from one type to another.
+    """
+
+
+@viz_migrations.command()
+@with_appcontext
+@optgroup.group(
+    "Grouped options",
+    cls=RequiredMutuallyExclusiveOptionGroup,
+)
+@optgroup.option(
+    "--viz_type",
+    "-t",
+    help=f"The viz type to migrate: {', '.join(list(VizTypes))}",
+)
+def upgrade(viz_type: str) -> None:
+    """Upgrade a viz to the latest version."""
+    migrate_viz(VizTypes(viz_type))
+
+
+@viz_migrations.command()
+@with_appcontext
+@optgroup.group(
+    "Grouped options",
+    cls=RequiredMutuallyExclusiveOptionGroup,
+)
+@optgroup.option(
+    "--viz_type",
+    "-t",
+    help=f"The viz type to migrate: {', '.join(list(VizTypes))}",
+)
+def downgrade(viz_type: str) -> None:
+    """Downgrades a viz to the previous version."""
+    migrate_viz(VizTypes(viz_type), is_downgrade=True)
+
+
+def migrate_viz(viz_type: VizTypes, is_downgrade: bool = False) -> None:

Review Comment:
   ```suggestion
   def migrate_viz(viz_type: VizTypes, is_upgrade: bool = True) -> None:
   ```
   
   I thought upgrading is more typical than downgrading and thus naming the 
flag `is_upgrade` seems more appropriate.



##########
superset/cli/viz_migrations.py:
##########
@@ -0,0 +1,91 @@
+# 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.
+from enum import Enum
+
+import click
+from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
+from flask.cli import with_appcontext
+
+from superset import db
+
+
+class VizTypes(str, Enum):
+    TREEMAP = "treemap"
+    DUAL_LINE = "dual_line"
+    AREA = "area"
+    PIVOT_TABLE = "pivot_table"
+
+
+@click.group()
+def viz_migrations() -> None:

Review Comment:
   ```suggestion
   def viz_migrate() -> None:
   ```
   
   Should this be a verb?



##########
superset/cli/viz_migrations.py:
##########
@@ -0,0 +1,91 @@
+# 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.
+from enum import Enum
+
+import click
+from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
+from flask.cli import with_appcontext
+
+from superset import db
+
+
+class VizTypes(str, Enum):

Review Comment:
   ```suggestion
   class VizType(str, Enum):
   ```
   
   I think the enum should be singular, i.e., 
[here](https://docs.python.org/3/library/enum.html) the enum is called `Color` 
and not `Colors`.



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to