I have never introduced this gem here. It is a library that we use at Doctolib (if you are french, you know it. If you aren’t, it is a healthcare system for practitioners and patients, in the top 10 of the most downloaded application in France). It makes PG migrations safe, by automatically replacing unsafe versions of a migration to its safe version.
Give it a try, and tell us what you think
Thanks for sharing. I remember a similar gem:
We don’t use it directly, but have set
lock_timeout before all migrations.
strong_migrations is a bit different, it’s detects dangerous migrations early, but it does not patch them. You’re saying that you do not use it directly, I believe that you should! It’s just one line of code in your gemfile, and then it will warn you if a migration is dangerous. There is no risk at all to install it, only benefits
safe-pg-migrations, on the other hand, patches dangerous migrations automatically. It’s totally understandable not to use it hides migration good practices (which is why actually we developped it in a first place: we could not teach correctly every of our 500 developers, so we patch it directly instead). We use it in one of the busiest production environment in France, it’s definitively battle tested.
online-migrations is similar to safe-pg-migrations. I’ve never used it directly (though I’ve apparently written part of the readme ), I can’t say if it’s going to scale in a big environment. Looking at the downloads on RubyGem though, it looks like it only have a fraction of the traffic of safe-pg-migrations.
online_migrations is similar to
strong_migrations - it does not (neither allow to) patch anything, only suggests concrete steps (compared to
strong_migrations, which only suggests abstract steps to perform). But I remember I spied a feature or couple of from the
I personally do not prefer implicit things, because I always forget and needs to double check if it performs what I want. And there are some migrations you cannot automatically perform, like a simple column renaming, for example. You can only do simple operations automatically, like adding
algorithm: :concurrently when creating an index. But you always can explicitly suggest the steps to perform, which the other two gems do.
Yeah, there are not so much downloads (~100k in 1.5 years) on the RubyGems, but most
safe-pg-migrations downloads (~700k) are probably from a single company.
strong_migrations has much more, because it was first and was created a long time ago.
We have indeed decided not to tackle the warning part, as
strong_migrations does an excellent job here. Instead, we have made
safe_pg_migrations compatible with
strong_migrations. The gem will work with and without
The idea is that we detect if
strong_migrations is installed, and if it is, we mark methods that we handle as safe. Then in our product codebase, developers will be able to write the migration without safety assured, and if
strong_migrations does not complain, they will be able to merge. For cases like renaming a column, the warning of
strong_migrations would be displayed.