rake db:schema:dump 不提供数据迁移信息 - 是否有自动方法来获取此信息?
rake db:schema:dump
此命令为您提供旧数据库的架构,您可以根据生成的架构为该数据库构建迁移。
但是,如果该数据库中有数据,那么如果有一个 rake 命令来检索 Rails 生成的迁移文件中的数据,那就太好了。
也许我在做梦 - 认为 Rails 可以查看遗留数据库中的数据并从现有数据为您构建迁移可能要求太多 - 像这样:
class LoadDefaultData < ActiveRecord::Migration
def self.up
bopeep = User.find_by_username 'bopeep'
BlogPost.create(:title => 'test', :content => 'test', :author_id => bopeep.id, :status => 'ok')
end
def self.down
end
end
或者有办法吗?
rake db:schema:dump
This command gives you the schema of a legacy database and you can build a migration for that database off the generated schema.
But if that database had data in it, it would be nice if there was a rake command to retrieve the data in a migration file generated by Rails.
Perhaps I'm dreaming - it's probably asking too much to think that Rails could look at the data in the legacy database and construct a migration for you from the existing data - something like this:
class LoadDefaultData < ActiveRecord::Migration
def self.up
bopeep = User.find_by_username 'bopeep'
BlogPost.create(:title => 'test', :content => 'test', :author_id => bopeep.id, :status => 'ok')
end
def self.down
end
end
Or is there a way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tobias Lütke 需要将数据库从一种架构迁移到另一种架构,但需要完整地复制数据。 为了确保格式与架构无关,他创建了一个插件,将数据转储到 YAML,然后将其重新加载回另一端的数据库中。 这是一个简单的 rake 任务,Tobi 给出了快速简单的说明。
http://blog.leetsoft.com/2006/5/29 /easy-migration- Between-databases
这可能会有所帮助。
您可能还想查看 YamlDB 插件 http://opensource.heroku.com/,它可以从一种数据库类型并恢复到另一种。 以下是一些说明
Tobias Lütke needed to migrate a database from one architecture to another but needed to copy the data across intact. To ensure that the format would be architecture agnostic, he's created a plugin that dumps the data to YAML and then reloads it back into the database at the other end. It's a simple rake task, and Tobi gives quick and easy instructions.
http://blog.leetsoft.com/2006/5/29/easy-migration-between-databases
This may help.
You may also like to look at YamlDB plugin http://opensource.heroku.com/ which can back up from one db type and restore to another. Here are some instructions