使用 capistrano 部署时在服务器上运行迁移
我正在尝试使用 capistrano 部署 Rails 应用程序,但在运行迁移时遇到一些问题。在我的开发环境中,我只使用 sqlite 作为数据库,但在我的生产服务器上,我使用 MySQL。
问题是我希望迁移从我的服务器而不是本地计算机运行,因为我无法从远程位置连接到我的数据库。
我的服务器设置: 一个运行 ngnix、passenger、mysql 和 git 存储库的 debian 盒子。
做到这一点最简单的方法是什么?
更新:
这是我的部署脚本:(我用 example.com 替换了我的实际域)
set :application, "example.com" set :domain, "example.com" set :scm, :git set :repository, "[email protected]:project.git" set :use_sudo, false set :deploy_to, "/var/www/example.com" role :web, domain role :app, domain role :db, "localhost", :primary => true after "deploy", "deploy:migrate"
当我运行 cap deploy 时,一切正常,直到它尝试运行迁移。 这是我收到的错误:
** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2)) connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2)))
这就是为什么我需要从服务器而不是从本地计算机运行迁移。
有什么想法吗?
I'm trying to deploy my rails application with capistrano, but I'm having some trouble running my migrations. In my development environment I just use sqlite as my database, but on my production server I use MySQL.
The problem is that I want the migrations to run from my server and not my local machine, as I am not able to connect to my database from a remote location.
My server setup:
A debian box running ngnix, passenger, mysql and a git repository.
What is the easiest way to do this?
update:
Here's my deploy script: (i replaced my actual domain with example.com)
set :application, "example.com" set :domain, "example.com" set :scm, :git set :repository, "[email protected]:project.git" set :use_sudo, false set :deploy_to, "/var/www/example.com" role :web, domain role :app, domain role :db, "localhost", :primary => true after "deploy", "deploy:migrate"
When I run cap deploy, everything is working fine until it tries to run the migration.
Here's the error I'm getting:
** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2)) connection failed for: localhost (Errno::ECONNREFUSED: Connection refused - connect(2)))
This is why I need to run the migration from the server and not from my local machine.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加
到您的 config/deploy.rb 文件中。成功部署项目后,这将在您的服务器上运行迁移。
Try to add
in your config/deploy.rb file. This will run a migration on your server upon a successful deployment of your project.
您是否已将部署用户添加为服务器上的 mysql 用户?我认为 localhost 是指自身的服务器,而不是您的本地计算机。
此外,您还没有在部署脚本中定义您的用户:
Have you added your deploying user as a mysql user on the server? I reckon the localhost is the server referring to itself not your local machine.
Also you haven't defined your user in your deploy script: