DATABASE_URL examples for Rails DB connection strings

… and check why 5600+ Rails engineers read also this

DATABASE_URL examples for Rails DB connection strings

Recently I’ve been configuring RailsEventStore to run tests on many databases on the Travis CI. We do it using DATABASE_URL environment variable but I couldn’t find good examples easily. So here they are.

PostgreSQL

DATABASE_URL=postgres://localhost/rails_event_store_active_record?pool=5

MySQL

DATABASE_URL=mysql2://root:@127.0.0.1/rails_event_store_active_record?pool=5

Sqlite in memory

DATABASE_URL=sqlite3::memory:

Code

ENV['DATABASE_URL'] ||= "postgres://localhost/rails_event_store_active_record?pool=5"

RSpec.configure do |config|
  config.around(:each) do |example|
    ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
  end
end

You might also like