Rails adds the ability to ignore tables in SQL schema dumps via regular expressions

Rails releases a new feature that allows developers to ignore tables via regular expressions when creating SQL schema dumps. This improvement builds upon the existing ability to ignore tables in schema.rb dumps, which has been available in Rails for some time.

The class ActiveRecord::SchemaDumper is used to dump the database schema from a connection to an output format (i.e., ActiveRecord::Schema). It uses ActiveRecord migration files to create a schema file.

ActiveRecord::SchemaDumper.ignore_tables is list of tables that should not be dumped into the schema. Acceptable values are strings as well as regexp’s.

However, to ignore tables via regexp we have to add an extra configuration: ActiveRecord.schema_format == :ruby.


Earlier, without the extra configuration, if a regexp is added to ActiveRecord::SchemaDumper.ignore_tables an error is thrown.

ActiveRecord::SchemaDumper.ignore_tables << /^dynflow_.*$/

Now if we try and dump the structure using rake db:structure:dump, this error is thrown:

TypeError: no implicit conversion of Regexp into String


Thanks to this PR, we can add regexp’s to ActiveRecord::SchemaDumper.ignore_tables without any extra configuration. This feature is now available on Rails 7.1.

# This extra configuration is not needed anymore to ignore tables using regexp.
ActiveRecord.schema_format == :ruby.

SchemaDumper.ignore_tables already supports regexps for schema.rb

ActiveRecord::SchemaDumper.ignore_tables << /^dynflow_.*$/

This can be useful when using zero-downtime migration tools that create temporary tables, as it allows developers to easily exclude these tables from the schema dump. Overall, this improvement makes it easier for developers to manage their database schemas and migrate their applications with minimal downtime.

Need help on your Ruby on Rails or React project?

Join Our Newsletter