diff --git a/migrations/versions/969126bd800f_.py b/migrations/versions/969126bd800f_.py index 051b97e695..4a476ef956 100644 --- a/migrations/versions/969126bd800f_.py +++ b/migrations/versions/969126bd800f_.py @@ -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.