0
0
Ruby on Railsframework~20 mins

Database setup for production in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Production Database Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Rails production database configuration
In a typical Rails app, where should you specify the production database credentials?
AIn the config/database.yml file under the production section
BDirectly in the config/environments/production.rb file
CInside the Gemfile
DIn the app/models/production.rb file
Attempts:
2 left
💡 Hint

Think about where Rails expects database connection details for different environments.

component_behavior
intermediate
1:30remaining
Effect of missing production database config
What happens if you try to run rails db:migrate RAILS_ENV=production but the production database is not configured properly?
ARails raises a connection error and migration does not run
BRails runs migrations on the development database instead
CRails creates a new SQLite database automatically
DRails skips migrations silently without error
Attempts:
2 left
💡 Hint

Consider what happens when Rails cannot connect to the specified database.

📝 Syntax
advanced
2:00remaining
Correct production database.yml snippet
Which of the following is the correct way to specify a PostgreSQL production database in config/database.yml?
A
production:
  adapter: postgresql
  encoding: utf8
  database: myapp_development
  pool: 5
  username: myuser
  password: mypass
B
production:
  adapter: mysql
  encoding: utf8
  database: myapp_production
  pool: 5
  username: myuser
  password: mypass
C
production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
D
production:
  adapter: postgresql
  encoding: unicode
  database: myapp_production
  pool: 5
  username: myuser
  password: mypass
Attempts:
2 left
💡 Hint

PostgreSQL uses adapter: postgresql and production database name should match environment.

🔧 Debug
advanced
2:00remaining
Debugging production database connection error
You deployed your Rails app and get this error when accessing it: PG::ConnectionBad: could not connect to server: Connection refused. What is the most likely cause?
AThe Rails secret key base is not set
BThe Rails app is missing the 'pg' gem in the Gemfile
CPostgreSQL server is not running or not reachable from the app server
DThe database.yml file has a syntax error in the development section
Attempts:
2 left
💡 Hint

Connection refused usually means the app cannot reach the database server.

state_output
expert
2:00remaining
Result of running migrations with multiple environments
Given this command run on a Rails app: RAILS_ENV=production rails db:migrate
Assuming the production database is configured and migrations exist, what is the state of the development database after this command?
AThe development database is reset and migrated
BThe development database remains unchanged; only the production database is migrated
CBoth development and production databases are migrated
DThe command fails because it tries to migrate both environments
Attempts:
2 left
💡 Hint

Consider how Rails handles environment variables for database commands.