Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from 3.0.0 to 5.0.0 or upper is failed #4105

Merged
merged 1 commit into from
Aug 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions migrations/versions/969126bd800f_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down