Skip to main content

Introduction to the Files Table

The files table is designed to store metadata and references for file uploads associated with processes and companies. This table plays a crucial role in managing and organizing file attachments within the Serial application’s ecosystem.

Table Structure

The files table is structured to efficiently store file-related information while maintaining relationships with other key entities in the system. Here’s a detailed breakdown of its columns:
Column NameData TypeConstraintsDescription
iduuidprimary keyUnique identifier for each file entry
company_iduuidforeign keyReference to the associated company
created_attimestamp with time zonenot nullTimestamp of when the file entry was created
dataset_iduuidforeign keyReference to the associated dataset
file_idstringnullableIdentifier for the file in the storage system
file_namestringnot nullName of the uploaded file
formatstringnot nullFormat or extension of the file
process_entry_iduuidforeign keyReference to the associated process entry
unique_identifier_iduuidforeign keyReference to the associated unique identifier
bucket_namestringnot nullName of the storage bucket (default: ‘data-files’)

Usage and Functionality

The files table is designed to be a central repository for file metadata within the Serial application. Here are some key points about its usage:
  1. File Association: Each file entry is associated with a specific company, allowing for organized file management across different organizational entities.
  2. Process Integration: Files can be linked to specific process entries, enabling the attachment of relevant documents or data to particular steps in a workflow.
  3. Unique Identifier Linking: The table allows files to be connected to unique identifiers, which could represent specific products, batches, or other trackable entities in the system.
  4. Dataset Correlation: Files can be associated with datasets, potentially allowing for grouping of related files or connecting files to specific data collection efforts.
  5. Storage Management: The combination of file_id and bucket_name columns facilitates the management of file storage, potentially across different storage systems or locations.

Notes

  • The structure of the table has evolved over time, with columns being added or renamed to meet changing requirements. For example, the data_key_id column was renamed to dataset_id, indicating a shift in how data is organized or referenced.
  • The file_id being nullable suggests that the system might allow for placeholder entries or metadata-only records in some cases.
  • Example usage in TypeScript might look like this:
    const fileEntry = {
      id: generateUUID(),
      company_id: currentCompanyId,
      dataset_id: associatedDatasetId,
      file_name: uploadedFile.name,
      format: getFileFormat(uploadedFile),
      process_entry_id: currentProcessEntryId,
      unique_identifier_id: productUniqueId,
      bucket_name: "data-files",
    };
    
    await supabase.from("files").insert(fileEntry);
    
By leveraging the files table, the Serial application can efficiently manage and organize file attachments across various business processes, ensuring that documents and data files are properly associated with relevant entities and easily retrievable when needed.