You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2023/04/06 15:28:28 UTC

[superset] 01/03: lit

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch chart-ds-constraint
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 4d673a6cf034f47ba6c7588c1a7b8c75f4491e30
Author: hughhhh <hu...@gmail.com>
AuthorDate: Thu Apr 6 11:06:57 2023 -0400

    lit
---
 ...03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py | 36 +++++++++++++++++++---
 1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py b/superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py
index 8b22ebbf50..3bcb0c3822 100644
--- a/superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py
+++ b/superset/migrations/versions/2023-03-27_12-30_7e67aecbf3f1_chart_ds_constraint.py
@@ -23,14 +23,40 @@ Create Date: 2023-03-27 12:30:01.164594
 """
 
 # revision identifiers, used by Alembic.
-revision = '7e67aecbf3f1'
-down_revision = 'b5ea9d343307'
+revision = "7e67aecbf3f1"
+down_revision = "b5ea9d343307"
+
+import json
 
-from alembic import op
 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():
-    pass
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+    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"
+
+    op.create_check_constraint(
+        "ck_chart_datasource", "slice", sa.column("datasource_type") == "table"
+    )
+
 
 def downgrade():
-    pass 
+    op.drop_constraint("ck_chart_datasource", "slices", type_="check")