如何使用 Capistrano gem 为生产数据库播种?
我正在使用 Ruby on Rails 3.0.9,我想为生产数据库播种,以便添加一些记录而无需重新构建所有数据库(即,无需删除所有现有记录,但仅添加一些尚不存在的记录)。我想这样做,因为需要新数据才能使应用程序正常工作。
因此,由于我使用的是 Capistrano gem,因此我在控制台中运行 cap -T 命令,以列出所有可用命令并了解如何实现我的目标:
$ cap -T
=> ...
=> cap deploy:seed # Reload the database with seed data.
=> ...
我不确定“使用种子数据重新加载数据库”中出现“重新加载”一词。句子。所以,我的问题是:如果我在本地计算机上的控制台中运行 cap deploy:seed
命令,播种过程是否会删除生产数据库中的所有现有数据,然后填充它或将该命令只是按照我的目标在该数据库中添加新数据?
I am using Ruby on Rails 3.0.9 and I would like to seed the production database in order to add some record without re-building all the database (that is, without delete all existing records but just adding some of those not existing yet). I would like to do that because the new data is needed to make the application to work.
So, since I am using the Capistrano gem, I run the cap -T
command in the console in order to list all available commands and to know how I can accomplish what I aim:
$ cap -T
=> ...
=> cap deploy:seed # Reload the database with seed data.
=> ...
I am not sure on the word "Reload" present in the "Reload the database with seed data." sentence. So, my question is: if I run the cap deploy:seed
command in the console on my local machine will the seeding process delete all existing data in the production database and then populate it or will that command just add the new data in that database as I aim to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用捆绑器,那么 capistrano 任务应该是:
并且它可能被放置在一个单独的文件中,例如 lib/deploy/seed.rb 并使用以下命令包含在您的 deploy.rb 文件中:
If you are using bundler, then the capistrano task should be:
and it might be placed in a separate file, such as
lib/deploy/seed.rb
and included in your deploy.rb file using following command:这对我有用:
capistrano 3,Rails 4
This worked for me:
capistrano 3, Rails 4
使用 Capistrano 3、Rails 4 和 SeedMigrations,我在 /lib/capistrano/tasks 下创建了一个 Capistrano Seed.rb 任务:
我的种子迁移现在与我的架构迁移完全分开,并按照 db:migrate 流程运行。多么高兴啊! :)
Using Capistrano 3, Rails 4, and SeedMigrations, I created a Capistrano seed.rb task under /lib/capistrano/tasks:
My seed migrations are now completely separate from my schema migrations, and ran following the db:migrate process. What a joy! :)
尝试在您的 deploy.rb 中添加类似的内容:
Try adding something like this in your deploy.rb:
在与 capistrano-rails gem 作者讨论后,我决定在单独的 gem 中实现此类任务。我认为这有助于遵循 DRY 理念,而不是一遍又一遍地执行相同的任务。
我希望它对您有帮助:https://github.com/dei79/capistrano-rails-collection
After a discussion with capistrano-rails gem authors I decided to implement this kind of tasks in a separate gem. I think this helps to follow the DRY idea and not implementing the same task over and over again.
I hope it helps you: https://github.com/dei79/capistrano-rails-collection