Skip to content

Commit

Permalink
try112
Browse files Browse the repository at this point in the history
Warn if we can't read the yaml to create database tasks
rails/rails#36560
  • Loading branch information
suketa committed Dec 14, 2019
1 parent 6e2b1a1 commit 0aab743
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -8,6 +8,7 @@ gem 'rails', '~> 6.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'mysql2'
gem 'puma', '~> 4.3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -99,6 +99,7 @@ GEM
mini_portile2 (2.4.0)
minitest (5.13.0)
msgpack (1.3.1)
mysql2 (0.5.2)
nio4r (2.5.2)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -206,6 +207,7 @@ DEPENDENCIES
capybara (>= 2.15)
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
mysql2
pg (>= 0.18, < 2.0)
puma (~> 4.3)
rails (~> 6.0.0)
Expand Down
36 changes: 13 additions & 23 deletions config/database.yml
@@ -1,31 +1,21 @@
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
mysql: &mysql
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
host: db_mysql

postgresql: &postgresql
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: db
host: db_postgresql
user: <%= ENV.fetch("POSTGRES_USER") %>
password: <%= ENV.fetch("POSTGRES_PASSWORD") %>

development:
<<: *default
<<: *<%= ENV.fetch("DB") { 'postgresql' } %>
database: app_development

# The specified database role being used to connect to postgres.
Expand Down Expand Up @@ -59,7 +49,7 @@ development:
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
<<: *<%= ENV.fetch("DB") { 'postgresql' } %>
database: app_test

# As with config/credentials.yml, you never want to store sensitive information,
Expand All @@ -82,7 +72,7 @@ test:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
<<: *<%= ENV.fetch("DB") { 'postgresql' } %>
database: app_production
username: app
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
11 changes: 10 additions & 1 deletion docker-compose.yml
Expand Up @@ -12,16 +12,25 @@ services:
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
db:
db_postgresql:
image: postgres:12.0-alpine
volumes:
- pgsqldb:/var/lib/postgresql/data
environment:
- POSTGRES_USER
- POSTGRES_PASSWORD
db_mysql:
image: mysql:8.0.16
command: --default-authentication-plugin=mysql_native_password
volumes:
- mysqldb:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes

volumes:
pgsqldb:
driver: local
mysqldb:
driver: local
bundle:
driver: local
2 changes: 2 additions & 0 deletions scripts/parse_database_yml.rb
@@ -0,0 +1,2 @@
yml = ERB.new(File.read(Rails.root.join('config/database.yml')))
print yml.result

0 comments on commit 0aab743

Please sign in to comment.