diff options
author | David Stosik <david.stosik+git-noreply@gmail.com> | 2018-03-19 17:42:23 +0000 |
---|---|---|
committer | David Stosik <david.stosik+git-noreply@gmail.com> | 2018-03-19 17:42:23 +0000 |
commit | d3fd4e4ed9bae3775969c5c913b15bbd927e9ad9 (patch) | |
tree | e560afb7d4bc1cf4f00a26eec408aee1d299ed0b /railties/test/rails_info_controller_test.rb | |
parent | d7b72761043f8d76dd95a7198c2dbba89da13b0b (diff) | |
download | rails-d3fd4e4ed9bae3775969c5c913b15bbd927e9ad9.tar.gz rails-d3fd4e4ed9bae3775969c5c913b15bbd927e9ad9.tar.bz2 rails-d3fd4e4ed9bae3775969c5c913b15bbd927e9ad9.zip |
Expose foreign key name ignore pattern in configuration
When dumping the database schema, Rails will dump foreign key names only
if those names were not generate by Rails. Currently this is determined
by checking if the foreign key name is `fk_rails_` followed by
a 10-character hash.
At [Cookpad](https://github.com/cookpad), we use
[Departure](https://github.com/departurerb/departure) (Percona's
pt-online-schema-change runner for ActiveRecord migrations) to run migrations.
Often, `pt-osc` will make a copy of a table in order to run a long migration
without blocking it. In this copy process, foreign keys are copied too,
but [their name is prefixed with an underscore to prevent name collision
](https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html#cmdoption-pt-online-schema-change-alter-foreign-keys-method).
In the process described above, we often end up with a development
database that contains foreign keys which name starts with `_fk_rails_`.
That name does not match the ignore pattern, so next time Rails dumps
the database schema (eg. when running `rake db:migrate`), our
`db/schema.rb` file ends up containing those unwanted foreign key names.
This also produces an unwanted git diff that we'd prefer not to commit.
In this PR, I'd like to suggest a way to expose the foreign key name
ignore pattern to the Rails configuration, so that individual projects
can decide on a different pattern of foreign keys that will not get
their names dumped in `schema.rb`.
Diffstat (limited to 'railties/test/rails_info_controller_test.rb')
0 files changed, 0 insertions, 0 deletions