FIX: properly migrate polls/votes stored as array

This commit is contained in:
Régis Hanol 2018-11-24 17:14:03 +01:00 committed by GitHub
parent a3ed570124
commit ed400a90fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -58,6 +58,10 @@ class MigratePollsData < ActiveRecord::Migration[5.2]
SQL
DB.query(sql).each do |r|
# for some reasons, polls or votes might be an array
r.polls = r.polls[0] if Array === r.polls && r.polls.size > 0
r.votes = r.votes[0] if Array === r.votes && r.votes.size > 0
existing_user_ids = User.where(id: r.votes.keys).pluck(:id).to_set
# Poll votes are stored in a JSON object with the following hierarchy