18

DATABASE_URL examples for Rails DB connection strings

 3 years ago
source link: https://blog.arkency.com/database-url-examples-for-rails-db-connection-strings/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:
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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK