You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "hughhhh (via GitHub)" <gi...@apache.org> on 2023/04/06 21:25:52 UTC

[GitHub] [superset] hughhhh commented on a diff in pull request #23614: chore: add check constraint to restrict `Slice` models datasource_type != "table"

hughhhh commented on code in PR #23614:
URL: https://github.com/apache/superset/pull/23614#discussion_r1160271255


##########
superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py:
##########
@@ -0,0 +1,66 @@
+# 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.
+"""chart-ds-constraint
+
+Revision ID: 7e67aecbf3f1
+Revises: b5ea9d343307
+Create Date: 2023-03-27 12:30:01.164594
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "7e67aecbf3f1"
+down_revision = "07f9a902af1b"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+Base = declarative_base()
+
+
+class Slice(Base):  # type: ignore
+    __tablename__ = "slices"
+
+    id = sa.Column(sa.Integer, primary_key=True)
+    slice_name = sa.Column(sa.String(250))
+    datasource_type = sa.Column(sa.String(200))
+    query_context = sa.Column(sa.Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    with op.batch_alter_table("slices") as batch_op:
+        for slc in session.query(Slice).filter(Slice.datasource_type != "table").all():
+            # clean up all charts with datasource_type not != table
+            slc.datasource_type = "table"

Review Comment:
   > @hughhhh we're seeing a defined `slices.datasource_name` column when `slices.datasource_type = 'query'` however it doesn't seem to be a dataset in the `tables` table—which would indicate that your migration would likely break said slices when you make the switch from `query` to `table`. BTW where is this query stored?
   
   is the column `datasource_name` only appearing when the `datasource_type` is `query`?
   
   Query is defined [here](https://github.com/apache/superset/blob/1dd895b9b0ebc2efcd2193b72013b4f9f0183564/superset/models/sql_lab.py#L65)



-- 
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-unsubscribe@superset.apache.org

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


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