You cannot delete old Rails Engine migrations which is inconsistent with what the docs say

According to the Active Record Migrations Old Migrations section you can delete old migration files. There are many articles which recommend doing this, for a variety of reasons such as cleaning up the code base.

However, Rails Engines work by copying over migrations and adding a special comment to them (https://guides.rubyonrails.org/engines.html#engine-setup).

This means that if I delete all old migrations and then re-run rails blorgh:install:migrations, it will add the engine migrations again, and re run them, which will cause migration errors.

I think this is either a bit of an inconsistency with the docs (specifically where it says you can delete old migrations), or an issue with how the engine migrations work.

I think when you install Rails Engine migrations a special file should be created indicating which engine migrations have been installed, that way if you try to install migrations again, it won’t have to rely on the migrations existing in the db/migrations/ directory.

Does this sound like a good idea? Am I missing something with Engines which would let you delete old migrations on the main app without any issues?

1 Like