Notifications/subscriptions data model
This is an overview of the Notifications data model, which should be useful for developers or for migrating content between different systems when you have lots of users with lots of subscriptions.
Subscription data
Subscriptions to different objects/events are kept in two different tables. They hold different types of subscriptions to different objects (node, user....) with any number of related conditions:
notifications, there's a row for each subscription, some fields:
- sid = unique index for each subscriptions
- type = subscription type (thread, nodetype, taxonomy...)
- event_type = the type of event that triggers the notifications, will be 'node' usually
- conditions = number of conditions for this subscription
- module, cron = Advanced usage for custom plug-ins. This ones allow other modules to store their own rows in here that may be processed on cron or not. For Notifications they should be always: ('notifications', 1)
notifications_fields, parameters for each subscription (conditions)
There may be one or more rows for each subscription, each one corresponds to a condition that should match for the notifications to be triggered. I.e, for a subscription to user 1 blog it will be like: node type = 'blog', node author = 1
- field, field name
- value, field value to match
Examples
- Example 1 (sid = 1): Thread (node) subscription, the user (uid =10) will be notified about a specific node (nid = 100) updates, comments, etc..
- Example 2 (sid = 2): Content type subscription, same user will be notified for posts of 'story' type
- Example 3 (sid = 3): Custom subscription, that may be created by other module, the user will be notified for posts of 'event' type, tagged with a taxonomy term (tid = 123). This one will need a pair rows in notifications_fields
notifications table
| sid | uid | type | event_type | conditions |
|---|---|---|---|---|
| 1 | 10 | thread | node | 1 |
| 2 | 10 | nodetype | node | 1 |
| 3 | 10 | custom | node | 2 |
notifications_fields table
| sid | field | value |
|---|---|---|
| 1 | nid | 100 |
| 2 | type | 'story' |
| 3 | type | 'event' |
| 3 | tid | 123 |
This model should support any type of subscription (new types may be created by plug-in modules), with any number of conditions and for a specific event all the subscription checking may be done with a *single query*.
