> And of course you can get quite clever and fun here....create a function that checks if a function is a fibonacci number
The fact this is presented as a reasonable (trivial!) thing to embed in the DB screams, this is a terrible place to work.
> And of course you can get quite clever and fun here....create a function that checks if a function is a fibonacci number
The fact this is presented as a reasonable (trivial!) thing to embed in the DB screams, this is a terrible place to work.
I agree on the fib constraint, though. Fun, but nothing you'd ever really do.
> embedding business logic in SQL along with the server app and whatever presents data to third parties, is just making everything harder
Not in many cases. In the past 15-20 years, think about how many application stacks have come and gone. We've had Postgres that whole time, and plsql. Core business logic in the DB never needs to be rewritten, no matter how many different front-end rewrites you go through.
And logic in the DB is inherently capable of only scaling as large a your DB cluster (i.e. not very), and can cause your DB cluster to scale prematurely (an event which incurs a lot of potential technical debt and additional monitoring).
If "you can't have a price <= 0" is a business rule then it should be enforced in all layers: in the UI because you want to warn the user they're trying to do something incorrect without sending obviously invalid data to the server, in the back-end because you don't want to write incorrect data to the database, and in the database because you don't know that someone else will not write "just a quick app" that will bypass your back-end and mess up the data.
Of course you can. For example, constraints inside triggers. A simple insert trigger will only apply on records going forward.
Also, the reason why you bother with "additional" constraints by implementing them on the database is because the database is typically the thing that can enforce them. Unless you go out of your way to roll your own single-write via queue or something.
I'm not sure I agree with your take-away since you can just drop constraints. Easy come, easy go. Meanwhile bad data is easy come and potentially a nightmare to fix.
Or you can just expand the constraint to superset of two, or figure out how the old data needs to be treated by new system and migrate it. There are many right options if you actually care about data integrity that are not as easy as not caring. Doesn't make it good general advice not to care.
If there was a way to distinguish "old" and "new" data, you could write your constraint to honor the difference.
> therefore you must implement those constraints somewhere else and if you have those constraints there anyway, why bother with additional ones.
IMHO, if you must only have one set of constraints, put it in the data store.
The thing about constraints is that they provide pretty solid guarantees that let you better reason about the data at its base level.
You can't reason well about data that was "checked" by dozens of different versions of validations over time. What you have in that case is garbage in need of cleanup.
So you'll never again use a uniqueness or foreign key constraint?
Also, I don't know what pocmeans, bit it provides no insight into the problems you had and why it was ok to accept otherwise bad data.
> The fact this is presented as a reasonable (trivial!) thing to embed in the DB screams, this is a terrible place to work.
Yes, a cute example showing you that you can constrain by anything is indicative of how terrible a place this is! /s
A filesystem is just a hierarchical key-value database.
Assuming you do believe in file permissions, why wouldn’t you use the additional sanity of validation available in a SQL database?