mirror of
https://github.com/getredash/redash.git
synced 2025-12-25 01:03:20 -05:00
Migrate with SQL statements. (#4105)
This commit is contained in:
committed by
Arik Fraimovich
parent
61a80ad8cc
commit
0207ba11a3
@@ -24,15 +24,20 @@ def upgrade():
|
||||
# Update widgets position data:
|
||||
column_size = 3
|
||||
print("Updating dashboards position data:")
|
||||
for dashboard in Dashboard.query:
|
||||
print(" Updating dashboard: {}".format(dashboard.id))
|
||||
layout = simplejson.loads(dashboard.layout)
|
||||
dashboard_result = db.session.execute("SELECT id, layout FROM dashboards")
|
||||
for dashboard in dashboard_result:
|
||||
print(" Updating dashboard: {}".format(dashboard['id']))
|
||||
layout = simplejson.loads(dashboard['layout'])
|
||||
|
||||
print(" Building widgets map:")
|
||||
widgets = {}
|
||||
for w in dashboard.widgets:
|
||||
print(" Widget: {}".format(w.id))
|
||||
widgets[w.id] = w
|
||||
widget_result = db.session.execute(
|
||||
"SELECT id, options, width FROM widgets WHERE dashboard_id=:dashboard_id",
|
||||
{"dashboard_id" : dashboard['id']})
|
||||
for w in widget_result:
|
||||
print(" Widget: {}".format(w['id']))
|
||||
widgets[w['id']] = w
|
||||
widget_result.close()
|
||||
|
||||
print(" Iterating over layout:")
|
||||
for row_index, row in enumerate(layout):
|
||||
@@ -47,17 +52,18 @@ def upgrade():
|
||||
if widget is None:
|
||||
continue
|
||||
|
||||
options = simplejson.loads(widget.options) or {}
|
||||
options = simplejson.loads(widget['options']) or {}
|
||||
options['position'] = {
|
||||
"row": row_index,
|
||||
"col": column_index * column_size,
|
||||
"sizeX": column_size * widget.width
|
||||
}
|
||||
|
||||
widget.options = simplejson.dumps(options)
|
||||
|
||||
db.session.add(widget)
|
||||
db.session.execute(
|
||||
"UPDATE widgets SET options=:options WHERE id=:id",
|
||||
{"options" : simplejson.dumps(options), "id" : widget_id})
|
||||
|
||||
dashboard_result.close()
|
||||
db.session.commit()
|
||||
|
||||
# Remove legacy columns no longer in use.
|
||||
|
||||
Reference in New Issue
Block a user