-- zikai_filesvc 数据库的表定义。
-- 由 app/scripts/init_db.py 通过本机 socket 以 root 身份执行；表级幂等。

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `uploaded_file` (
    `id`                BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `storage_path`      VARCHAR(512)    NOT NULL COMMENT 'upload_dir 下相对路径，例如 2026/06/<uuid>.bin',
    `original_filename` VARCHAR(512)    NOT NULL,
    `content_type`      VARCHAR(255)    NOT NULL DEFAULT '',
    `size_bytes`        BIGINT UNSIGNED NOT NULL DEFAULT 0,
    `sha256`            CHAR(64)        NOT NULL DEFAULT '',
    `source`            VARCHAR(32)     NOT NULL DEFAULT 'http' COMMENT 'http / sftp / ...',
    `uploaded_by`       VARCHAR(128)    NOT NULL DEFAULT '',
    `uploaded_at`       DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    KEY `idx_uploaded_at` (`uploaded_at`),
    KEY `idx_source` (`source`),
    KEY `idx_sha256` (`sha256`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
