DEV Community

Masa
Masa

Posted on • Updated on

Easier database schema management with Ridgepole

Sharing ActiveRecord's schema migrations with teams

It is tough when multiple teams are working on the same Rails application and deploy stuff at a fast pace.
People create migrations without knowing the migrations the other teams are creating at the same time.
You can not ignore them because you can't have multiple sets of migrations in Rails. You can only have a set of migrations.
So you have to keep track of migrations the other teams commit to the repository while you commit your migrations.
Because of that, it is not easy to share the migrations with the other teams withouts slowing them down.

Ridgepole

https://github.com/winebarrel/ridgepole

Ridgepole is a database schema manager.
You write Ruby DSL to "Schemafile" and apply it to your database with ridgepole --apply on CLI.

With Ridgepole, you don't need to create migration files every time you want to add some changes to tables in your database.

Ridgepole compares tables in Schemafile and actual tables in the database.
Then it applies the difference with ALTER TABLE if there is any.

It also supports "dry run". Basically you can get SQL it's going to execute without actually executing it.
If you want to do a similar thing with ActiveRecord's schema migration, you need to migrate the migration and then roll it back.
(there was a PR for ActiveRecord to support dry run, but it didn't get merged. https://github.com/rails/rails/pull/31630)

Integration with Rails

There are some gems for it.

https://github.com/space-pirates-llc/ridgepoler-rails

https://github.com/masakazutakewaka/rafter
(This is my gem. I hope you check it out😁 PRs are welcome🙏)

Thank you for reading this to the end!!

references

Top comments (0)