forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB migration of annotation_layers on slice objects and slimming down …
…annotation object. (apache#4072)
- Loading branch information
1 parent
6547c5b
commit f446ce5
Showing
2 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
superset/migrations/versions/21e88bc06c02_annotation_migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import json | ||
|
||
from alembic import op | ||
from sqlalchemy import ( | ||
Column, Integer, or_, String, Text) | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
from superset import db | ||
|
||
"""migrate_old_annotation_layers | ||
Revision ID: 21e88bc06c02 | ||
Revises: 67a6ac9b727b | ||
Create Date: 2017-12-17 11:06:30.180267 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '21e88bc06c02' | ||
down_revision = '67a6ac9b727b' | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class Slice(Base): | ||
__tablename__ = 'slices' | ||
id = Column(Integer, primary_key=True) | ||
viz_type = Column(String(250)) | ||
params = Column(Text) | ||
|
||
|
||
def upgrade(): | ||
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', []) | ||
new_layers = [] | ||
if len(layers) and isinstance(layers[0], int): | ||
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', | ||
}) | ||
params['annotation_layers'] = new_layers | ||
slc.params = json.dumps(params) | ||
session.merge(slc) | ||
session.commit() | ||
session.close() | ||
|
||
|
||
def downgrade(): | ||
pass |