You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/04/05 01:09:57 UTC

[GitHub] john-bodley commented on a change in pull request #4746: Filtering out SQLLab views out of table list view by default

john-bodley commented on a change in pull request #4746: Filtering out SQLLab views out of table list view by default
URL: https://github.com/apache/incubator-superset/pull/4746#discussion_r179326188
 
 

 ##########
 File path: superset/migrations/versions/130915240929_is_sqllab_viz_flow.py
 ##########
 @@ -0,0 +1,54 @@
+"""is_sqllab_view
+
+Revision ID: 130915240929
+Revises: f231d82b9b26
+Create Date: 2018-04-03 08:19:34.098789
+
+"""
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+# revision identifiers, used by Alembic.
+revision = '130915240929'
+down_revision = 'f231d82b9b26'
+
+Base = declarative_base()
+
+
+class Table(Base):
+    """Declarative class to do query in upgrade"""
+    __tablename__ = 'tables'
+    id = sa.Column(sa.Integer, primary_key=True)
+    sql = sa.Column(sa.Text)
+    is_sqllab_view = sa.Column(sa.Boolean())
+
+
+def upgrade():
+    bind = op.get_bind()
+    op.add_column(
+        'tables',
+        sa.Column(
+            'is_sqllab_view',
+            sa.Boolean(),
+            nullable=True,
+            default=False,
+            server_default=sa.false(),
+        ),
+    )
+
+    session = db.Session(bind=bind)
+
+    # Use Slice class defined here instead of models.Slice
+    for tbl in session.query(Table).all():
+        if tbl.sql:
+            tbl.is_sqllab_view = True
+            session.merge(tbl)
+            session.commit()
 
 Review comment:
   I think the `session.commit()` could be defined outside the for loop.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services