How can you run a Sequel migration that updates a newly added column with a value from the row?
The Sequel documentation shows how you can update the column with a static value:
self[:artists].update(:location=>'Sacramento')
What I need to do is update the new column with the value of the ID column:
something like:
self[:artists].each |artist| do
artist.update(:location => artist[:id])
end
But the above doesn’t work and I have been unable to figure out how to get it to go.
Thanks!
artistin your loop is aHash, so you are callingHash#update, which just updates theHashinstance, it doesn’t modify the database. That’s why your loop doesn’t appear to do anything.I could explain how to make the loop work (using
allinstead ofeachand updating a dataset restricted to the matching primary key value), but since you are just assigning the value of one column to the value of another column for all rows, you can just do: