Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database design for coupon usuage restriction

While working on implementing voucher feature for an eCommerce application, I need to implement Voucher usage restriction, some of restriction I am planning to have

  1. Products
  2. Exclude products
  3. Product categories
  4. Exclude categories
  5. Email /Customer restrictions

Currently We are supporting following 2 type of Vouchers with an option to create Custom voucher type and all those Vouchers types are being maintained in a single table with help of discriminator (Hibernate use).

  1. Serial Vouchers
  2. Promotion Vouchers.

these are only few which I am targeting at initial stage.My main confusion is about database design and restriction of these voucher usage with Voucher.I am not able to decide which is best way to Map these restrictions in database.

Should I go for a single table for all these restriction and have a relation with Voucher table or is it good to group all similar type of restriction in a single table and have their relation with Voucher table.

As an additional information , we are using hibernate to map our entities with the DB table.

like image 430
Umesh Awasthi Avatar asked Sep 06 '14 16:09

Umesh Awasthi


2 Answers

This seems like a very wide-open and freeform requirement. Some questions:

How complex will the business rules you are attempting to model be? If you’re allowing (business) users to define their own vouchers, odds are good they’ll come up with some pretty byzantine rules and combinations. If you have to support anything they come up with, you will have problems.

What will the database be tasked to do with this data? Store the “voucher definition”, sure, but then what? Run tallies or reports on them? Analyze how many are used, by who/when/how/for what? Or just list out what was used/generated over the past year?

What kind of data volumes are you going to have? One entry per voucher definition, or per voucher printed/issued? (If the latter, can you use one entry per voucher, with a count of how many issued?) Are we talking dozens, hundreds, or millions of vouchers?

If it’s totally free-form, if they just want a listing without serious analysis, if the overall volume is small, consider using blob fields rather than minutiae-oriented columns. Something like a big text field and a data-entry box wherein the user will “Enter any other criteria defining the voucher”. (You might even do this using XML.) Ugly, you can’t readily analyze the data, but if the goals are too great or diffuse and you're not going to use all that detailed data, it might be necessary.

A final note: a voucher that is good for only selected products cannot be used on products that are added after the voucher is created. A voucher that is good for all but selected products can be used for subsequently created products. This logic may apply to any voucher-limiting criteria. Both methodologies have merit, make sure the users are clear on what they’re doing.

like image 96
Philip Kelley Avatar answered Oct 15 '22 07:10

Philip Kelley


If I understand what your your are doing, you will have a problem with only one table for all restrictions, because it means 1 row per Voucher and multiple values in your different restrictions columns.

It will be harder for you to UPDATE, extract and cast restrictions values.

In my opinion, you should have one table for each restrictions type and map them with Voucher table. However It will be easier for you to add new restrictions.

like image 36
Guillaume Mercey Avatar answered Oct 15 '22 07:10

Guillaume Mercey