Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails & Capistrano 3 - staging server trying to user production database

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
like image 372
fatfrog Avatar asked Jun 07 '15 21:06

fatfrog


People also ask

What are Rails used for?

Rails is one of many web frameworks in the world of app programming and web development. These frameworks are collections of code libraries that give app and web developers readymade solutions for time consuming, repetitive tasks—things like building menus, tables, or forms on a website.

Does Netflix use Rails?

Some of the popular companies that use Rails for web development include Shopify, Groupon, Zendesk, GitHub, Netflix, and Hulu.

Is Rails a backend or frontend?

It does so by creating default structures for your code, your application's database and the web pages your application will serve up to the client. Seeing as Ruby on Rails runs on a web server and serves up information to client programs (web browsers), it's said to be a server-side or backend application.

What is rail framework?

Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pages. It encourages and facilitates the use of web standards such as JSON or XML for data transfer and HTML, CSS and JavaScript for user interfacing.


1 Answers

With my cap 3 setup, i have a config/deploy/production.rb file where the environment gets set. Are you doing the same for both staging & production?

set :stage, :staging
server 'example.com', user: 'aaron', roles: %w{web app db}
set :rails_env, :staging

Need to be sure it sets the proper environment, so the db tasks will know what database to connect to.

like image 128
agmcleod Avatar answered Oct 17 '22 03:10

agmcleod