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/08/07 02:57:58 UTC

[GitHub] john-bodley commented on a change in pull request #5556: Time filter migrate dashboard stored default filters to time range format

john-bodley commented on a change in pull request #5556: Time filter migrate dashboard stored default filters to time range format
URL: https://github.com/apache/incubator-superset/pull/5556#discussion_r208085771
 
 

 ##########
 File path: superset/migrations/versions/388242a6da7e_dash_json_add_time_range.py
 ##########
 @@ -0,0 +1,89 @@
+"""dash json add time_range
+
+Revision ID: 388242a6da7e
+Revises: c18bd4186f15
+Create Date: 2018-08-03 15:26:58.524367
+
+"""
+
+import json
+
+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 = '388242a6da7e'
+down_revision = 'c18bd4186f15'
+
+Base = declarative_base()
+
+
+class Dashboard(Base):
+    """Declarative class to do query in upgrade"""
+    __tablename__ = 'dashboards'
+    id = sa.Column(sa.Integer, primary_key=True)
+    json_metadata = sa.Column(sa.Text)
+
+
+def upgrade():
+
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    dashboards = session.query(Dashboard).all()
+    for i, dashboard in enumerate(dashboards):
+        print('Upgrading ({}/{}): {}'.format(
+            i + 1, len(dashboards), dashboard.id))
+        metadata = json.loads(dashboard.json_metadata or '{}')
+        default_filters = json.loads(metadata.get('default_filters') or '{}')
+
+        for filter_id in default_filters:
+            filter = default_filters[filter_id]
+            if '__from' in filter or '__to' in filter:
+                time_range = '{} : {}'.format(
+                    filter.get('__from', ''), filter.get('__to', ''))
+                default_filters[filter_id] = {'__time_range': time_range}
+
+        metadata['default_filters'] = json.dumps(default_filters, indent=2)
+        dashboard.json_metadata = json.dumps(metadata, indent=2)
+        session.merge(dashboard)
+        session.commit()
 
 Review comment:
   The commit should be outside of the for lool.

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