Hacker News new | ask | show | jobs
by mrkeen 2594 days ago
I try to keep code out of my data where possible. No triggers, no constraints (excepting maybe PRIMARY KEY and NOT NULL). Despite otherwise being a nutter for type safety, I'll even favour TEXT over enums.

The main reason is change. As I evolve the code base, I might want to do something today which is principled, but seemed unprincipled yesterday. Database constraints have tended to hit me the hardest at the worst times too, e.g. being unable to make an emergency fix in prod. Or prod can't come up because the flyway script (which succeeded in test/stage) got snagged on a constraint when it ran on prod data.

1 comments

No triggers, no constraints (excepting maybe PRIMARY KEY and NOT NULL)

Could you not then simply use a nosql solution?

Or you can have that logic at a back-end application level (assuming all clients are going through this one back-end to interact with the database).
I use both.