mistercrunch commented on a change in pull request #4800: Improve the calendar 
heatmap
URL: 
https://github.com/apache/incubator-superset/pull/4800#discussion_r180940171
 
 

 ##########
 File path: 
superset/migrations/versions/bf706ae5eb46_cal_heatmap_metric_to_metrics.py
 ##########
 @@ -0,0 +1,56 @@
+"""cal_heatmap_metric_to_metrics
+
+Revision ID: bf706ae5eb46
+Revises: f231d82b9b26
+Create Date: 2018-04-10 11:19:47.621878
+
+"""
+from alembic import op
+
+import json
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy import Column, Integer, String, Text
+
+from superset import db
+from superset.legacy import cast_form_data
+
+Base = declarative_base()
+
+# revision identifiers, used by Alembic.
+revision = 'bf706ae5eb46'
+down_revision = 'f231d82b9b26'
+
+
+class Slice(Base):
+    """Declarative class to do query in upgrade"""
+    __tablename__ = 'slices'
+    id = Column(Integer, primary_key=True)
+    datasource_type = Column(String(200))
+    viz_type = Column(String(200))
+    slice_name = Column(String(200))
+    params = Column(Text)
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    slices = session.query(Slice).filter_by(viz_type='cal_heatmap').all()
+    slice_len = len(slices)
+    for i, slc in enumerate(slices):
+        try:
+            params = json.loads(slc.params or '{}')
+            params['metrics'] = [params.get('metric')]
+            del params['metric']
 
 Review comment:
   Nice. I should have thought of that. Though now without a downgrade script 
I'd rather just not touch it as I should probably re-test it after changing the 
code. Will leave as is. BTW I think our linter isn't setup to check migrations 
scripts, we should probably change that.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to