> ## 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.

# Component Process Links

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

## Introduction to the Component\_Process\_Links Table

The component\_process\_links table is designed to establish and maintain relationships between components and processes in the Serial database. This table plays a crucial role in organizing the workflow and structure of component processing within the system.

## Table Structure

The component\_process\_links table is structured to efficiently link components to their associated processes while maintaining order and versioning information. Here's a detailed breakdown of its columns:

| Column Name       | Data Type | Constraints                               | Description                                      |
| ----------------- | --------- | ----------------------------------------- | ------------------------------------------------ |
| id                | uuid      | primary key, default uuid\_generate\_v4() | Unique identifier for each link                  |
| company\_id       | uuid      | not null, foreign key                     | Reference to the company owning this link        |
| component\_id     | uuid      | not null, foreign key                     | Reference to the component being linked          |
| process\_id       | uuid      | not null, foreign key                     | Reference to the process being linked            |
| order             | bigint    | not null                                  | Specifies the order of processes for a component |
| is\_active        | boolean   | not null, default true                    | Indicates whether the link is currently active   |
| process\_revision | bigint    | not null, default 1                       | Tracks the revision of the process in this link  |

## Usage and Functionality

The component\_process\_links table is designed to be a flexible and powerful tool for managing the relationships between components and processes. Here are some key points about its usage:

1. **Active Link Management**: The table allows for soft deletion of links through the `is_active` column, enabling historical tracking while maintaining current relationships.

2. **Process Ordering**: The `order` column facilitates the sequencing of processes for a given component, allowing for structured workflows.

3. **Revision Tracking**: By including the `process_revision` column, the table supports versioning of processes, ensuring that components are linked to the correct version of a process.

4. **Company-Specific Relationships**: The inclusion of `company_id` ensures that links are properly segregated by company, supporting multi-tenant functionality.

## Notes

* The table is often queried to retrieve only active links of active components, excluding links to processes of type "Instantiation". This can be seen in the following example:

  ```typescript
  const { data, error } = await supabase
    .from("component_process_links")
    .select("*, component:component_id!inner(*), process:processes!inner(*)")
    .eq("component.is_active", true)
    .neq("process.type", ProcessType.Instantiation)
    .eq("is_active", true)
    .returns<ComponentProcessLink[]>();
  ```

* The table is involved in transactional deletions of components, ensuring that all related links are properly removed when a component is deleted.

* It plays a role in retrieving component genealogies, helping to establish the hierarchical relationships between components based on their associated processes.

* The table is updated automatically when process revisions change, ensuring that links always reference the most up-to-date process information.

By leveraging the component\_process\_links table, the Serial application maintains a flexible and versioned structure for associating components with their relevant processes, enabling complex workflows and maintaining data integrity across the system.
