Database views
Postgres schema
Every organization in Factry Historian will have a corresponding schema in the postgres database with the same name. A postgres user which can only access the schema is also created when creating an organization. This user can only access the views and functions present in this schema, by default its search path is set to this schema. Renaming the organization will also rename this schema.
Views
There are 4 views which are present from the start and are not dependant on the configured event types: v_events, v_assets, v_event_types and v_event_type_properties. Two helper functions, assets_by_parent and is_asset_child_of, are created alongside them.
Events view
This view can be used to get basic information of all the events in the organization.
It contains the following columns:
- event_uuid: The UUID of the event.
- asset_uuid: The UUID of the asset of the event
- event_parent_uuid: The UUID of the parent event, may be null if no parent is configured
- event_type: The name of the event type of the event
- event_type_uuid: The UUID of the event type of the event
- asset_path: The asset path of the asset of the event
- asset_name: The name of the asset of the event
- asset_description: The description of the asset of the event
- start_time: The start time of the event
- stop_time: The stop time of the event
- start_time_epoch: The unix milliseconds of the start time of the event
- stop_time_epoch: The unix milliseconds of the stop time of the event
- status: The status of the event. The stored values are lowercase: open, incomplete, pending or processed.
- source: The source of the event (auto or manual)
- properties: The properties of the event in JSON form
- duration: The duration of the event in seconds
- event_name: The name of the event, NULL for an unnamed event. Available from version 8.3, see Event name column.
Assets view
This view returns all assets in the organization.
It contains the following columns:
- uuid: The UUID of the asset
- name: The name of the asset
- description: The description of the asset
- status: Will be deleted (lowercase) if the asset is deleted
- parent_uuid: The UUID of the parent asset, NULL if the asset has no parent
- asset_path: The full asset path
- created_by: The UUID of the user that created the asset
- created_at: The timestamp when the asset was created
- updated_by: The UUID of the user that last updated the asset
- updated_at: The timestamp when the asset was last updated
- attributes: /
- metadata: The asset metadata in JSON form, as used by event configurations and calculations
- organization_uuid: The UUID of the organization the asset is part of
Generated views
All event types will have up to 3 views generated depending on the configured properties.
All these views will have the following columns:
- event_uuid: The UUID of the event
- event_parent_uuid: The parent UUID of the event
- asset_uuid: The UUID of the asset of the event
- asset_path: The full asset path of the asset of the event
- asset_name: The name of the asset of the event
- asset_description: The description of the asset of the event
- start_time: The start time of the event
- stop_time: The stop time of the event
- start_time_epoch: The unix milliseconds of the start time of the event
- stop_time_epoch: The unix milliseconds of the stop time of the event
- status: The status of the event. The stored values are lowercase: open, incomplete, pending or processed.
- source: The source of the event (auto or manual)
- duration: The duration of the event in seconds
- event_name: The name of the event, NULL for an unnamed event. Available from version 8.3, see Event name column.
All event types will have the following corresponding view.
v_{event_type_name}_event_properties:
This view has an extra column for every configured simple event type property.
v_{event_type_name}_event_samples:
This view has the following extra columns:
- time_offset: The offset in seconds from the start time of the sample time of the periodic value
- sample_time: The sample time of the periodic value
- sample_time_epoch: The unix milliseconds of the sample time
- name: The name of the corresponding periodic property
- value: The value of the corresponding periodic property at the sample time
This view only covers periodic properties with datatype number or boolean, and boolean values appear as 1 and 0 rather than true and false. Periodic properties of datatype string do not appear here; use v_{event_type_name}_event_samples_joined, which has no datatype restriction.
v_{event_type_name}_event_samples_joined:
This view has the following extra columns:
- time_offset: The offset in seconds from the start time of the sample time of the periodic value
- sample_time: The sample time of the periodic value
- sample_time_epoch: The unix milliseconds of the sample time
- A column for every periodic property configured with the corresponding value at the sample time (if any)
Event name column
Available from version 8.3 and later.
v_events and the generated _event_properties, _event_samples and _event_samples_joined views have an event_name column with the name of the event, or NULL for an unnamed event. The column is there whether or not named events are on. In the _event_samples views, the name column still holds the property name.
The upgrade to version 8.3 adds event_name as the last column of each view. A query with SELECT * returns one more column.
The upgrade to version 8.3 drops and recreates v_events, v_assets and the generated event views. Views you built on top of them are dropped with them. Recreate them after the upgrade.
Reserved property names
Available from version 8.3 and later.
A property becomes a column in the generated views, so it cannot use the name of a column those views already have. The API rejects creating a property with one of these names, or renaming a property to one, with a 400:
event_name, duration, event_uuid, event_parent_uuid, asset_uuid, asset_path, asset_name, asset_description, start_time, stop_time, start_time_epoch, stop_time_epoch, status, source, time_offset, sample_time and sample_time_epoch.
The names are matched exactly, in lowercase. A property that already has one of these names stays editable as long as it keeps its name.
The upgrade to version 8.3 does not start while an event type has a property named event_name. It stops before its first migration, names the event types concerned, and leaves the database as it was. Rename the property and run the upgrade again.
Event property values table
From version 8.3, Historian stores event property values in a new table, with one row per event and property. event_properties in the public schema is now a read-only view on that table. It still returns one row per event, with the properties of the event in JSON form, and leaves out values of deleted properties. SQL that inserts, updates or deletes rows in event_properties fails. Write property values through the REST API or a manual entry form instead.
The upgrade keeps the old table as event_properties_legacy. Values stored under a name that no longer matches a property, left by an earlier rename, are not moved to the new table. They stay only in event_properties_legacy, and the upgrade log warns how many there are. Values of a deleted property are moved, and stay hidden like the property. Moving the values can take a while on large databases.