Files
fixin.me/config/database.yml.dist
barbie-bot 24539f236c Add multi-database test runner (test:all_databases)
Adds `bundle exec rails test:all_databases` which runs the full test
suite against every test database configured in database.yml in a single
command.

Convention: any top-level key starting with "test" that contains a Hash
is a test database. `test:` is the required primary; `test_<name>:` blocks
are optional additional adapters (e.g. test_sqlite, test_pg).

For each configured database the task:
  1. Checks the required adapter gem is available (skips with warning if not)
  2. Runs `rails db:test:prepare` to create and migrate the database
  3. Runs `rails test` and records pass/fail
  4. Prints a summary and exits non-zero if any database failed

Mechanism: a RAILS_DATABASE_YML env var points each subprocess to a
temporary database.yml that contains only the current test config.
config/application.rb(.dist) reads this var and overrides Rails'
database config path before initialisation, so no monkey-patching of
the test runner is required.

config/database.yml.dist is updated with documented examples for SQLite
and PostgreSQL additional test databases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 10:48:53 +00:00

74 lines
2.4 KiB
Plaintext

# If you don't want to store sensitive information, like your database password,
# in your source code, provide the password or a full connection URL as an
# environment variable when you boot the app. For example:
#
# DATABASE_PASSWORD="Some-password1%"
#
# or
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV["MY_APP_DATABASE_URL"] %>
#
# You can specify password environment variable in a similar way:
#
# production:
# password: <%= ENV["DATABASE_PASSWORD"] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
default: &default
adapter: mysql2
encoding: utf8mb4
collation: utf8mb4_0900_as_ci
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: fixinme
password: Some-password1%
socket: /run/mysqld/mysqld.sock
production:
<<: *default
database: fixinme
# Unless you're planning on developing the application, you can skip
# configurations for development and test databases altogether.
#development:
# <<: *default
# database: fixinme_dev
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
#test:
# <<: *default
# database: fixinme_test
# Multi-database testing — `bundle exec rails test:all_databases`
# ---------------------------------------------------------------
# Add any number of `test_<name>:` blocks to run the full test suite
# against additional database adapters in a single command.
# Each adapter's gem must be available in the bundle:
# bundle config --local with "mysql:sqlite" # mysql + sqlite
# bundle config --local with "mysql:pg" # mysql + postgresql
#
# Example — run tests against MySQL and SQLite:
#
#test_sqlite:
# adapter: sqlite3
# database: db/fixinme_test.sqlite3
#
# Example — run tests against MySQL and PostgreSQL:
#
#test_pg:
# adapter: postgresql
# database: fixinme_test
# username: fixinme
# password: Some-password1%
# host: localhost