-
Notifications
You must be signed in to change notification settings - Fork 0
3. Database model
For the design of the data model, a separation was established between the following aspects:
- sensor network
- timeseries
- users and roles
Through the conceptual model based on the E-R (Entity-Relationships) scheme, the subjects to be described (the Entities) and any relationships between them (Relationships) are identified.
This aspect concerns the net management and the mapping of net's channels with timeseries.
Each node of the network is a station (Station) to which one or more acquisition channels (Channel) are associated.
The mapping between the sensor network and a timeseries pass from channels: a time series is linked to zero, one or more channels.
For each station, the name, the geographical coordinates, the network to which it belongs (Net), and the installation site (Site) are stored.
The site is a specific geographical point with a reference name, which is associated with the installation of one or more stations, and is mainly represented by its coordinates, which can be punctual or relative to an area. For each network it is also possible to identify an owner (Owner).
The relationship between station and channels is not direct, but passes through the sensor entity (Sensor) and the related (if any) digitizer (Digitizer). In fact, over time, the station instrumentation can be updated. Each update of the sensor and/or digitizer settings produces a new set of channels.
The list of channels of a station is therefore associated with a very specific configuration (Station_config) identified by the tuple (Sensor, Digitizer, start date, end date), to trace the history of the station instrumentation over time.
There are different types of sensors (Sensortype) from which the installed instances inherit the structure of the main properties (e.g. model, number of components, response parameters). The sensortypes can be grouped into classes, based on certain common characteristics, defining categories (Sensortype_category) from which the typologies inherit the structure of the descriptive information.
Similarly, there are different types of digitizers (Digitizertype) from which the installed instances inherit the structure of the main properties (e.g. model, sampling frequency, sensitivity, etc.). Both the sensor and the digitizer mainly take into account the assigned name, the serial number and the type.
The main resource of the TSDSystem are timeseries (Timeseries). For each timeseries, it is useful to define and save:
- the name,
- the type of values (usually numeric) of which it is composed,
- the sampling rate,
- if in the public domain,
- whether the times are saved with reference to the time zone (Time Zone Definition – TZD), always compatible with the ISO-8601 standard (https://www.w3.org/TR/NOTE-datetime) or not (in this case the times are treated as UTC),
- perhaps other configuration parameters for plotting or state identification (thresholds).

List of schemas -> tables:
-
tsd_pnetownersnetssitesstationsstation_configschannelssensorssensortypessensortype_categoriesdigitizersdigitizertypes
-
tsd_maintimeseriestimeseries_mapping_channels
Note: For tables
owners,nets,stations,sites,sensors,sensortypes,sensortype_categories,digitizers,digitizer_types,station_configs,channels,timeseries, in addition to the fields described in the diagrams, the following have been included:
create_timetimestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text),update_timetimestamp without time zone,remove_timetimestamp without time zone,create_userinteger,update_userinteger,remove_userinteger
This aspect concerns the management of users permissions using the RBAC (Roles Based Access Control) model.
TSDSystem exposes a REST API to perform writing and reading operations.
To obtain control over the required operations it is necessary to define the user authentication system (user authentication) and the resource access policies through authorization systems (user authorization).
Regarding the resource access policies, the RBAC (Role Based Access Control) design pattern was followed. The RBAC mechanism is based on the concepts of role and privilege. The object of privileges, in our case, is each resource that can be interfaced by the REST service. The main subjects are: resources, roles (Roles) and permissions (Permissions):
- The resources are connected to the entities of the conceptual data model and are those accessible by the REST service.
- Users are linked to roles.
- Each role has a set of permissions defined on the resources. The permissions can be mainly distinguished for read and/or write operations. For some resources, such as timeseries, permissions can be limited to a specific time period.

List of schemas -> tables:
-
tsd_users-
members(registered users) rolesmember_mapping_roles-
members_permissions(permissions can be linked directly to users) roles_permissions-
tokens(not included into E-R diagram - service table for logging all JWT tokens generated for the utilization of REST API) -
temp_reset_keys(not included into E-R diagram - service table for user reset password)
-
Note:
create_time,update_timeandremove_timefields have been included also into tablesroles,roles_permissions,members_permissions,member_mapping_roles.
Some predefined roles are registered during installation, such as:
-
Admin userwho has administration privileges on all resources; -
Network readerwho can read all information about sensor network data; -
Timeseries editorwho can read e write timeseries
See codelines 136-146 in https://github.com/ingv-oe-dev/tsdsystem/blob/master/docker/timescale/sql/tsd_users.sql)
There are two types of permissions stored into members_permissions and roles_permissions:
- specific for the manipulation of resources such as:
owners,nets,sites,stations,sensortypes,sensors,digitizers,digitizertypes,channels,timeseries, which in turn are specified separately for reading and for writing. -
administrative for the management of
roles,members, their mapping (member_mapping_roles) and the relative permissions (members_permissionsandroles_permissions), as well as operations on the resources.
The permission model is defined by the JSON schema at: https://github.com/ingv-oe-dev/tsdsystem/blob/master/src/tsdws/json-schemas/resource_permissions.json
Note: In the proposed JSON schema, permissions defined at resource level has the following subsections:
enabled<boolean> - which generally indicates whether enabled or notip<array> - where you can enter specific IP addresses enabled to make the requestpermissions<object> - where you can enable permission on specific resource IDs
Permissions can be stored directly into the payload of the JWT authorization tokens when these last are used to perform automatical action through the REST API.
Special mention must be made of the timeseries resource section.
For this resource, the read->permissions section adds more details to specify a permission on a limited period of the timeseries through the fields:
-
start_period<timestamp>, -
end_period<timestamp>, -
number_of_days<integer>, -
last_days<boolean>
Permissions structure:
"edit": {
"enabled": true,
"ip": [],
"permissions": {
"net_id": [], // o null
"station_id": [], // o null
"channel_id": [], // o null
"id" : [] // o null
}
}
Permission checks will be carried out from the authorization system as follows.
Check if edit->enabled = true
Check if the IP of the client performing the request is into edit->ip list (empty list equals to all ip)
If edit->permissions section does not exist, all writes are available, else:
- Check if there is a restriction on specific timeseries by
idand then that theidof the requested timeseries is intoedit->permissions->idlist - Else check timeseries dependencies in the following order (
channels,stations,netsto which the timeseries can be related):- else check if
edit->permissions->channel_idlist is not empty and that the timeseries is related at least with one listed channel id - else check if
edit->permissions->station_idlist is not empty and that the timeseries is related at least with one listed station id (passing from channels) - else check if
edit->permissions->net_idlist is not empty and that the timeseries is related at least with one listed net id (even passing from channels)
- else check if
Permissions structure:
"read": {
"enabled": true,
"ip": [],
"permissions": [{
"target": <string> // one of ["all", "nets", "stations", "channels", "timeseries"]
"id": [] // list of IDs for the selected target
“priority”: <integer>
"settings": {
"start_period": <datetime>,
"end_period": <datetime>,
"number_of_days": <integer>,
"last_days": <boolean>
}
}]
}
Permission checks will be carried out from the authorization system as follows.
Check if read->enabled = true
Check if the IP of the client performing the request is into read->ip list (empty list equals to all ip)
If read->permissions section does not exist, all reads are available, else:
- Check if there is a restriction on specific timeseries by
idand then that theidof the requested timeseries is intoread->permissions->idlist - Else check timeseries dependencies in the following order (
channels,stations,netsto which the timeseries can be related):- else check if
read->permissions->channel_idlist is not empty and that the timeseries is related at least with one listed channel id - else check if
read->permissions->station_idlist is not empty and that the timeseries is related at least with one listed station id (passing from channels) - else check if
read->permissions->net_idlist is not empty and that the timeseries is related at least with one listed net id (even passing from channels) - finally check if there is a permission defined for all cases (
read->permissions->allsection) - otherwise the default permission is selected (last day of the requested timeseries):
{ "start_period": null, "end_period": null, "number_of_days": 1, "last_days": true } - else check if
List of other schemas -> tables used in the physical design with PostGreSQL:
public- <all schemas created by Timescale extension>