You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2018/01/10 16:50:09 UTC

[incubator-superset] branch master updated: [annotations] Fixing migration for annotation layers (#4187)

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

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cb7c5e  [annotations] Fixing migration for annotation layers (#4187)
0cb7c5e is described below

commit 0cb7c5e4a62eacfee2e2ce4b0e17fa4d7e1a1320
Author: John Bodley <45...@users.noreply.github.com>
AuthorDate: Wed Jan 10 08:50:05 2018 -0800

    [annotations] Fixing migration for annotation layers (#4187)
---
 .../versions/21e88bc06c02_annotation_migration.py  | 37 +++++++++++++++-------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/superset/migrations/versions/21e88bc06c02_annotation_migration.py b/superset/migrations/versions/21e88bc06c02_annotation_migration.py
index 77c6453..4c7bb80 100644
--- a/superset/migrations/versions/21e88bc06c02_annotation_migration.py
+++ b/superset/migrations/versions/21e88bc06c02_annotation_migration.py
@@ -37,18 +37,19 @@ def upgrade():
             Slice.viz_type.like('line'), Slice.viz_type.like('bar'))):
         params = json.loads(slc.params)
         layers = params.get('annotation_layers', [])
-        new_layers = []
-        if len(layers) and isinstance(layers[0], int):
+        if layers:
+            new_layers = []
             for layer in layers:
-                new_layers.append(
-                    {
-                        'annotationType': 'INTERVAL',
-                        'style': 'solid',
-                        'name': 'Layer {}'.format(layer),
-                        'show': True,
-                        'overrides': {'since': None, 'until': None},
-                        'value': 1, 'width': 1, 'sourceType': 'NATIVE',
-                    })
+                new_layers.append({
+                    'annotationType': 'INTERVAL',
+                    'style': 'solid',
+                    'name': 'Layer {}'.format(layer),
+                    'show': True,
+                    'overrides': {'since': None, 'until': None},
+                    'value': layer,
+                    'width': 1,
+                    'sourceType': 'NATIVE',
+                })
             params['annotation_layers'] = new_layers
             slc.params = json.dumps(params)
             session.merge(slc)
@@ -57,4 +58,16 @@ def upgrade():
 
 
 def downgrade():
-    pass
+    bind = op.get_bind()
+    session = db.Session(bind=bind)
+
+    for slc in session.query(Slice).filter(or_(
+            Slice.viz_type.like('line'), Slice.viz_type.like('bar'))):
+        params = json.loads(slc.params)
+        layers = params.get('annotation_layers', [])
+        if layers:
+            params['annotation_layers'] = [layer['value'] for layer in layers]
+            slc.params = json.dumps(params)
+            session.merge(slc)
+            session.commit()
+    session.close()

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <co...@superset.apache.org>'].