Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8816003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:30:53+00:00 2026-06-14T04:30:53+00:00

Let’s say I have s different database connections… Right now for the purposes of

  • 0

Let’s say I have s different database connections…

Right now for the purposes of this example let’s only be concerned with development. When I run ‘rake db:setup’ it only creates development because from the rake task perspective the other connection is another environment. I could pass in the other connection as the RAILS_ENV to create the database. However, the problem comes in with how we’ve defined our database connections. I’d rather not undo this as it makes management and deployment much easier. What we’ve done is this…

In our database.yml we’ve added the following code.

databases_file = File.join(Rails.root.to_s, "config", "databases", "#{Rails.env.to_s}.yml")
IO.read(databases_file) if File.exist?(databases_file)

Then in a databases sub-folder under config we’ve created the different environment yml files.

So in development.yml we have…

development:
  ... details ...

logging:
  ... details ...

Now if I set RAILS_ENV to ‘logging’ it will never load the file since the file is called development.yml. Thus it will never find the logging connection.

If I consolidate all these settings back into the database.yml file then we’re back to not checking in the database.yml into the git repo and having to manually create it on the development machines for new hires and such. We’d also have to change our deploy process to start putting the file in place on the lower environments. (Our production process already supports this)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:30:54+00:00Added an answer on June 14, 2026 at 4:30 am

    We have multiple databases and we use branches heavily… so I came up with this solution to create multiple databases and tie their names to the branch being worked on…

    # config/database.yml
    <%=
        databases_file = File.join(Rails.root.to_s, "config", "databases", "#{Rails.env.to_s}.yml")
      if Rails.env.development? || Rails.env.test?
        branch = ENV['BRANCH'] || `git branch --no-color 2> /dev/null`.chomp.split("\n").grep(/^[*]/).first[/(\S+)$/,1].sub("-", "_")
        puts "Using databases for #{branch}"
        IO.read(databases_file).gsub!("<branch>", branch) if File.exist?(databases_file)
      else
        IO.read(databases_file) if File.exist?(databases_file)
      end
    %>
    

    And then you create a database file for each environment. In the development.yml and test.yml you use the token to let this script look for what it needs to in order to do replacement. So an example file would look like this.

    # config/databases/development.yml
    development:
      adapter: mysql2
      host: 127.0.0.1
      database: <branch>_dev
      username: user
      password: pass
    
    versions:
      adapter: mysql2
      host: 127.0.0.1
      database: <branch>_versions
      username: user
      password: pass
    
    reporting:
      adapter: mysql2
      host: 127.0.0.1
      database: <branch>_reporting
      username: user
      password: pass
    
    ods:
      adapter: mysql2
      host: 127.0.0.1
      database: <branch>_ods
      username: user
      password: pass
    

    I then extended the rake tasks to handle multiple databases

    This is where most of the work went in. Therefore, I’m going to leave it out of the answer and make you work for it! No actually, it’s just a big large mess that I’m not proud of and would love time to fix it, but haven’t found any. I don’t want to lead anyone down the wrong path but if you have questions just get me a message and I’ll be happy to help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have some text as follows: do this, do that, then this,
Let say I've this URL: http://example.com/image-title/987654/ I want to insert download to the part
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.