使用 capistrano 部署时在服务器上运行迁移

发布于 2024-09-06 02:05:12 字数 1152 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔一刀 2024-09-13 02:05:12

尝试添加

after "deploy", "deploy:migrate"

到您的 config/deploy.rb 文件中。成功部署项目后,这将在您的服务器上运行迁移。

Try to add

after "deploy", "deploy:migrate"

in your config/deploy.rb file. This will run a migration on your server upon a successful deployment of your project.

拥有 2024-09-13 02:05:12

您是否已将部署用户添加为服务器上的 mysql 用户?我认为 localhost 是指自身的服务器,而不是您的本地计算机。

此外,您还没有在部署脚本中定义您的用户:

set :user, "deploy_user_name"

role :web, domain
role :app, domain
role :db, domain, :primary => true 

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:

set :user, "deploy_user_name"

role :web, domain
role :app, domain
role :db, domain, :primary => true 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文