Capistrano Rails deploy with new migration files

138 views Asked by At

I want to deploy from a new branch I have created. On this branch, the db/migrate content has changed, I removed some migration files and regenerated a new one.

The problem is, when I cap staging deploy from this branch, it fails when running migrations PG::DuplicateTable: ERROR: relation "partners" already exists.

I want to run rake db:drop and rake db:setup on the server(no real data), but first I need to have an updated content in my app_name/current/db/migrate folder.

How can I accomplish this?

2

There are 2 answers

0
Bogdan Popa On BEST ANSWER

I ended up disabling require 'capistrano/rails/migrations' from my Capfile and ran rake db:drop rake db:setup from the server.

0
TarunJadhwani On

You can override cap db:migrations in config/deploy.rb by adding

namespace :deploy do
  desc "No ActiveRecord override"
  task :migrate do
  end
end

This way when you deploy it won't run the migrations, then you can go to the server and run rake tasks for dropping and resetting the database.

Note: It is not advisable that you edit, delete any migration files. Just create a new migration if you want to edit any columns or tables.