我在locations
表有一大堆的记录:闻起来像ActiveRecord的食堂对象属性上保存
...
*************************** 8. row ***************************
id: 8
feed: http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/4564.xml
...
*************************** 11. row ***************************
id: 11
feed: http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/5007.xml
...
有了这个迁移的帮助:
def self.up
add_column :locations, :old_feed, :string
Location.all.each do |l|
l.old_feed = l.feed
l.feed.sub!(/^.*?(\d+)\.xml$/, 'http://newsrss.bbc.co.uk/weather/forecast/\1/Next3DaysRSS.xml') # l.feed = l.feed.sub(...) does not make it any better
l.save!
end
end
我想他们变成
...
*************************** 8. row ***************************
id: 8
feed: http://newsrss.bbc.co.uk/weather/forecast/4564/Next3DaysRSS.xml
old_feed: http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/4564.xml
...
*************************** 11. row ***************************
id: 11
feed: http://newsrss.bbc.co.uk/weather/forecast/5007/Next3DaysRSS.xml
old_feed: http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/5007.xml
...
我得到的是
...
*************************** 8. row ***************************
id: 8
feed: http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/4564.xml
old_feed: http://newsrss.bbc.co.uk/weather/forecast/4564/Next3DaysRSS.xml
...
*************************** 11. row ***************************
id: 11
feed: http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/5007.xml
old_feed: http://newsrss.bbc.co.uk/weather/forecast/5007/Next3DaysRSS.xml
...
看起来像feed
和以某种方式被交换,我不明白为什么。
Rails 2.3.4,MySQL 5.0。
P.S.
我敢打赌,这是一个愚蠢的明显的东西,我在这里失踪。
什么位置验证?任何重写的setter/getters? – Eimantas 2010-01-12 16:52:19
P.S.我不建议在迁移过程中进行数据更改。你可能想为这个问题设置一个单独的rake任务。 – Eimantas 2010-01-12 16:54:32
没有覆盖的setter/getters – artemave 2010-01-12 17:15:19