Rails 7 adds support for setting the schema dump filepath in the database config


One of the best features of Rails is its ORM, Active Record which makes it easy to interface with various database engines and even multiple databases themselves. However, not every database-specific task was available to these shards.

Only in Rails 6 was additional database-specific rake tasks for multi-database users added. This allowed tasks like schema dumps to be run on individual databases via rails db:schema:dump:primary and more.

Before

However, doing this will not allow users to specify the schema dump filepath. All dumps will write to the same location. This was quite troublesome as there was no easy way to quickly dump all shards without manual intervention.

After

Fortunately, this PR allows users to set the filename of the schema or structure dump in the database config.

  production:
    primary:
      database: my_db
      schema_dump: my_schema_dump_filename.rb
    animals:
      database: animals_db
      schema_dump: false

The filename set in schema_dump will be used by the application. It is also possible to toggle dumping itself by setting schema_dump to false.

Join Our Newsletter