5 Thing You Didn't Know YOU CAN DO with Check Constraints!

Sdílet
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

Komentáře • 21

  • @dshukertjr
    @dshukertjr Před 6 dny +8

    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 👇

  • @mrrolandlawrence
    @mrrolandlawrence Před 5 dny +2

    Keeping the rules in the sql datastore. This makes me happy.

  • @Trashmanatx
    @Trashmanatx Před 6 dny +5

    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!

    • @dshukertjr
      @dshukertjr Před 5 dny

      A lot more Postgres content coming from the Supabase team 💪

  • @funkdefied1
    @funkdefied1 Před 6 dny +5

    Love the content. It should be said that not everything needs to be constrained at the DB level. It’s not extensible.

    • @dshukertjr
      @dshukertjr Před 6 dny

      Every usecase has a different solution for sure, and every solution has its pros and cons. What do you mean extensible here?

  • @ryanmouritz
    @ryanmouritz Před 6 dny +3

    Perfectly timed. I was only wondering last night whether I should add enums for my Web app or use constraints

  • @EmielvanGoor
    @EmielvanGoor Před 6 dny +4

    Thanks for the video, i learn a lot from them... Keep it up please! Kudo's on the quality, really good!

    • @dshukertjr
      @dshukertjr Před 6 dny +1

      Glad to hear it's helping you out! I'm also learning a lot through creating these videos! Thanks for such a nice comment!

  • @nerrydanna
    @nerrydanna Před 5 dny +2

    Very interesting! Thanks

  • @andreh.9300
    @andreh.9300 Před 6 dny +2

    Super useful! Thank you! 🙌🏾

    • @dshukertjr
      @dshukertjr Před 5 dny

      Glad to hear that you liked it!

  • @kamil_supabase_enjoyer
    @kamil_supabase_enjoyer Před 6 dny +2

    ❤❤❤

  • @guilhemheinrich9110
    @guilhemheinrich9110 Před 5 dny

    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?

    • @dshukertjr
      @dshukertjr Před 5 dny

      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.

  • @erdemarslan3371
    @erdemarslan3371 Před 3 dny

    ts support pls