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.
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.
Now if we try and dump the structure using
rake db:structure:dump, this error is thrown:
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.
SchemaDumper.ignore_tables already supports regexps for
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.