News for hackers. Stuff that matters.
Re:How to Get Foreign Keys Horribly Wrong by cogman10 on Friday July 18, 2025 @03:25PM (#44608805)
This sort of thing hasn't really done much to make me like ORMs.

It seems like a lot of code to generate the tables in the first place and you STILL need to read the output scripts just to ensure the ORM isn't generating some garbage you didn't want.

That seems like a lot of extra effort when a simple migration service (such as liquibase) could do the same work running SQL directly. No question on "which indexes are getting created and why". No deep knowledge of Django interactions with sql. Instead, it's just directly running the SQL you want to run.

Re:How to Get Foreign Keys Horribly Wrong by wvenable on Friday July 18, 2025 @04:13PM (#44609291)
I do read my migration scripts generated from an ORM to make sure my source code is correct.

Liquibase starts with "Write your database change code in your preferred authoring tool in SQL, YAML, JSON, or XML." So instead of just having my ORM generate that and I just have to read them to ensure correctness, I have to manually write change scripts instead? I don't see how that's is comparable.

Liquibase could certainly come in after I have some SQL scripts generated from my ORM and do whatever it does.

Re:How to Get Foreign Keys Horribly Wrong by viapivov on Saturday July 19, 2025 @02:29AM (#44613086)
For some reason, programmers still think that writing is always slower than reading
Re:How to Get Foreign Keys Horribly Wrong by wvenable on Saturday July 19, 2025 @09:10PM (#44620992)
Not-writing is infinitely faster than writing. Writing doesn't keep you having to read.
Re:How to Get Foreign Keys Horribly Wrong by teaearlgraycold on Friday July 18, 2025 @03:32PM (#44608878)
I would say automatic migration generation isn’t a necessary or particularly important part of an ORM. ORMs are there to map your database relational objects to your client language’s objects.
Re:How to Get Foreign Keys Horribly Wrong by cjs_ac on Friday July 18, 2025 @03:47PM (#44609025)
I think the person you're replying to is arguing for using some sort of database migration library without using an ORM library. It's the same position I came to recently.
Re:How to Get Foreign Keys Horribly Wrong by teaearlgraycold on Friday July 18, 2025 @04:43PM (#44609622)
Yes but they seem to have switched because they didn’t like ORM-generated migration code. I think that’s a bad reason to switch because it wasn’t an important part of ORMs in the first place. Basically, I want to know why they were even using ORMs before.

I don’t want to go without an ORM because I’ll end up making one ad-hoc anyway. I’m not going to do work on raw tuples in my application code.

Re:How to Get Foreign Keys Horribly Wrong by pphysch on Friday July 18, 2025 @04:08PM (#44609225)
Most(?) devs nowadays are introduced to database migration tools as a DX feature.

"Wow, 1-2 command and my app and database are in sync!"

In reality, migration tools are 100% about data loss prevention.

If you do not care about data loss, updating your schema is trivial, just drop everything and create. Dev environments should be stateless anyways, using separate data "fixtures" when needed.

Data loss itself is a highly nuanced topic. Some data is replaceable, some might be protected in a separate store. So I agree that ORMs should challenge the assumption that automatic migration tools need to be part of their kitchen sink.

Re:How to Get Foreign Keys Horribly Wrong by teaearlgraycold on Friday July 18, 2025 @04:46PM (#44609647)
I like that they provide the basic structure of how to apply yet unseen migrations. But they don’t need to generate the SQL at all. You quickly learn to never trust the generated code. It always needs to be manually reviewed.
Re:How to Get Foreign Keys Horribly Wrong by wagwang on Friday July 18, 2025 @07:58PM (#44611178)
The ORM auto migration tools are a 100% a DX feature. Obviously any serious application will have complicated migrations that outgrow the generated sql; doesn't mean its not a nice to have feature for quick iteration.
Re:How to Get Foreign Keys Horribly Wrong by pphysch on Saturday July 19, 2025 @02:14PM (#44617908)
I largely agree, but the cargo-culting around every migration operation being "reversible" suggests everyone isn't on the same page here. Too much straddling of the line (gulf) between DX tool and production data management tool.
Re:How to Get Foreign Keys Horribly Wrong by solarkraft on Monday July 21, 2025 @01:30AM (#44632054)
But that’s close to the same thing. No data loss is a non negotiable (or very expensive) requirement, so we have to make migrations work somehow.
Re:How to Get Foreign Keys Horribly Wrong by Tostino on Friday July 18, 2025 @03:49PM (#44609034)
I'd call it an anti-feature for most long-lived projects that will end up needing migrations through its lifetime.

I go the liquibase route for migrations, and just use the mapping portion of any ORM.