Introduction to the Report_Templates Table
The report_templates table is designed to store and manage various types of report templates within the Serial application. This table plays a crucial role in organizing, versioning, and controlling access to different reporting configurations across the system.Table Structure
The report_templates table is structured to accommodate diverse report types while maintaining version control and access management. Here’s a detailed breakdown of its columns:| Column Name | Data Type | Constraints | Description |
|---|---|---|---|
| id | uuid | not null, default uuid_generate_v4() | Unique identifier for each template |
| revision | bigint | not null | Version number of the template |
| company_id | uuid | not null | Associated company identifier |
| type | text | not null | Type of report template |
| name | text | not null | Name of the template |
| description | text | Optional description of the template | |
| created_at | timestamp with time zone | not null, default now() | Timestamp of template creation |
| created_by | uuid | not null | User identifier of the creator |
| last_edited_at | timestamp with time zone | default now() | Timestamp of last edit |
| last_edited_by | uuid | User identifier of the last editor | |
| is_public | boolean | not null, default false | Flag indicating if the template is publicly accessible |
| shared_with | jsonb | not null, default ''::jsonb | JSON object storing sharing permissions |
| config | jsonb | not null, default ''::jsonb | JSON object storing template configuration |
| is_latest_revision | boolean | not null, default false | Flag indicating if this is the latest revision |
Usage and Functionality
The report_templates table is designed to be flexible and secure, accommodating various reporting needs within the Serial application. Here are some key points about its usage:-
Version Control: The table implements a revision system, allowing multiple versions of a template to be stored. The
revisioncolumn, along with theis_latest_revisionflag, helps manage different iterations of a template. -
Access Control: Through the
is_publicflag and theshared_withJSON column, the table provides granular control over who can access and use each template. This is further reinforced by row-level security policies. -
Template Diversity: The
typecolumn allows for different kinds of report templates, such as GridBuilderView, GraphBuilderView, SnLookupPdfTemplate, and Dashboard. TheconfigJSON column stores the specific configuration for each template type.
Notes
-
The table uses triggers to automatically increment the revision number and update the
last_edited_attimestamp when changes are made. -
Row-level security is implemented with policies that restrict access based on user roles and company associations. For example:
-
The table has foreign key constraints linking to the
companiesanduserstables, ensuring data integrity across the database.

