# file_upload

## Description

Tracks file uploads including S3 location, status, and metadata

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE TABLE `file_upload` (
  `file_upload_id` mediumint unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key.',
  `file_upload_config_id` mediumint unsigned NOT NULL COMMENT 'Foreign key to file_upload_config table.',
  `file_key` varchar(36) NOT NULL COMMENT 'Unique identifier for the file upload (UUID).',
  `original_file_name` varchar(255) NOT NULL COMMENT 'Original filename from upload.',
  `file_size_bytes` bigint unsigned NOT NULL COMMENT 'File size in bytes.',
  `file_type` varchar(10) DEFAULT NULL COMMENT 'File extension without leading dot and lowercase (e.g., csv, pdf, xlsx).',
  `mime_type` varchar(255) DEFAULT NULL COMMENT 'MIME type of the file (e.g., text/csv, application/pdf).',
  `s3_bucket` varchar(63) NOT NULL COMMENT 'S3 bucket name where the file is stored (e.g., prod-abacus-flowthrough).',
  `s3_key` varchar(1024) NOT NULL COMMENT 'S3 object key/path for the uploaded file (e.g., uploads/2025/11/00000000-0000-0000-0000-000000000000.csv).',
  `md5sum` varchar(32) DEFAULT NULL COMMENT 'MD5 sum of file contents for integrity verification and duplicate detection.',
  `upload_status` enum('init','complete','error','cancelled') NOT NULL DEFAULT 'init' COMMENT 'Current status of the upload. init: initiated, complete: successfully uploaded, error: failed, cancelled: cancelled by user.',
  `multipart_upload_id` varchar(255) DEFAULT NULL COMMENT 'S3 multipart upload ID for large file uploads.',
  `total_parts` smallint NOT NULL DEFAULT '1' COMMENT 'Total number of parts for multipart uploads.',
  `upload_metadata` json DEFAULT NULL COMMENT 'Additional metadata about the upload (flexible JSON structure).',
  `error_message` text COMMENT 'Error message if upload failed.',
  `completed_at` datetime DEFAULT NULL COMMENT 'Timestamp when the upload completed successfully.',
  `expires_at` datetime DEFAULT NULL COMMENT 'Expiration timestamp for the upload/presigned URL.',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_by` varchar(180) NOT NULL,
  `last_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_modified_by` varchar(180) NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `deleted_by` varchar(180) DEFAULT NULL,
  PRIMARY KEY (`file_upload_id`),
  UNIQUE KEY `uidx_file_key` (`file_key`) COMMENT 'Ensures file_key is unique across all uploads.',
  KEY `fk_file_upload_config` (`file_upload_config_id`),
  KEY `idx_md5sum` (`md5sum`) COMMENT 'For duplicate file detection.',
  CONSTRAINT `fk_file_upload_config` FOREIGN KEY (`file_upload_config_id`) REFERENCES `file_upload_config` (`file_upload_config_id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='Tracks file uploads including S3 location, status, and metadata'
```

</details>

## Columns

| Name                  | Type                                        | Default           | Nullable | Extra Definition                              | Children                                                      | Parents                                     | Comment                                                                                                                      |
| --------------------- | ------------------------------------------- | ----------------- | -------- | --------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| completed_at          | datetime                                    |                   | true     |                                               |                                                               |                                             | Timestamp when the upload completed successfully.                                                                            |
| created_at            | datetime                                    | CURRENT_TIMESTAMP | false    | DEFAULT_GENERATED                             |                                                               |                                             |                                                                                                                              |
| created_by            | varchar(180)                                |                   | false    |                                               |                                                               |                                             |                                                                                                                              |
| deleted_at            | datetime                                    |                   | true     |                                               |                                                               |                                             |                                                                                                                              |
| deleted_by            | varchar(180)                                |                   | true     |                                               |                                                               |                                             |                                                                                                                              |
| error_message         | text                                        |                   | true     |                                               |                                                               |                                             | Error message if upload failed.                                                                                              |
| expires_at            | datetime                                    |                   | true     |                                               |                                                               |                                             | Expiration timestamp for the upload/presigned URL.                                                                           |
| file_key              | varchar(36)                                 |                   | false    |                                               |                                                               |                                             | Unique identifier for the file upload (UUID).                                                                                |
| file_size_bytes       | bigint unsigned                             |                   | false    |                                               |                                                               |                                             | File size in bytes.                                                                                                          |
| file_type             | varchar(10)                                 |                   | true     |                                               |                                                               |                                             | File extension without leading dot and lowercase (e.g., csv, pdf, xlsx).                                                     |
| file_upload_config_id | mediumint unsigned                          |                   | false    |                                               |                                                               | [file_upload_config](file_upload_config.md) | Foreign key to file_upload_config table.                                                                                     |
| file_upload_id        | mediumint unsigned                          |                   | false    | auto_increment                                | [worksheet_flowthrough_batch](worksheet_flowthrough_batch.md) |                                             | Primary key.                                                                                                                 |
| last_modified         | datetime                                    | CURRENT_TIMESTAMP | false    | DEFAULT_GENERATED on update CURRENT_TIMESTAMP |                                                               |                                             |                                                                                                                              |
| last_modified_by      | varchar(180)                                |                   | false    |                                               |                                                               |                                             |                                                                                                                              |
| md5sum                | varchar(32)                                 |                   | true     |                                               |                                                               |                                             | MD5 sum of file contents for integrity verification and duplicate detection.                                                 |
| mime_type             | varchar(255)                                |                   | true     |                                               |                                                               |                                             | MIME type of the file (e.g., text/csv, application/pdf).                                                                     |
| multipart_upload_id   | varchar(255)                                |                   | true     |                                               |                                                               |                                             | S3 multipart upload ID for large file uploads.                                                                               |
| original_file_name    | varchar(255)                                |                   | false    |                                               |                                                               |                                             | Original filename from upload.                                                                                               |
| s3_bucket             | varchar(63)                                 |                   | false    |                                               |                                                               |                                             | S3 bucket name where the file is stored (e.g., prod-abacus-flowthrough).                                                     |
| s3_key                | varchar(1024)                               |                   | false    |                                               |                                                               |                                             | S3 object key/path for the uploaded file (e.g., uploads/2025/11/00000000-0000-0000-0000-000000000000.csv).                   |
| total_parts           | smallint                                    | 1                 | false    |                                               |                                                               |                                             | Total number of parts for multipart uploads.                                                                                 |
| upload_metadata       | json                                        |                   | true     |                                               |                                                               |                                             | Additional metadata about the upload (flexible JSON structure).                                                              |
| upload_status         | enum('init','complete','error','cancelled') | init              | false    |                                               |                                                               |                                             | Current status of the upload. init: initiated, complete: successfully uploaded, error: failed, cancelled: cancelled by user. |

## Constraints

| Name                  | Type        | Definition                                                                                |
| --------------------- | ----------- | ----------------------------------------------------------------------------------------- |
| PRIMARY               | PRIMARY KEY | PRIMARY KEY (file_upload_id)                                                              |
| fk_file_upload_config | FOREIGN KEY | FOREIGN KEY (file_upload_config_id) REFERENCES file_upload_config (file_upload_config_id) |
| uidx_file_key         | UNIQUE      | UNIQUE KEY uidx_file_key (file_key)                                                       |

## Indexes

| Name                  | Definition                                                    |
| --------------------- | ------------------------------------------------------------- |
| PRIMARY               | PRIMARY KEY (file_upload_id) USING BTREE                      |
| fk_file_upload_config | KEY fk_file_upload_config (file_upload_config_id) USING BTREE |
| idx_md5sum            | KEY idx_md5sum (md5sum) USING BTREE                           |
| uidx_file_key         | UNIQUE KEY uidx_file_key (file_key) USING BTREE               |

## Relations

![er](file_upload.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
