The vrsn schema includes several admin prefixed functions and views designed to simplify common management tasks for bitemporal entities and attributes. These functions act as convenient wrappers for more complex underlying vrsn operations.
This function is designed to initialize or reset the bitemporal framework's core tables, often used for testing or setting up a fresh environment.
- Purpose: This function is primarily used for setup and testing. It truncates (empties) various bitemporal core tables and then re-inserts initial configuration data, effectively resetting the bitemporal state to a clean baseline.
- Parameters:
only_get_query: (boolean) IfTRUE, the function returns the SQL script as a text string without executing it. IfFALSE, it executes the SQL script directly.
- Usage: Be cautious when using this function, as it will delete all data from the specified bitemporal tables. It's intended for development, testing, or initial deployment scenarios where a complete reset is desired.
This function is a wrapper for vrsn.bitemporal_entity__register, used to set up a new table or view for bitemporal management.
- Purpose: Simplifies the process of configuring a table or view as a bitemporal entity, including generating necessary history tables and views, and defining its initial bitemporal behavior.
- Parameters:
table_schema: The schema of the table/view to register.table_name: The name of the table/view to register.historice_entity: (vrsn.historice_entity_behaviour) Default historicization behavior for the new entity.enable_history_attributes: (boolean) IfTRUE, enables attribute historicization for this entity.main_fields_list: (text) Comma-separated list of main fields.cached_fields_list: (text) Comma-separated list ofvrsn.cached_attributefields.print_only: (boolean) IfTRUE, the function returns the DDL statements as text without executing them.
This function allows you to modify the bitemporal behavior settings of an already registered entity. It's a wrapper around vrsn.bitemporal_entity__change.
- Purpose: Provides a user-friendly interface to update settings like how an entity is historicized (
historice_entity), whether attribute history is enabled, which fields are considered "main" for versioning, and other conflict resolution flags. - Parameters:
p_entity_schema: The schema of the entity view.p_entity_name: The name of the entity view.p_modify_user_id: The ID of the user performing the change (for audit purposes).p_historice_entity: (vrsn.historice_entity_behaviour) Defines the historicization strategy ('always','never','on_main_fields').p_enable_history_attributes: (boolean) Enables or disables attribute-level historicization.p_main_fields_list: (text) Comma-separated list of fields that, if changed, always trigger a new version whenhistorice_entityis'on_main_fields'.p_cached_fields_list: (text) Comma-separated list ofvrsn.cached_attributefields to be managed as attributes.p_mitigate_conflicts: (boolean) IfTRUE, attempts to auto-resolve timestamp conflicts.p_ignore_unchanged_values: (boolean) IfTRUE, an update won't create a new history record if no significant values changed.p_enable_attribute_to_fields_replacement: (boolean) IfTRUE, enables overwriting scalar fields fromcached_attributecontent.
- Caution: This function works alse if there are data alreday inserted but doesn't armonize these inforamtion with new parameters.
This function inserts a new global attribute into the vrsn.attribute_lineage table. Global attributes are those not tied to a specific schema or entity, making them universally usable.
- Purpose: To register an attribute as a "global" concept within the bitemporal framework. This attribute can then be mapped to various entities and fields across different schemas.
- Parameters:
p_attribute_name: (text) The unique name of the global attribute.p_modify_user_id: (text) The user ID performing the operation.p_json_schema_plus: (jsonb, optional) An optional JSON schema to describe the attribute's expected structure or data type.
- Returns:
bigint- Theattribute_idof the newly created global attribute. - Caution: Normally new global attributes are inserted automatically.
This function inserts a new local attribute into the vrsn.attribute_lineage table, associating it with a specific entity (view).
- Purpose: To register an attribute that is specific or particularly relevant to a given entity (view). This allows for attributes that might have the same name but different meanings or contexts across various entities.
- Parameters:
p_attribute_name: (text) The name of the local attribute.p_schema_name: (text) The schema of the entity (view) this attribute is associated with.p_entity_name: (text) The name of the entity (view) this attribute is associated with.p_modify_user_id: (text) The user ID performing the operation.p_json_schema_plus: (jsonb, optional) An optional JSON schema for the attribute.
- Returns:
bigint- Theattribute_idof the newly created local attribute. - Caution: use this function if you really want to create local attributes to an entity.
This function reserves an existing attribute ID for use with a specific entity. This is particularly useful if you have a pre-existing attribute_id from a global attribute and want to explicitly link it to a new entity, preventing other entities from "claiming" it.
- Purpose: To explicitly assign an
attribute_idfromvrsn.attribute_lineageto a specific entity (schema_name.entity_name), ensuring that this attribute is primarily managed by or associated with that entity. This prevents unexpected behavior where the sameattribute_idmight be inadvertently mapped differently. - Parameters:
p_attribute_id: (bigint) The ID of the attribute to reserve.p_schema_name: (text) The schema of the entity view.p_entity_name: (text) The name of the entity view.p_modify_user_id: (text) The user ID performing the operation.
- Returns:
bigint- Theattribute_idif the reservation is successful. Raises an exception if the attribute ID doesn't exist, the entity is invalid, or the attribute is already used by a different entity.
This is a view that provides a comprehensive overview of all attributes defined in vrsn.attribute_lineage and their mappings to entities via vrsn.attribute_mapping_to_entity.
- Purpose: To provide a consolidated view of all attributes, indicating whether they are "global" (not tied to a specific entity) or "local" (tied to a specific schema.entity). It also shows the
json_schema_plusfor each attribute and, crucially, ajsonbrepresentation (attribute_mapping_json) detailing which fields within which entities each attribute is mapped to. This view is invaluable for understanding the overall attribute landscape and debugging mapping issues. - Key Columns:
attribute_id: Unique identifier for the attribute.attribute_name: The logical name of the attribute.attribute_scope: Indicates'global'or theschema.entityif local.json_schema_plus: The optional JSON schema for the attribute.attribute_mapping_json: A JSONB object showing how this attribute is mapped to specific fields across different schemas/entities.
main - [readme](../README.md