0

I'm creating a subscription based website with exclusive video contents.

Types of Subscription
   - Basic
   - Hobbyist
   - Professional

I have 3 subscription plans, and each subscription package can only access some videos indicated in the package. So, I have to create a column that indicate what subscription plans allowed to access each video.

In the example below, the video can only be access if the customer is using Professional Subscription plan

class Video(db.Model):
    - id = 1
    - name = 'video 1'
    - allowed_subscription = ['professional']

In this another example, the video can be access by all subscription plan.

class Video(db.Model):
    - id = 2
    - name = 'video 2'
    - allowed_subscription = ['basic', 'hobbyist', 'professional']

What's the best way to implement this type of model? How can I properly implement the allowed_subscription logic?

PS: I'm using Flask and SQLAlchemy (MySQL Database)

Paulo Sairel Don
  • 129
  • 1
  • 1
  • 7
  • Possible duplicate of [How can you represent inheritance in a database?](https://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database) – philipxy Jun 24 '19 at 09:49
  • That question uses "inheritance" but the concept is also "subtyping" & "polymorphism". But it's a faq--there are plenty other duplicates. Also subtyping is a special case of "hierarchical relationship/association" & [that's a faq](https://stackoverflow.com/q/4048151/3404097). And a common antipattern for this is "2/many/multiple FKs to 2/many/multiple tables" so see those faqs too. Please research. Also-- – philipxy Jun 24 '19 at 10:07
  • There's no such thing as "better"/"best" in engineering unless *you* define it. Also unfortunately all reasonable practical definitions require a ridiculous amount of experience with a ridiculous number of factors that interact with chaotic sensitivity to details. Make straightforward designs. When you demonstrate via measurement that a design and all alternatives you can think of have problems (whatever that means at the time), then ask a very specific question. Which should also define "better"/"best". [Strategy for “Which is better” questions](https://meta.stackexchange.com/q/204461) – philipxy Jun 24 '19 at 10:07
  • Thank you! Honestly, this is my first time to hear MySQL can do inheritance, subtyping and polymorphism. Definitely, I need to dig more about MySQL Database. – Paulo Sairel Don Jun 24 '19 at 15:53
  • 1
    On the other hand, you don't need those in this case. A simple table of subscriptions and a many-to-many relationship between subscriptions and videos should suffice. – Ilja Everilä Jun 24 '19 at 20:02
  • @IljaEverilä Yeah because there's no per-type data. (Yet.) – philipxy Jun 24 '19 at 20:29
  • "MySQL can do inheritance, subtyping and polymorphism" -- Well, superficially. But you really need to get those terms out of your head while you learn the primitive things that SQL has -- JOINs, UNIONs, subqueries, indexes, plus a few patterns like many:many and 1:many; and not much else. – Rick James Jun 24 '19 at 21:43

0 Answers0