Search code examples
ruby-on-railsnginxsqlitecapistranoproduction

How to deploy Rails sqlite3 database with Capistrano?


I deploy like this:

bundle exec cap deploy:cold
RAILS_ENV=production rake db:migrate
bundle exec cap deploy:migrate

Error in log file:

I, [2014-04-14T14:15:14.853543 #10769]  INFO -- : Started GET "/users/sign_up" for
176.192.228.14 at 2014-04-14 14:15:14 -0400
I, [2014-04-14T14:15:14.856055 #10769]  INFO -- : Processing by
Devise::RegistrationsController#new as HTML
I, [2014-04-14T14:15:14.857398 #10769]  INFO -- : Completed 500 Internal Server Error
in 1ms
F, [2014-04-14T14:15:14.860844 #10769] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'users')

But in the current/db folder was created production.sqlite3. On localhost:3000 it works. How can I migrate the database for production with Capistrano?

I use Nginx and Unicorn and this is my repository.


Solution

  • Working with Sqlite in production is very problematic because each time you deploy new version you entiredb is stay on the old release folder, what you can do is when you deploy add this command:

    task :copy_sqlite, roles: :app do
        run "cp #{current_path}/db/production.sqlite3 #{release_path}/db/"
    end
    

    just add this the before rake db:migrate and it will solve your problem.

    My strong suggestion move to PostgreSQL/MySQL.