4 ms·
The data should be handled by the database, especially when there might be many different applications accessing it. Think of microservices, maybe written in di
by pmontra 9y ago
The data should be handled by the database, especially when there might be many different applications accessing it. Think of microservices, maybe written in different languages and frameworks, plus some devops running queries by hand on the db.
The ability to stop modifications inside the db is the ultimate safeguard against data corruption. If you really value your data you should also implement validations with CHECK statements and not only in the application. Think about the database as another microservice worth its own logic.
- concede_pluto 9y agoThis. You don't want to reimplement all your validation in each of your applications (plural!), and you're in for a nasty surprise if you think your entire organization has only one application using your database now and forever.
- pmontra 9y agoActually you probably should. Front end (JS SPA) for the convenience of users. Back end API (any web framework) for the convenience of developers, the users of the API. The database to make sure nobody can corrupt the data. In my experience the validations in the database almost never go past foreign keys, null fields and bounds on numeric data. Anecdote. I remember when the consensus of Rails developers was not to use foreign keys: Rails didn't have a way to define them so they probably didn't matter, right? I laughed and added them to every application of mine. Rails has foreign keys now, maybe since version 3. There are some gems to generate CHECK statements from validations.
- jstewartmobile 9y agoYou are correcting something I never said. MySQL has primary/foreign key checking, field validation, transactions, etc. I have nothing against RDBMSes. I like them! I'm talking about not doing shit like XML parsing (https://www.postgresql.org/docs/9.6/static/functions-xml.html https://www.postgresql.org/docs/9.6/static/functions-xml.htm...), or LDAP queries (https://docs.oracle.com/cd/B10501_01/network.920/a96577/dbmsldap.htm https://docs.oracle.com/cd/B10501_01/network.920/a96577/dbms...) in the database. I don't think those things belong there. Serves me right for leaving a blank on HN! People here just love to fill those with 'herp derp'.
- pmontra 9y agoI agree that they don't belong to databases. There might be use cases or there where it's ok to do that but I never run into them.
- kuschku 9y agoXML parsing definitely belongs into a major database. There’s a lot of legacy tools using XML databases, and supporting them is useful. (And they are not technically bad either)