Skip to content

Generic Field Entity with FieldValues

Vijay Khollam edited this page May 4, 2024 · 9 revisions

Problem Statement

The integration of a generic field entity system with FieldValues is essential to facilitate the flexible management of various data types across different entities. There is a need to establish a robust framework that allows for seamless handling of field values associated with diverse entities like users, cohorts, and more.

Approach

To overcome this challenge, we adopt an approach where we generate fields for any entity, utilizing field types and parameters to render the corresponding field types using front-end libraries. Additionally, we leverage the FieldValues table to store values associated with specific fields. Establishing this centralized repository allows for efficient management and access of data from different entities, ensuring consistency and scalability in handling various data types across multiple entities.

Solution

The solution entails implementing a comprehensive database schema comprising tables for FieldValues, Fields, Users, and Cohorts. Each table serves a distinct purpose in managing data related to the corresponding entity. By utilizing this schema, developers can effectively manage and manipulate data across different entities, ensuring seamless integration and efficient data management.

Database Schema

Fields Table

Column Name Data Type Description
field_id uuid Unique identifier for the field.
context uuid Context of the field.
name VARCHAR Name of the field.
label VARCHAR Label for the field.
default_value VARCHAR Default value of the field.
type VARCHAR Type of the field.
description TEXT Description of the field.
state TEXT State of the field.
required BOOLEAN Indicates if the field is required.
ordering INTEGER Ordering of the field.
tenantId uuid Identifier of the tenant.
created_at TIMESTAMP Timestamp for creation.
updated_at TIMESTAMP Timestamp for last update.
created_by uuid Creator of the field.
updated_by uuid Last updater of the field.
contextId uuid Context identifier.
contextType VARCHAR Type of the context.
fieldParams JSONB Additional parameters for the field.

FieldValues Table

Column Name Data Type Description
value VARCHAR Value of the field.
fieldValuesId uuid Unique identifier for each field value.
itemId uuid Identifier of the associated entity (e.g., userId for users, cohortId for cohorts).
fieldId uuid Identifier of the field.
created_at TIMESTAMP Timestamp for creation.
updated_at TIMESTAMP Timestamp for last update.
created_by uuid Creator of the field value.
updated_by uuid Last updater of the field value.

You can find more details about Cohort Management and User Management as below.

  1. Cohort Management
  2. User Management ER Final 2