How to rebuild database with capistrano

I’ve deployed an application using Capistrano.

But on my local machine I edited one of the earlier migrations. I’ve
tried “cap deploy_with_migrations”, but it looks like it didn’t rebuild
the database.

How can I do the equivalent of this using Capistrano?
“rake db:migrate VERSION=0”
“rake db:migrate”

I’m not sure if Capistrano comes with a built in method to do this,
If you can gain access to the production machine you can just run

rake db:migrate VERSION=0
or
rake db:migrate VERISON=0 RAILS_ENV=production

to redump it.

Otherwise you can always just access the database directly, drop the
schema, and recreate it.

On Oct 22, 2007, at 6:03 PM, [email protected] wrote:

schema, and recreate it.

“rake db:migrate VERSION=0”
“rake db:migrate”

Editing a migration doesn’t change the version number that the system
thinks the schema is right now.

In any case, you probably need to do this manually. If the target
machine is some type of POSIX (unix, etc.), you can probably do:

env RAILS_ENV=production rake db:migrate VERSION=x

To force a migration to ‘x’ from wherever you are now.

You can try to do this with:

cap invoke COMMAND=“env RAILS_ENV=production rake db:migrate
VERSION=0” ROLES=app

It might be that you want the ROLES=db, but if you have everything on
a single host, that doesn’t matter anyway (you could replace ROLES=db
with HOST=yourhost.com if you want/need to be specific).

I think this works with both cap1.x and cap2.0, but I’m just typing,
not testing, so your results may vary. (Since you want to wipe the
database, I feel fairly safe suggesting that you try it.)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

Well,

I am talking crap; the remote deployment under current does contain a
Rakefile and I just logged in and ran a rake task manually to migrate my
database.

But for me; the cap invoke task does not work and just says that no rake
file can be found.

I am using Capistrano 2.1.0 and my general deployments work fine.

Cheers,
Paul

Hey;

When you issue the cap command that will presumably try to tun the rake
command on the remote server, it just tells me that it can’t find a
rake file.

The remote code has not been capified and so has no rake file, so unless
you want to check the rake file in to your source code I don’t see this
one working.

Please shout if talking crap though.

Cheers

cap invoke COMMAND=“env RAILS_ENV=production rake db:migrate
VERSION=0” ROLES=app

It might be that you want the ROLES=db, but if you have everything on
a single host, that doesn’t matter anyway (you could replace ROLES=db
with HOST=yourhost.com if you want/need to be specific).

I think this works with both cap1.x and cap2.0, but I’m just typing,
not testing, so your results may vary. (Since you want to wipe the
database, I feel fairly safe suggesting that you try it.)

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs