mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
[annotations] Fixing migration for annotation layers (#4187)
This commit is contained in:
committed by
Maxime Beauchemin
parent
e182f7f962
commit
0cb7c5e4a6
@@ -37,18 +37,19 @@ def upgrade():
|
|||||||
Slice.viz_type.like('line'), Slice.viz_type.like('bar'))):
|
Slice.viz_type.like('line'), Slice.viz_type.like('bar'))):
|
||||||
params = json.loads(slc.params)
|
params = json.loads(slc.params)
|
||||||
layers = params.get('annotation_layers', [])
|
layers = params.get('annotation_layers', [])
|
||||||
new_layers = []
|
if layers:
|
||||||
if len(layers) and isinstance(layers[0], int):
|
new_layers = []
|
||||||
for layer in layers:
|
for layer in layers:
|
||||||
new_layers.append(
|
new_layers.append({
|
||||||
{
|
'annotationType': 'INTERVAL',
|
||||||
'annotationType': 'INTERVAL',
|
'style': 'solid',
|
||||||
'style': 'solid',
|
'name': 'Layer {}'.format(layer),
|
||||||
'name': 'Layer {}'.format(layer),
|
'show': True,
|
||||||
'show': True,
|
'overrides': {'since': None, 'until': None},
|
||||||
'overrides': {'since': None, 'until': None},
|
'value': layer,
|
||||||
'value': 1, 'width': 1, 'sourceType': 'NATIVE',
|
'width': 1,
|
||||||
})
|
'sourceType': 'NATIVE',
|
||||||
|
})
|
||||||
params['annotation_layers'] = new_layers
|
params['annotation_layers'] = new_layers
|
||||||
slc.params = json.dumps(params)
|
slc.params = json.dumps(params)
|
||||||
session.merge(slc)
|
session.merge(slc)
|
||||||
@@ -57,4 +58,16 @@ def upgrade():
|
|||||||
|
|
||||||
|
|
||||||
def downgrade():
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user