Matilda
Matilda

Reputation: 1718

Database + data model design pattern

I'm designing a notification system for our company, where users can specify if they want to send notifications for different actions or not.

I'm wondering what is the name for this Design Patter, so I can read on it and follow the do and dont's.

Story(requirements): When user takes different actions on our site (app), the actions get posted to their facebook and twitter accounts and and we emailed him also. There are a lot of actions, 6 under Facebook, 6 under Twitter and 12 under email. So it doesn't make sense to make a separate column for each action, specially that their value is by default true.

So for example when user uploads a new image to their page on our website we want to post to their facebook and twitter, that they just upload an image to our app.

My desing for this is a meta_data table with these columns (with examples rows):

id, user_id, namespace,  notification,   value 
0,  1,       'facebook', 'image_upload', false
1,  1,       'twitter',  'video_post',   false
2,  10,      'email',    'send_money',   false

also for all the actions and their namespaces I add some rows by default to the database when creating the table, where I set all the values to true. Then in users setting page he can see check-boxes for these settings that are all checked by default. Every time the user creates uncheck one, then I create a new row for that user, action and namespace with the value to be false.

Upvotes: 1

Views: 476

Answers (2)

user1494736
user1494736

Reputation: 2400

I'd be more like a Publish-subscribe pattern, but I'd doubt that'll help you.

Regarding the data model: I'd use 3 tables. Since EventDefinition and ActionDefinition should be extremelly small you should always have them in memory.

EventDefinition id name 0 'did something in your app' 1 'other something' ...

ActionDefinition id name 0 'upload_image_tofacebook' 1 'send_email' 2 ...

You'll have to have some kind of "context" where the event sets some data or variables, and the actions performed in response can read from.

Subscription user_id event_id action_id 0 2 3 // When event id 2 happens related to user_id 0 perform action 3

Upvotes: 0

user1168577
user1168577

Reputation: 1973

This is called Observer pattern.

Upvotes: 1

Related Questions