evertap
Frameworks

Ruby on Rails

Use an evertap PostgreSQL or MySQL database with Rails, with database.yml, migrations, and a test database that stays apart from your development data.

Each evertap database runs on a PostgreSQL or MySQL instance of its own, and the user in its URL can create and drop databases there. bin/rails db:create and db:test:prepare work as they do on a database you run yourself.

Create the database

evertap create postgres myapp     # or: evertap create mysql myapp
evertap env myapp >> .env

Rails does not read .env by itself; the dotenv gem loads it. Add it to the Gemfile:

gem "dotenv", groups: [:development, :test]

On a laptop that reaches evertap on another machine, keep evertap connect running while you work (Connect from your laptop).

Keep tests off your development data

Rails applies DATABASE_URL to whichever environment runs, tests included, so bin/rails test would run on your development database and its fixtures would delete the data there. Give each environment its own URL in config/database.yml, in place of their database: lines. A url: written there makes Rails ignore DATABASE_URL:

development:
  <<: *default
  url: <%= ENV["DATABASE_URL"] %>

test:
  <<: *default
  url: <%= ENV["TEST_DATABASE_URL"] %>

In .env, copy the line and change only the database at the end:

DATABASE_URL=postgres://evertap_k3x9q2m7v1ab:…@ev.internal:5432/evertap_k3x9q2m7v1ab
TEST_DATABASE_URL=postgres://evertap_k3x9q2m7v1ab:…@ev.internal:5432/myapp_test

Migrate and test

bin/rails db:migrate
bin/rails db:test:prepare     # creates myapp_test and loads the schema
bin/rails test

On PostgreSQL, parallelize in test_helper.rb gives each worker a database of its own on the same instance. On MySQL, see MySQL.

MySQL

A mysql:// URL uses the mysql2 adapter. For Trilogy, start both URLs in .env with trilogy:// instead.

Parallel tests in processes stop on MySQL with "Unknown database". Rails creates a worker's database only when connecting to it fails, and evertap's MySQL entry accepts the connection and reports the missing database at the first query instead. Run them in threads, which share the test database:

parallelize(workers: :number_of_processors, with: :threads)

Good to know

  • With config.active_record.schema_format = :sql, Rails runs pg_dump on your computer, and pg_dump refuses a database of a newer major version than itself. Install the client of your database's version, PostgreSQL 18 unless you picked another, or create the database with --version to match your client.
  • evertap does not offer PostgreSQL's own TLS. Leave sslmode out of the URL, or set it to disable; sslmode=require fails.
Edit on GitHub

The evertap name and logo are not licensed with the code (section 6 of the license). You may use them to refer to evertap, but not to name or brand your own product or service, or in a way that suggests evertap made or endorses it, without permission.

evertap is an independent project. It is not affiliated with, endorsed, sponsored, supported, or certified by the owners of the software it runs, and it uses their names only to say which software that is.

  • Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.
  • MySQL is a registered trademark of Oracle and/or its affiliates.
  • Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd.
  • Other names, including Garage and Cloudflare, may be trademarks of their respective owners.

On this page