views:

40

answers:

2

Hi, 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?

A: 

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.

Zepplock
Thanks, I tried to add it, but no luck. It's still running on my local machine. I'm probably just doing it really wrong, so I added my script to my post :)
Pandafox
+1  A: 

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 
mark
Well, the deploy username is the same as my local username. Also, when I log in and run the migration through ssh it works fine.
Pandafox
Hmm. Actually the error you posted is on update_code. Can I just check, your application is actually called example.com, you did cap deploy:setup and cap deploy:check from your local machine? example.com is just something you put for privacy here I take it?
mark
Heh, yeah, I replaced my real domain with my example.com for privacy. The code gets deployed to my server just fine, it's just that capistrano tries to run the migration on my local machine and not on the server :)
Pandafox
I'm still not convinced localhost isn't your remote server responding to capistrano. Can you post more of your error in a pastie. Actually first, can I refer you to a really great tutorial:http://github.com/monolith/rollout_tutorial
mark
Just noticed you've defined your db as localhost. See edit to my answer above. :)
mark
There we go! Thanks! For some reason I was under the impression that the :db role was the database host, which doesn't even make sense when I think about it, as the hostname is specified in database.yml :)
Pandafox
Hey glad you got it all working. I remember struggling the first time I met capistrano too. If I can offer further advice, download capistrano recipes. http://github.com/nesquena/cap-recipes It'll make things a lot easier. There are examples included.
mark