I've setup a server for my staging environment using NGINX & Passenger. I've also setup a staging.rb file which is a duplicate of my production.rb file under environments. In my database.yml file I've put in a staging configuration:
staging:
adapter: mysql2
database: myapp_staging
username: root
password: xxxxxxxxxxxxx
port: 3306
pool: 15
timeout: 5000
Environments/staging.rb:
role :app, %w{[email protected]}
role :web, %w{[email protected]}
role :db, %w{[email protected]}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.
server '111.111.111.111', user: 'deploy', roles: %w{web app db}, port: 0001
I deploy with cap staging deploy
however the app won't start and in the logs it says: Unknown database 'myapp_production'
How can I force it to use the staging database?
EDIT
Deploy.rb:
set :application, 'dispatch'
set :repo_url, 'myapp'
set :deploy_to, '/home/deploy/myapp'
set :scm, :git
set :branch, 'master'
set :keep_releases, 5
set :format, :pretty
set :log_level, :debug
set :pty, true
set :passenger_restart_with_sudo, true
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :rvm_map_bins, fetch(:rvm_map_bins, []).push('rvmsudo')
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
config/database.yml
file in your repository that is pointing tomyapp_production
database. See the2. Move secrets out of the repository.
section in capistranorb.com/documentation/getting-started/… to learn how to deal with database.yml while deploying with capistrano. Essentially, you will need to keep a staging/production version of the file on the respective server, and copy it to the required location while deploying. – Wildman