bte*_*les 11 ruby database activerecord data-migration ruby-on-rails
是否有任何Ruby gems /库可以帮助您从旧的DB结构迁移到新的结构?ActiveRecord迁移在跟踪新的数据库结构方面做得很好,但我想知道是否有什么可以帮助您将整个遗留数据库迁移到新结构:
transfer_from(:source_table => 'person', :destination_table => 'dudes_and_dudets') do
from :name, :to => :full_name
from :dob, :to => :age do |dob| # this would, for example, load the result
(Date.today - dob)/60/60/24/365 # of the block into :age
end
end
Run Code Online (Sandbox Code Playgroud)
(我意识到你可以像使用AR一样轻松地进行这些变换,但我希望魔术库可以有更多的变换.
伯恩斯
我已经开始做这方面的工作了。
如果有人想提供有关更好/更惯用或更有效的实施的提示,请告诉我。
http://github.com/btelles/legacy_migrations
编辑:
我现在在上面的 github 存储库上使用了这个精确的语法...计划添加一些 rake 任务来将旧结构映射到新的 ActiveRecord 类,以及更多转换...以防有人感兴趣。
它也在 gemcutter/rubygems 上:gem install legend_migrations