palkan / logidze

Database changes log for Rails
MIT License
1.6k stars 76 forks source link

`rails destroy logidze:model MyModel` does not delete migration file #205

Closed danielmklein closed 2 years ago

danielmklein commented 2 years ago

Tell us about your environment

Ruby Version: 3.0.3

Rails Version: 6.1.4

PostgreSQL Version: 11.14

Logidze Version: 1.2.0

What did you do? / What did you expect to happen? / What actually happened?

Run the following (assuming MyModel is an existing model that does not have logidze yet):

rails generate logidze:model MyModel

# ^ this generates a migration file and injects `has_logidze` into the model class definition -- cool

rails destroy logidze:model MyModel

# ^ this removes the injected `has_logidze` from the model class definition,
# but it looks like it tries to delete a file with a different migration version number
# than the original, so it fails (the file it's looking for doesn't exist),
# and the migration file lingers around

Rest assured, I am wading through the migration code and I will push a PR for this if I can figure it out, but I wanted to raise it here in case anyone else saw a quick fix! If I am going crazy and/or doing something wrong here, please let me know.

palkan commented 2 years ago

it looks like it tries to delete a file with a different migration version number than the original

That's interesting. I wonder how rails destroy model X works 🤔

I will push a PR for this if I can figure it out

That would be awesome! I'd suggest starting with a test here: https://github.com/palkan/logidze/blob/master/spec/generators/model_generator_spec.rb

danielmklein commented 2 years ago

As an update, I made a bit of progress here -- https://github.com/danielmklein/logidze/tree/fix/migration-revoke. I have the fix working when I run rails destroy logidze:model MyModel manually now, but I haven't quite cracked why my test isn't working.

EDIT: Figured it out -- PR #206 is up!