|
| 1 | +--- |
| 2 | +title: "Explanation of the Notification Database Tables for Subscriptions" |
| 3 | +description: "This document describes the subscription data model in the NRC database. It clarifies the usage of tables like kanalen, abonnementen, and filtervalues." |
| 4 | +keywords: [NRC, database, subscriptions, notifications, data model, kanalen, abonnementen, filtervalues, ZGW, webhook] |
| 5 | +slug: /notifications/notification-subscription-database-model |
| 6 | +--- |
| 7 | + |
| 8 | +# Notification Database: Subscription Data Model |
| 9 | + |
| 10 | +This document outlines the subscription data model within the NRC database. |
| 11 | + |
| 12 | +**Goal:** To clarify the relationship between tables, specifically focusing on the `abonnementkanalen` table. While this table may appear to contain duplicate records, this design is intentional and necessary for the flexible functioning of notification filters. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## 1. Kanalen |
| 19 | + |
| 20 | +**OAS Resource:** [`kanaal`](https://vng-realisatie.github.io/gemma-zaken/standaard/notificaties/redoc-1.0.0#tag/kanaal/operation/kanaal_create) |
| 21 | + |
| 22 | +The `kanalen` table represents the source of notifications (e.g., 'zaken' or 'besluiten' in the ZRC). |
| 23 | + |
| 24 | +| Column | Description | |
| 25 | +| :--- | :--- | |
| 26 | +| **`id`** | **Primary Key.** Unique identifier for the kanaal. | |
| 27 | +| **`naam`** | The name of the channel (e.g., `zaken`, `besluiten`). | |
| 28 | +| **`documentatielink`** | URL pointing to the documentation for this specific channel. | |
| 29 | +| **`filters`** | A list of available attributes that can be used to filter subscriptions for this channel. | |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +## 2. Abonnementen |
| 34 | + |
| 35 | +**OAS Resource:** [`abonnement`](https://vng-realisatie.github.io/gemma-zaken/standaard/notificaties/redoc-1.0.0#tag/abonnement/operation/abonnement_create) |
| 36 | + |
| 37 | +The `abonnementen` table stores the actual subscriptions for ZGW notifications received via POST requests. |
| 38 | + |
| 39 | +| Column | Description | |
| 40 | +| :--- | :--- | |
| 41 | +| **`id`** | **Primary Key.** Unique identifier for the subscription. | |
| 42 | +| **`callbackurl`** | The full webhook URL of the application where the notification must be sent. | |
| 43 | +| **`auth`** | The bearer token required by the webhook receiver for authorization. | |
| 44 | +| **`owner`** | The RSIN of the organization granting access to the application. | |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## 3. Abonnementkanalen |
| 49 | + |
| 50 | +**OAS Element:** `kanalen` array within `abonnement`. |
| 51 | + |
| 52 | +This table establishes an **N:M (Many-to-Many)** relationship between `abonnementen` and `kanalen`. |
| 53 | + |
| 54 | +> **Key Concept:** The Primary Key (`id`) of this table is referenced by the `filtervalues` table. This architecture allows a single subscription to link to the *same* `kanaal` multiple times. While this looks like duplicate data, it allows different sets of `filtervalues` to be applied to the same channel within one subscription. |
| 55 | +
|
| 56 | +| Column | Description | |
| 57 | +| :--- | :--- | |
| 58 | +| **`id`** | **Primary Key.** Referenced by `filtervalues`. | |
| 59 | +| **`abonnement_id`** | **Foreign Key.** Points to the parent subscription in `abonnementen`. | |
| 60 | +| **`kanaal_id`** | **Foreign Key.** Points to the source channel in `kanalen`. | |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 4. Filtervalues |
| 65 | + |
| 66 | +**OAS Element:** `filters` element within `abonnement`. |
| 67 | + |
| 68 | +To prevent message flooding, subscriptions often restrict which notifications they receive. The `filtervalues` table stores these restrictions. |
| 69 | + |
| 70 | +| Column | Description | |
| 71 | +| :--- | :--- | |
| 72 | +| **`id`** | **Primary Key.** | |
| 73 | +| **`abonnement_kanaal_id`** | **Foreign Key.** Links to the `abonnementkanalen` table. | |
| 74 | +| **`key`** | The filter name. Valid values are listed in `kanalen.filters`. <br /> Special values include:<br />• `#resource`: The resource triggering the event.<br />• `#actie`: The event type (e.g., create, destroy). | |
| 75 | +| **`value`** | The specific value to match against. | |
| 76 | + |
| 77 | +### Example Usage |
| 78 | + |
| 79 | +If you want to filter for a specific domain, the definition for the **zaken** channel might look like this: |
| 80 | + |
| 81 | +* **Key:** `domein` |
| 82 | +* **Value:** `VTH` |
| 83 | + |
| 84 | +*Result: The notification is delivered only if the 'zaak' belongs to a 'zaaktype' within the 'VTH' domain.* |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Logic: Combining Filters |
| 89 | + |
| 90 | +The data model supports complex filtering logic by combining multiple `filtervalues` and multiple `abonnementkanalen`. |
| 91 | + |
| 92 | +### The Logic Rule |
| 93 | + |
| 94 | +> 1. **Inside** a single `abonnementkanaal`: Filters are combined with **AND**. |
| 95 | +> 2. **Between** different `abonnementkanalen` (for the same subscription): Logic is combined with **OR**. |
| 96 | +
|
| 97 | +### Scenario: "Create OR Delete" |
| 98 | + |
| 99 | +A client application wants to receive notifications from the `zaken` channel *only* when a `zaakinformatieobject` is **created** OR **deleted**. |
| 100 | + |
| 101 | +**Abonnementkanalen ID: 1** (The "Create" Condition) |
| 102 | + |
| 103 | +* Filter A: `key='#resource'`, `value='zaakinformatieobject'` |
| 104 | +* Filter B: `key='#actie'`, `value='create'` |
| 105 | +* *Logic: Resource is object **AND** action is create.* |
| 106 | + |
| 107 | +**Abonnementkanalen ID: 2** (The "Delete" Condition) |
| 108 | + |
| 109 | +* Filter A: `key='#resource'`, `value='zaakinformatieobject'` |
| 110 | +* Filter B: `key='#actie'`, `value='destroy'` |
| 111 | +* *Logic: Resource is object **AND** action is destroy.* |
| 112 | + |
| 113 | +**Final Result:** |
| 114 | +If (Object created) **OR** (Object destroyed) then **Send Notification**. |
0 commit comments