twoam
twoam

Reputation: 892

How to structure/handle paid features in the database

I am having trouble with handling paid features for users. Basically users can buy multiple features to use.

A really silly example, but it explains what I want:

It's a todo list and user can add/complete a task for free. If he wants to delete that task he has to buy that feature first. If he wants to edit that task he has to buy that feature also.

Now my problem comes in place. What is the best way to add features to a specific user in the database? I could create multiple roles which have features attached to them, but I feel like this is gonna be a mess when I add more features.

I also could add a paid_features column in the users table with the id of the paid features. I feel like this is the best way to do it?

Any thoughts on this or better ideas?

Upvotes: 0

Views: 36

Answers (1)

SK -
SK -

Reputation: 469

You can try keeping the features out of the user table. It will keep you out of the mess after your application has more features.

User Table - your user details, Primary Key - user_id.

Feature Table - your feature table, this will be used to identify the different features you have and used to identify different functionality. Primary Key - feature_id.

User_feature - This will be used to identify different features allowed to a user. You can modify the table as per what features the user has purchased or allowed for free.

Column - User_id and feature_id. You can add more columns like create_date, expiry_date and other as per your need. A direct select query on this table with the user_id will give you the list of features allowed to the user.

You can design it in many ways but this is something we have used and worked. Happy Coding.

Upvotes: 1

Related Questions