Closed danielmklein closed 2 years ago
Thanks!
Shouldn't deleting create a new migration that drops the logidze trigger? 🤔
Shouldn't deleting create a new migration that drops the logidze trigger? 🤔
My two cents: that would not align with how eg the original rails destroy model MyModel
works. Running rails destroy model MyModel
deletes the model class file and the table create migration, but it doesn't generate a "drop table" migration, correct?
In other words, as I see it, rails destroy ...
destroys the code files by the corresponding rails generate ...
command, not the actual database etc objects.
Makes sense. However I do think it might make sense to have a task that would revert the migration. Essentially running the down
part.
Fixes #205
What is the purpose of this pull request?
As described in #205, currently when someone does
rails generate logidze:model MyModel
and then wants to revoke that generation withrails destroy logidze:model MyModel
, the injectedhas_logidze
is removed from the model file, but the created migration file is not deleted. This PR fixes that.What changes did you make? (overview)
Remove the
migration_file_name
method fromModelGenerator
entirely.After digging, I discovered that this method was clobbering an
attr_accessor
of the same name in the underlying generator plumbing inRails::Generators::Migration
(lib/rails/generators/migration.rb
inrailties
), which was causing themigration_exists?
in that same file not to work as expected. This was, in turn, causing code inRails::Generators::Actions::CreateMigration
(lib/rails/generators/actions/create_migration.rb
inrailties
) not to realize that there was already a matching migration file existing with a prior migration number (which we should delete), so it would fall back to using the "current" migration number, for which a file doesn't exist.Is there anything you'd like reviewers to focus on?
Are there edge cases or things to consider that I'm not thinking about? I am very new to this codebase and thus fairly unfamiliar, so I have somewhat of "blinders" on and am focused on my specific use case.
Checklist