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

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

## Introduction to the Unique\_Identifiers Table

The unique\_identifiers table is designed to store and manage information about individual items or components within the Serial system. This table plays a crucial role in tracking the lifecycle, status, and relationships of uniquely identifiable objects across various processes and operations.

## Table Structure

The unique\_identifiers table is structured to capture comprehensive details about each unique identifier. Here's a detailed breakdown of its columns:

| Column Name                | Data Type                | Constraints             | Description                                               |
| -------------------------- | ------------------------ | ----------------------- | --------------------------------------------------------- |
| id                         | uuid                     | primary key             | Unique identifier for the record                          |
| identifier                 | text                     | not null                | The actual unique identifier string                       |
| company\_id                | uuid                     | not null, foreign key   | Reference to the company owning this identifier           |
| component\_id              | uuid                     | not null, foreign key   | Reference to the associated component                     |
| created\_at                | timestamp with time zone | not null, default now() | Timestamp of record creation                              |
| status                     | text                     | foreign key             | Current status of the identifier                          |
| metadata                   | jsonb                    |                         | Flexible field for additional data                        |
| last\_updated\_at          | timestamp with time zone | default now()           | Timestamp of the last update                              |
| completed\_at              | timestamp with time zone |                         | Timestamp when the identifier was marked as completed     |
| work\_order\_id            | uuid                     | foreign key             | Reference to the associated work order                    |
| part\_number\_id           | uuid                     | foreign key             | Reference to the associated part number                   |
| latitude                   | double precision         |                         | Geographical latitude of the identifier                   |
| longitude                  | double precision         |                         | Geographical longitude of the identifier                  |
| latest\_process\_entry\_id | uuid                     | foreign key             | Reference to the latest process entry for this identifier |

## Usage and Functionality

The unique\_identifiers table is designed to be the central repository for tracking individual items throughout their lifecycle. Here are some key points about its usage:

1. **Lifecycle Tracking**: The table captures the creation, updates, and completion of identifiers, allowing for comprehensive lifecycle management.

2. **Status Management**: The status field, linked to the unique\_identifier\_status\_types table, enables efficient tracking of an identifier's current state (e.g., WIP, COMPLETE, DEFECTIVE).

3. **Relational Connections**: Through various foreign keys, the table establishes relationships with companies, components, work orders, part numbers, and process entries, creating a web of interconnected data.

4. **Geolocation Support**: The latitude and longitude fields allow for geographical tracking of identifiers, which can be crucial for logistics and inventory management.

5. **Flexible Metadata**: The jsonb metadata field provides a way to store additional, schema-less information about the identifier, accommodating diverse use cases.

## Notes

* The table is central to many operations in the Serial system, including the `sn_lookup_page` function, which retrieves detailed information about an identifier and its genealogy.

* The `latest_process_entry_id` field allows for quick access to the most recent process information without the need for complex joins or subqueries.

* Example usage in TypeScript:

  ```typescript
  interface UniqueIdentifier {
    id: string;
    status: UniqueIdentifierStatus | null;
    company_id: string;
    created_at: TimestamptzString;
    identifier: string;
    completed_at: TimestamptzString | null;
    component_id: string;
    // ... other fields
  }
  ```

By leveraging the unique\_identifiers table, the Serial application can efficiently track, manage, and analyze individual items throughout their lifecycle, providing a robust foundation for inventory management, process tracking, and supply chain operations.
