Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #846 from omu/fix-database-yml
Browse files Browse the repository at this point in the history
Database yapılandırmasını düzelt
  • Loading branch information
roktas authored Mar 11, 2019
2 parents bf1a7eb + 9444acc commit e282824
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ def appname
self.class.module_parent.to_s.underscore
end
end

def database_url_for(env)
host = ENV.fetch('DB_HOST', 'localhost')

"postgresql://#{appname}:#{appname}@#{host}/#{appname}_#{env}"
end
end
end
7 changes: 2 additions & 5 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<% name = Rails.application.appname
url = "postgresql://#{name}:#{name}@localhost/#{name}_%{environment}" %>

default: &default
adapter: postgresql
pool: 5
Expand All @@ -9,11 +6,11 @@ default: &default

development:
<<: *default
url: <%= ENV.fetch('DEVELOPMENT_DATABASE_URL', format(url, environment: 'development')) %>
url: <%= Rails.application.database_url_for('development') %>

test:
<<: *default
url: <%= ENV.fetch('TEST_DATABASE_URL', format(url, environment: 'test')) %>
url: <%= Rails.application.database_url_for('test') %>

production: &production
<<: *default
Expand Down
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ services:
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY
- RAILS_ENV=$RAILS_ENV
environment:
TEST_DATABASE_URL: postgresql://nokul:nokul@db/nokul_test
DEVELOPMENT_DATABASE_URL: postgresql://nokul:nokul@db/nokul_development
DB_HOST: db
REDIS_URL: redis://redis:6379
ports:
- "80:3000"
Expand All @@ -35,8 +34,7 @@ services:
- RAILS_MASTER_KEY=$RAILS_MASTER_KEY
- RAILS_ENV=$RAILS_ENV
environment:
TEST_DATABASE_URL: postgresql://nokul:nokul@db/nokul_test
DEVELOPMENT_DATABASE_URL: postgresql://nokul:nokul@db/nokul_development
DB_HOST: db
REDIS_URL: redis://redis:6379
command: sh -c "bundle exec sidekiq -q high -q low"
depends_on:
Expand All @@ -50,7 +48,7 @@ services:
- RAILS_ENV=$RAILS_ENV
- NODE_ENV=$NODE_ENV
environment:
TEST_DATABASE_URL: postgresql://nokul:nokul@db/nokul_test
DB_HOST: db
REDIS_URL: redis://redis:6379
RAILS_MASTER_KEY: $RAILS_MASTER_KEY
CODACY_PROJECT_TOKEN: $CODACY_PROJECT_TOKEN
Expand Down

0 comments on commit e282824

Please sign in to comment.