lorm
lorm

Reputation: 3361

How to find the code that generates the database.yml file?

I am taking over an old Rails project. This is part of a larger corporate effort to refactor much of the old technology in the company. Among the many changes, we upgraded our MySQL from 5.1 to 5.7, and we got a new, more powerful server to act as our database server. Now I want to point the Rails app at the new server.

On my Mac, where I do development, I have a database file that looks like this:

  # MySQL.  Versions 5.0+ are recommended.
  #
  # Install the MYSQL driver
  #   gem install mysql2
  #
  # Ensure the MySQL gem is defined in your Gemfile
  #   gem 'mysql2'
  #
  # And be sure to use new-style password hashing:
  #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
  #
  default: &default
    adapter: mysql2
    encoding: utf8
    pool: 5
    socket: /var/lib/mysql/mysql.sock

  development:
    <<: *default
    database: wawa_onset_development
    username: root
    password:

  # Warning: The database defined as "test" will be erased and
  # re-generated from your development database when you run "rake".
  # Do not set this db to the same as development or production.
  test:
    <<: *default
    database: wawa_onset_test
    username: root
    password:

  staging:
    <<: *default
    database: wawa_onset_stage
    username: onset_stage
    password: <%= ENV['STAGE_DATABASE_PASSWORD'] %>

  preview:
    <<: *default
    database: wawa_onset_preview
    username: onset_preview
    password: <%= ENV['PREVIEW_DATABASE_PASSWORD'] %>

  production:
    <<: *default
    database: wawa
    username: onset_prod
    password: <%= ENV['PRODUCTION_DATABASE_PASSWORD'] %>

To deploy my code to staging, I do:

  vagrant up

  vagrant ssh

  cap staging deploy 

The deploy process creates a database.yml file that looks like this:

  staging:
    adapter: mysql2
    encoding: utf8
    pool: 5
    socket: /var/lib/mysql/mysql.sock
    database: wawa_onset_stage
    username: onset_stage
    password: <%= ENV['STAGE_DATABASE_PASSWORD'] %>
    host: localhost

I need to change the "host" and the "database" and the "username", but I don't know where to change these things. We don't keep database.yml in the git repo, so I can't edit the file and commit it. I need to find the template that generates the database.yml file. Where is this typically stored? What gems are typically used to generate the database.yml file?

Upvotes: 0

Views: 647

Answers (1)

Doon
Doon

Reputation: 20232

it probably isn't a gem My guess is that it is in the shared folder of you app.

standard capistrano deployed app has structure like

shared/
repo/
current -> /path/to/releases/20160226153309
releases/

your database.yml is probably in the shared/config folder

and your deploy.rb probably has something like

set :linked_files, %w{config/database.yml config/secrets.yml}

But your deploy.rb will have the information you need to locate the file on the server.

Upvotes: 1

Related Questions