Hacker News new | past | comments | ask | show | jobs | submit login

I find people hate/are ok with ORMs based on how they're used.

If you're using it to ad-hoc query your db then it's understandable you'll hate it - a leaky and poor abstraction over sql. Probably a bad fit.

Projects where I've seen it work well is when most of the logic is in the app with per row/per aggregate changes. In these apps it's only used for the "object relational mapping" side of things - ie to marshal types to/from db rows.

I've never found auto-migrations in ORMs good for anything less than a 1 day project - it's a world of hurt.




> I've never found auto-migrations in ORMs good for anything less than a 1 day project - it's a world of hurt.

Just to offer a counterpoint.

Every project I worked on that did not have automatic migrations was extremely flawed in other ways as well.

Manually keeping track of your DB schema, and indeed, seeing it as something separate from the code that needs to interact with it is a bad idea in my opinion.

It’s same as ‘infrastructure as code’, database also needs to be ‘database as code’.


That's why I prefer idempotent SQL DDL updates. A disk full of up/down scripts makes me nervous.

Most folks test their up scripts. They almost NEVER adequately test their down scripts, so you're left with this false sense of security moving forward even though revision 63 of 64 has a bug in the down portion…which you only find when you're trying to revert to the state of rev 60.

As for ORM migrations, of course they work. They've dumbed down your use of the database to the lowest common denominator (looking at you, MySQL).

IF EXISTS and IF NOT EXISTS are your good friend. Run the script, the database will be at the target state. When all databases are past a certain point, remove the appropriate ALTER TABLE IF EXISTS ADD COLUMN statements.

Makes source diffing much easier, is a consistent single source of truth, and allows for pruning old parts as needed.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: