Use a SQL Schema

Learn to use a SQL schema for the database of our Rails application.

It’s rare to create an app that must connect to many different types of databases. It’s also rare to migrate from one database type to another. Thus, we should not be shy about using database-specific features whenever it helps us meet our users’ needs. However, Rails’ API for managing the database doesn’t provide access to all of these features.

This matters because Rails uses a schema file to maintain the test database as well as to initialize a development database in a fresh environment. We need that schema to match production; therefore, we cannot use db/schema.rb, and instead must use SQL. Fortunately, this is a one-line configuration change in config/application.rb:

Get hands-on with 1400+ tech skills courses.