I'm finding it difficult to decide on a schema for a monthly subscription service. In particular, if my the credit cards table should be related to the customer or to the subscription.
The tables I currently have are the following:
users
id
other fields.
addresses
id
userid
other fields
subscriptions
开发者_开发百科id
userid
other fields
cards
id
userid
last4digits
A user can only have one subscription. For now, only credit cards are accepted as a form of payment. However, that could change in the future. My schema is simplistic, but I'm afraid my setup will be a pain to alter in the future if more payment types are added.
Can you provide me with some advice please?
Your database design should consider what types of queries you will want to execute against the data, however, without knowing more, how about introducing a Payments table:
Clients 1..* Cards
Cards 1..* Payments
Payments 1..* Subscriptions
This way in the future you can easily add other payment types, e.g. add:
Clients 1..* PaypalAccounts
PaypalAccounts 1..* Payments
Also, I'm assuming a payment can be taken for more than one subscription.
精彩评论