Data validation is a topic that I keep coming back...
# off-topic
a
Data validation is a topic that I keep coming back to when considering Supabase as a platform. How are people solving this today? Is the only current way to use db functions for validation?
c
For validation which can be evaluated based on the data of a single table, you can use PostgreSQL check constraints: https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-CHECK-CONSTRAINTS
You can probably also use the RLS, since RLS just requires a boolean variable to determine whether it's OK to write or NOT, and that boolean can be based on anything you need, not just auth info
finally, there is a PostgreSQL extension that allows the validaiton of JSON schema, so you can also use that if you need to validate a JSON request payload before inserting it in the DB: https://github.com/supabase/supabase/discussions/679#discussioncomment-1777145
a
Thanks chipilov. Do you know if it's possible to apply a more complicated check, like regex in a constraint check? I often find myself making sure that ppl don't intentionally (or by accident) add something that might cause problems. "Always validate user input" comes to mind 🙂
Seems like it does. Sweet! Postgres keeps surprising me in a good way