lfittl / activerecord-clean-db-structure

Automatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)
BSD 3-Clause "New" or "Revised" License
146 stars 36 forks source link

Fix Rake task enhancement for compatibility with Rails 6.1+ #31

Closed ajvondrak closed 2 years ago

ajvondrak commented 2 years ago

Rails 6.1 deprecated the db:structure:dump Rake task in favor of a combined db:schema:dump task: https://github.com/rails/rails/pull/39470 Even internally, tasks like db:migrate are now invoking db:schema:dump after the migration instead of switching between db:{structure,schema}:dump conditionally.

However, activerecord-clean-db-structure was hooking explicitly into the db:structure:dump task. This meant that your db/structure.sql would no longer be reformatted by the gem after upgrading to Rails 6.1+.

There was an existing pull request at https://github.com/lfittl/activerecord-clean-db-structure/pull/26 that just swapped the task name, but (a) that hasn't been merged in over a year and (b) it doesn't bother with a version check. The present commit improves upon the other PR by conditionally switching the task based on the version of the activerecord gem.

ajvondrak commented 2 years ago

Closing this in favor of #32, because I originally opened this against the fork's master branch instead of creating a separate branch. D'oh.