You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/11/15 23:18:04 UTC

[GitHub] graceguo-supercat commented on a change in pull request #6378: [migration]clean up __from and __to in dashboard json_metadata

graceguo-supercat commented on a change in pull request #6378: [migration]clean up __from and __to in dashboard json_metadata
URL: https://github.com/apache/incubator-superset/pull/6378#discussion_r234044051
 
 

 ##########
 File path: superset/migrations/versions/4ce8df208545_migrate_time_range_for_default_filters.py
 ##########
 @@ -0,0 +1,94 @@
+"""empty message
+
+Revision ID: 4ce8df208545
+Revises: 55e910a74826
+Create Date: 2018-11-12 13:31:07.578090
+
+"""
+
+# revision identifiers, used by Alembic.
+import json
+
+from alembic import op
+from sqlalchemy import (
+    Column,
+    Integer,
+    Text,
+)
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+revision = '4ce8df208545'
+down_revision = '55e910a74826'
+
+Base = declarative_base()
+
+
+class Dashboard(Base):
+    """Declarative class to do query in upgrade"""
+    __tablename__ = 'dashboards'
+    id = Column(Integer, primary_key=True)
+    json_metadata = Column(Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    dashboards = session.query(Dashboard).all()
+    for i, dashboard in enumerate(dashboards):
+        print('scanning dashboard ({}/{}) >>>>'.format(i + 1, len(dashboards)))
+        if dashboard.json_metadata:
+            json_metadata = json.loads(dashboard.json_metadata)
+            has_update = False
+
+            # default_filters: it may define time_range filter
+            default_filters = json_metadata.get('default_filters')
+            if default_filters and default_filters != '{}':
+                try:
+                    filters = json.loads(default_filters)
+                    keys = [key for key, val in filters.items() if
+                            val.get('__from') or val.get('__to')]
+                    if len(keys):
+                        for key in keys:
+                            val = filters[key]
+                            val['__time_range'] = '{} : {}'.format(
 
 Review comment:
   yes, i think should check if `__time_range exist`. if it is exist, just abandon __from and __to parameter, so that not override existed __time_range.

----------------------------------------------------------------
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

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