I’m dealing with user subscriptions.
A user creates a recurring subscription. Many things can happen to that subscription, such as it is renewed, or it’s canceled, or the latest billing was unsuccessful, or the user has paused or restarted with subscription.
Do you suggest:
- Having one
subscriptionsrecord for each user, which has fields for all possible values such as started date, expires date, is active, failed billing date, canceled date, paused date, restarted date? - Or having one
subscriptionsrecord, with a secondary tablesubscription_events? A row in this secondary table could record “subscription X has been renewed”. Then I would query the most recent event for a subscription to figure out its current status. - Or a better approach?
Don’t go for 1. It’s not flexible enough for new events. You don’t want a design where you need to alter the table every time a new event comes along. You would also need columns for each event date and it just starts getting ugly when you want to know the order of things.
Also what happens when a user can have multiple subscriptions?
2 is about right. To normalize it a bit, I would imagine you have a USER table and a SERVICE table with a SUBSCRIPTION mapping the two together. Then there would be an EVENT table with the known possible events and a SUBSCRIPTION_EVENT_MAP mapping SUBSCRIPTION to EVENT with a time stamp.