Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
hjk10156962yDatabase constraints are nice for some consistency guarantees but do not replace validation. First of all you place business logic in the persistent layer. Error handling (reporting) becomes depended on specific database technology used.
Some validations are context based. The database must than allow for the least constrictive. For example only admin users may set an enum field to verified. The database should contain that value in the enum field even though other users should fail to set it so.
A lot of validations are (near) impossible to put into constraints.
For example this table:
|id|version|name|email|
We can't set a unique constraint on the email column because multiple versions of the id must allow it. Also in the history of another user the email may exist and that is fine but we don't want the same email in the latest version of any other user than we are currently saving. -
Two reasons.
It's faster to test a change like that inside the model. Migrations have a way of taking a long time on tables with a lot of data.
It's more risky to run a migration that it is to change code. Yes, you should have backups. But lost time is gone forever.
Related Rants
-
mcraz17Someone advised him that WP runs faster on Ruby. Now, he wants me to port WordPress to RubyOnRails !!!
-
ausername3Just solved a bug I was trying to solve for hours. Oh, the pleasure of closing 12 tabs at once without wanting...
-
vedipen19Elon Musk makes a front end website containing a single alphabet in html and everyone loses their mind. Meanwh...
Why does rails have validation at the model layer? Isn't that what the table schema/migration is for?
question
rails