i am currently learning how to work with databases in a full stack web development context. I want to model a scenario where students can enroll into a variety of events which have a certain capacity. I already looked into this thread:
How to write a constraint concerning a max number of rows in postgresql?
but couldn't quite apply it to my scenario, since it should be possible to have different capacities which can also change when the room is updated for example(the capacity references the capacity column of a room table)
Is there an elegant way to model this?
My current solution is to have a column for capacity and one for registrations that gets in-/decremented on every insert/delete. This crude check also happens client side atm, which i am aware of being a bad practice for several reasons and i am absolutely not happy with it, which is why i created this post.
I think one could at least model this server side with Postgres functions, but since i am not familiar with those yet, i wanted to ask first, whether there is a generally better way of modelling such a thing. I am using a Supabase instance for my project.
Thanks in advance everyone!