4 ms·
Honestly? I don't know of any tool that handles database migrations as well or as easily as Ruby on Rails and ActiveRecord. I have literally spun up a barebone
by t0mbstone 7y ago
Honestly? I don't know of any tool that handles database migrations as well or as easily as Ruby on Rails and ActiveRecord.
I have literally spun up a barebones Rails app just to manage my schema and migrations for a completely separate Python/PostgreSQL project before.
https://guides.rubyonrails.org/v5.2/active_record_migrations.html https://guides.rubyonrails.org/v5.2/active_record_migrations...
- diminish 7y agoI second this - migrations in Rails are fantastic. Even if you aren't using Rails you can get the styles and source code here https://edgeguides.rubyonrails.org/active_record_migrations.html https://edgeguides.rubyonrails.org/active_record_migrations.... Large open source projects such as GitLab source code are also treasures to discover migration rules. If you have a millions of users with high traffic tables you may want to check some migration guides for downtime, data migrations and batch processing here https://docs.gitlab.com/ee/development/migration_style_guide.html https://docs.gitlab.com/ee/development/migration_style_guide... If you want to have some concurrent ways of DDL operations you may benefit from https://gitlab.com/gitlab-org/gitlab/blob/master/lib%2Fgitlab%2Fdatabase%2Fmigration_helpers.rb https://gitlab.com/gitlab-org/gitlab/blob/master/lib%2Fgitla...
- WilliamMayor 7y agoThat gitlab link was a good read, thanks! One of the points was that migrations should always be reversible. I’ve struggled with this in the past when it comes to migrations that change or drop data. How do you write a downgrade script that recalls the previous data? I’ve given up with downgrades now. I make sure to take a dB backup or snapshot before running an upgrade. I’ve never had to test this solution in a tense situation though...
- diminish 7y agoOne way is to keep a polymorphic (postgres unloggged) `backups` table with bson/json field to store any table's row. use this before and after migrations and backup and truncate this frequently.
- tbrock 7y agoI wholeheartedly agree. Why do you think no other toolchain has come close to this for other languages or frameworks? It’s a very common problems that needs a solution no matter what you are building and what you are building it on.
- mkolodny 7y agoDjango's migration handling is excellent as well [0]. [0] https://docs.djangoproject.com/en/2.2/topics/migrations/ https://docs.djangoproject.com/en/2.2/topics/migrations/
- sumosudo 7y agoWe use this for migrations on the daily.. https://pypi.org/project/yoyo-migrations/ https://pypi.org/project/yoyo-migrations/
- NicoJuicy 7y agoEver tried EntityFramework in .Net ? It's amazingly easy and there are 2 ways: - Database-First - Code-First
- kerryritter 7y ago+1 for code-first migrations. It's a bit of a learning curve, but the effort is worth it imo.
- mmusc 7y agoI prefer dB first. Create an SQL project that defines the schema. It automatically compares the schema with your current dB schema and auto generates a migration script for you. Then update entities from the dB. Few steps involved but avoids writing and maintaing migrations yourself.
- breakingcups 7y agoCode-first does this too, but based on a schema you define in your code and not in your DB.
- NicoJuicy 7y agoI would like to suggest code-first, at least try it once. I don't want to go back to any sort of migrations outside of this.