> ## Documentation Index
> Fetch the complete documentation index at: https://docs.serial.okos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Unique Identifier Links

> An in-depth look at the structure and purpose of the `unique_identifier_links` table in the Serial database

## Introduction to the Unique\_Identifier\_Links Table

The unique\_identifier\_links table is designed to establish and manage relationships between unique identifiers in a hierarchical structure. This table plays a crucial role in tracking the assembly and disassembly of components, associating process entries with unique identifiers, and maintaining a historical record of these relationships.

## Table Structure

The unique\_identifier\_links table is structured to capture the complex relationships between unique identifiers and their associated data. Here's a detailed breakdown of its columns:

| Column Name            | Data Type                | Constraints             | Description                                              |
| ---------------------- | ------------------------ | ----------------------- | -------------------------------------------------------- |
| id                     | uuid                     | primary key             | Unique identifier for each link                          |
| company\_id            | uuid                     | foreign key             | References the company associated with the link          |
| unique\_identifier\_id | uuid                     | foreign key             | References the parent unique identifier                  |
| has\_child\_of\_id     | uuid                     | foreign key             | References the child unique identifier                   |
| process\_entry\_id     | uuid                     | foreign key             | References the associated process entry                  |
| is\_active             | boolean                  | default true            | Indicates whether the link is currently active           |
| dataset\_id            | uuid                     |                         | Associates the link with a specific dataset              |
| created\_at            | timestamp with time zone | not null, default now() | Timestamp of when the link was created                   |
| removed\_at            | timestamp with time zone | nullable                | Timestamp of when the link was removed (if applicable)   |
| removed\_by\_user\_id  | uuid                     | foreign key, nullable   | References the user who removed the link (if applicable) |
| removal\_reason        | text                     | nullable                | Reason for removal of the link (if applicable)           |

## Usage and Functionality

The unique\_identifier\_links table is designed to be flexible and informative, capturing the dynamic relationships between components. Here are some key points about its usage:

1. **Hierarchical Component Structure**: The table allows for the creation of a hierarchical structure of components through the `unique_identifier_id` and `has_child_of_id` columns. This enables the system to track complex assemblies and sub-assemblies.

2. **Active Status Tracking**: The `is_active` column allows for soft deletion of links. When a link is no longer valid, it can be marked as inactive rather than being permanently deleted, preserving the historical record.

3. **Removal Information**: When a link is deactivated, the `removed_at`, `removed_by_user_id`, and `removal_reason` columns capture important metadata about the removal process, enhancing traceability.

4. **Process Association**: Each link is associated with a specific process entry through the `process_entry_id`, allowing for detailed tracking of assembly or disassembly operations.

## Notes

* The table is used extensively in genealogy queries, such as in the `sn_lookup_page` function, to trace relationships between unique identifiers and construct component hierarchies.

* Example usage in TypeScript:

  ```typescript
  interface UniqueIdentifierLink {
    id: string;
    company_id: string;
    unique_identifier_id: string;
    has_child_of_id: string;
    process_entry_id: string;
    is_active: boolean;
    dataset_id: string;
    created_at: string;
    removed_at: string | null;
    removed_by_user_id: string | null;
    removal_reason: string | null;
  }
  ```

By leveraging the unique\_identifier\_links table, the Serial application can maintain a comprehensive and traceable record of component relationships, supporting complex genealogy queries and providing insights into the assembly and disassembly processes throughout a product's lifecycle.
