Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running migration on server when deploying with capistrano

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?

like image 740
Pandafox Avatar asked Jun 17 '10 20:06

Pandafox


People also ask

How do you run Migration in Ruby on Rails?

1 Migration Overview Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent. You can think of each migration as being a new 'version' of the database.


1 Answers

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.

like image 136
Zepplock Avatar answered Sep 18 '22 18:09

Zepplock