• D
    Expose foreign key name ignore pattern in configuration · d3fd4e4e
    David Stosik 提交于
    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`.
    d3fd4e4e
schema_dumper.rb 8.4 KB