5 Thing You Didn't Know YOU CAN DO with Check Constraints!
Vložit
- čas přidán 3. 07. 2024
- Data hygiene is important when managing a database. Postgres has build in mechanism to ensure you can only enter properly formatted data into your database using check constraints.
In this video, / dshukertjr shows four different ways, plus a bonus, to use check constraints to restrict what type of data can be entered into the database. Starting with numeric constraints, regex constraints for text columns, time-based constraints for timestamps and date, and using check constraints to simulate enum values.
00:00 Why we should be using check constraints
00:13 Numeric constraints
01:54 Constraints using regex
02:46 Time based constraints with timestamps and date
04:14 Using check constraints instead of enums
07:31 Lead to JSON constraints
💻 Videos to watch next:
▶ • Use this to lock down ...
▶ • Make your queries 43,2...
▶ • Self-host Maps with Pr...
👇 Learn more about Supabase 👇
🕸 Website: supabase.com/
🏁 Get started: app.supabase.com/
📄 Docs: supabase.com/docs
🔔 Subscribe for more tutorials and feature updates from Supabase: / @supabase
📱 Connect with Us:
🐙 Github: www.github.com/supabase
💬 Discord: www.discord.supabase.com/
🐦 Twitter: / supabase
▶ Instagram (follow for memes): / supabasecom
ABOUT SUPABASE:
Supabase is the open source Firebase alternative. Supabase provides a full Postgres database for every project with pgvector, backups, realtime, and more. Add and manage email and password, passwordless, OAuth, and mobile logins to your project through a suite of identity providers and APIs.
Build in a weekend, scale to millions.
#Supabase #AppDevelopment #RealtimeApps #DeveloperTools - Věda a technologie
The one with date column example was my favorite! Which example was your favorite? Do you have other ways you are utilizing check constraints? Let us know in the comments 👇
Keeping the rules in the sql datastore. This makes me happy.
Holy cow... I can't believe this kind of content is coming from the actual team that is making the software/service. Keep up the great work!
A lot more Postgres content coming from the Supabase team 💪
Love the content. It should be said that not everything needs to be constrained at the DB level. It’s not extensible.
Every usecase has a different solution for sure, and every solution has its pros and cons. What do you mean extensible here?
Perfectly timed. I was only wondering last night whether I should add enums for my Web app or use constraints
Right on time!
Thanks for the video, i learn a lot from them... Keep it up please! Kudo's on the quality, really good!
Glad to hear it's helping you out! I'm also learning a lot through creating these videos! Thanks for such a nice comment!
Very interesting! Thanks
Super useful! Thank you! 🙌🏾
Glad to hear that you liked it!
❤❤❤
I liked those simple and clean exemples.
But for the enums part, while what you have shown seems convenient from a migration point of view, you loose the generated typings no?
Yes, that is one thing you lose, but it's not that hard to modify your generated Typescript file to add those types manually. Also, if you prefer to just keep using enums, that is totally fine too.
ts support pls
For the enum?
@@Supabase Nah, for the check constraints. (type gen)