Creating a database model that supports dynamic entity creation requires a flexible and scalable design. The goal is to design tables that can accommodate the creation of new entities on the fly, without the need for structural database changes.
- BaseEntity: Represents generic entity types in our system.
- Attribute can contain validations like Minlength, max length, validations etc
- -metadata for attributes added to attributes table
- The EntityRelationship table essentially serves as a cross-reference (XRef) table, especially in a many-to-many relationship scenario.
- EntityInstance records are joined through EntityRelationship to find all related child entities for a given parent entity.
- Attributes differ significantly across entity types and instances, requiring a system that can accommodate a wide range of data structure
- As the number of entities and attributes grows, the system must scale efficiently without compromising performance.
- Ensuring accuracy and consistency of data across various entities with diverse attributes.
- DB model allows our microservices to define and modify attributes without restructuring the database schema.
- Attribute Metadata Management: Utilize EntityMetadata to store additional information about attributes, such as data validation rules, which helps in maintaining data quality and integrity.
- APIs will be designed to dynamically generate responses based on the attributes of the requested entities, ensuring flexibility and relevance in data delivery.
- When a new attribute is introduced, it will be registered in the EntityAttribute table, making it immediately available for association with entity instances.
- Values for these attributes are stored in the EntityAttributeValue table, allowing for efficient retrieval and manipulation as per business logic requirements.
- The frontend dynamically adjusts to display and interact with these attributes, providing a seamless user experience regardless of the underlying data
- Generic page that can adapt to display any entity type. This is already in place
- Dynamic form to render different types of inputs/display fields based on the data type of each attribute ( text fields, data pickers, dropdowns etc)
- metadata can be used to add additional information or influence the rendering of the entity (e.g., adding tooltips, conditional formatting).
- UI to call endpoints passing relevant entity and instance ID’s
- API endpoints to fetch data for a specific entity including its attributes and metadata
- To fetch a specific Study instance, Query Should join baseentity, EntityInstance, EntityAttribute and EntityAttributeValue tables
- If these tables have large number of rows, Performance will be extremely slow. To mitigate that we can consider indexes on frequently queried columns like entityid
- Enforce data type consistency. For instance, if an attribute 'StartDate' is designed to store dates, the schema restricts this field to date data types only.
- Data Validation :before inserting or updating data, the application layer checks if a 'StartDate' is indeed a valid date and not just a random string or number.
- When a new 'Study' entity is created, and multiple attributes are added, this process is wrapped in a transaction. If adding any attribute fails, the entire operation is rolled back to avoid partial updates.
- Leveraging indexing on the EntityAttributeValue table for faster query execution.
- Dynamic model queries can be complex and might impact performance. We should consider query optimization techniques, caching, or even indexed views if the performance becomes a concern.



