Re:Mongo but on Postgres and with strong consistency benefits
by pennomi on Monday July 08, 2024 @09:08AM
(#40905092)
App layer validation is for the user’s sanity. DB layer validation is for the developer’s sanity.
[ Parent
| on HN ]
Re:Mongo but on Postgres and with strong consistency benefits
by goosejuice on Monday July 08, 2024 @10:47AM
(#40905920)
I like this as a general rule, but I almost always have more refined validation at the app layer -- particularly when using jsonb.
Tool of choice is ecto which has excellent support for maintaining jsonb structure.
Re:Mongo but on Postgres and with strong consistency benefits
by papichulo2023 on Monday July 08, 2024 @09:29AM
(#40905239)
Ehhh, most dbs are managed by migrations in the application, so essentially is duplicated logic
Re:Mongo but on Postgres and with strong consistency benefits
by eropple on Monday July 08, 2024 @09:37AM
(#40905317)
Most databases eventually have a human typing an INSERT statement or the moral equivalent. It's not duplication to have your correctness functions protect that, too.
Re:Mongo but on Postgres and with strong consistency benefits
by evanelias on Monday July 08, 2024 @03:53PM
(#40908901)
I'd assume this might be solvable in the DB layer using CHECK constraints, possibly combined with JSON Schema validation?
From quick glance, JSON Schema validation isn't built-in to Postgres, but there are third-party extensions, such as https://github.com/supabase/pg_jsonschema or https://github.com/gavinwahl/postgres-json-schema.
I'm more familiar with MySQL and MariaDB, which offer it built-in: https://dev.mysql.com/doc/refman/8.0/en/json-validation-func... and https://mariadb.com/kb/en/json_schema_valid/