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

# Log File Schema Dataset Links

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

## Introduction to the Log\_File\_Schema\_Dataset\_Links Table

The log\_file\_schema\_dataset\_links table is designed to establish and manage relationships between log file schemas and datasets. This table plays a crucial role in the system by facilitating the mapping of structured data schemas to various datasets, enabling flexible and versioned data integration.

## Table Structure

The log\_file\_schema\_dataset\_links table is structured to maintain the connections between schemas and datasets while providing additional metadata. 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 (companies)          | Reference to the company owning the link       |
| schema\_id       | uuid        | foreign key (log\_file\_schemas) | Reference to the associated schema             |
| dataset\_id      | uuid        | foreign key (datasets)           | Reference to the associated dataset            |
| path\_key        | jsonb       | not null                         | JSON representation of the data mapping path   |
| created\_at      | timestamptz | not null, default now()          | Timestamp of link creation                     |
| is\_active       | boolean     | not null, default true           | Indicates whether the link is currently active |
| schema\_revision | integer     | not null, default 1              | Revision number of the associated schema       |

## Usage and Functionality

The log\_file\_schema\_dataset\_links table is designed to be flexible and support versioned schema-to-dataset mappings. Here are some key points about its usage:

1. **Schema-Dataset Association**: The table allows for many-to-many relationships between schemas and datasets, enabling reuse of schemas across multiple datasets and vice versa.

2. **Versioning Support**: The `schema_revision` column facilitates schema versioning, allowing the system to maintain multiple versions of schema-dataset mappings over time.

3. **Active Link Management**: The `is_active` column provides a mechanism to enable or disable specific schema-dataset links without deleting them, offering flexibility in managing data integrations.

4. **Data Mapping**: The `path_key` column stores a JSON representation of the mapping between schema elements and dataset fields, allowing for complex and nested data structures.

## Notes

* Example usage in TypeScript:

  ```typescript
  export const generateBlankSchemaDatasetLink = (
    schemaDatasetLink: Partial<LogFileSchemaDatasetLink>
  ): LogFileSchemaDatasetLink => {
    const newSchemaDataset: LogFileSchemaDatasetLink = {
      id: uuidv4(),
      company_id: "",
      schema_id: "",
      schema_revision: 0,
      dataset_id: "",
      path_key: [],
      is_active: true,
      created_at: new Date().toISOString(),
      ...schemaDatasetLink,
    };
    return newSchemaDataset;
  };
  ```

* The table works in conjunction with the `log_file_schemas` table, which stores the actual schema definitions, including sample file data and metadata.

By leveraging the log\_file\_schema\_dataset\_links table, the Serial application can maintain a flexible and versioned mapping between data schemas and datasets, enabling robust data integration capabilities and supporting complex data processing workflows across different components of the system.
