Move to new db setup
This commit is contained in:
+15
-99
@@ -18,119 +18,35 @@ USE videodetect;
|
||||
CREATE TABLE IF NOT EXISTS videos (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
file_path VARCHAR(2048) NOT NULL,
|
||||
file_hash CHAR(64) NOT NULL COMMENT 'SHA-256 hash of file',
|
||||
file_size BIGINT NOT NULL COMMENT 'Size of the file in bytes',
|
||||
file_hash CHAR(64) COMMENT 'SHA-256 hash of file',
|
||||
resolution_w INT DEFAULT NULL,
|
||||
resolution_h INT DEFAULT NULL,
|
||||
codec VARCHAR(50) DEFAULT NULL,
|
||||
duration FLOAT DEFAULT NULL COMMENT 'Duration in seconds',
|
||||
status ENUM('NEW', 'PENDING', 'PROCESSING', 'COMPLETED', 'UNSCANNABLE', 'ERROR')
|
||||
NOT NULL DEFAULT 'NEW' COMMENT 'Processing status',
|
||||
last_scan_time DATETIME DEFAULT NULL,
|
||||
last_processed_time DATETIME DEFAULT NULL,
|
||||
confidence_score FLOAT DEFAULT NULL COMMENT 'Video-level confidence score',
|
||||
routing_decision ENUM('MATCH', 'REVIEW', 'SKIP') DEFAULT NULL COMMENT 'Routing decision',
|
||||
model_version VARCHAR(50) DEFAULT NULL COMMENT 'Model version used for processing',
|
||||
frame_count INT DEFAULT NULL COMMENT 'Number of frames sampled',
|
||||
error_message TEXT DEFAULT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
UNIQUE KEY uk_file_hash (file_hash),
|
||||
INDEX idx_videos_status (status),
|
||||
UNIQUE KEY uk_path (file_path),
|
||||
INDEX idx_videos_last_scan (last_scan_time),
|
||||
INDEX idx_videos_status_last_scan (status, last_scan_time),
|
||||
INDEX idx_videos_file_path (file_path(255))
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table: processing_logs
|
||||
-- Audit trail for each video processing job
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS processing_logs (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tasks (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
task_type VARCHAR(16) NOT NULL,
|
||||
video_id BIGINT NOT NULL,
|
||||
model_version VARCHAR(50) NOT NULL,
|
||||
frame_count INT NOT NULL DEFAULT 0,
|
||||
confidence_score FLOAT DEFAULT NULL,
|
||||
confidence_scores JSON DEFAULT NULL COMMENT 'Frame-level confidence scores',
|
||||
routing_decision ENUM('MATCH', 'REVIEW', 'SKIP') NOT NULL,
|
||||
processed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
error_message TEXT DEFAULT NULL,
|
||||
FOREIGN KEY (video_id) REFERENCES videos(id) ON DELETE CASCADE,
|
||||
INDEX idx_processing_logs_video (video_id),
|
||||
INDEX idx_processing_logs_processed_at (processed_at),
|
||||
INDEX idx_processing_logs_routing (routing_decision)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table: models
|
||||
-- Model registry tracking all deployed and archived models
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS models (
|
||||
version VARCHAR(50) PRIMARY KEY,
|
||||
status ENUM('ACTIVE', 'CANDIDATE', 'ARCHIVED') NOT NULL DEFAULT 'CANDIDATE',
|
||||
path VARCHAR(2048) NOT NULL,
|
||||
calibration_temp FLOAT DEFAULT NULL COMMENT 'Temperature scaling parameter',
|
||||
f1_score FLOAT DEFAULT NULL COMMENT 'F1 score on validation set',
|
||||
ece_score FLOAT DEFAULT NULL COMMENT 'Expected Calibration Error',
|
||||
deployed_at DATETIME DEFAULT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_models_status (status)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table: review_queue
|
||||
-- Videos awaiting manual annotation
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS review_queue (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
video_id BIGINT NOT NULL,
|
||||
confidence_score FLOAT NOT NULL,
|
||||
routing_decision ENUM('REVIEW') NOT NULL DEFAULT 'REVIEW',
|
||||
annotated BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ground_truth BOOLEAN DEFAULT NULL COMMENT 'True label from annotator',
|
||||
annotated_at DATETIME DEFAULT NULL,
|
||||
notes TEXT DEFAULT NULL,
|
||||
status ENUM('PENDING', 'IN_PROGRESS', 'COMPLETED', 'FAILED') NOT NULL DEFAULT 'PENDING',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
assign_key VARCHAR(64) DEFAULT NULL COMMENT 'Key to identify the worker assigned to this task',
|
||||
assigned_at DATETIME DEFAULT NULL COMMENT 'Timestamp when the task was assigned to a worker',
|
||||
results JSON DEFAULT NULL COMMENT 'Task-specific results or metadata',
|
||||
FOREIGN KEY (video_id) REFERENCES videos(id) ON DELETE CASCADE,
|
||||
INDEX idx_review_queue_annotated (annotated),
|
||||
INDEX idx_review_queue_created (created_at)
|
||||
INDEX idx_tasks_video (video_id),
|
||||
INDEX idx_tasks_status (status),
|
||||
INDEX idx_tasks_type_status (task_type, status),
|
||||
UNIQUE KEY uk_tasks_video_type (video_id, task_type)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table: scan_history
|
||||
-- Tracks directory scan operations for incremental sync
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS scan_history (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
scan_start DATETIME NOT NULL,
|
||||
scan_end DATETIME DEFAULT NULL,
|
||||
files_discovered INT DEFAULT 0,
|
||||
files_new INT DEFAULT 0,
|
||||
files_modified INT DEFAULT 0,
|
||||
files_removed INT DEFAULT 0,
|
||||
files_unscannable INT DEFAULT 0,
|
||||
duration_seconds FLOAT DEFAULT NULL,
|
||||
status ENUM('RUNNING', 'COMPLETED', 'FAILED') NOT NULL DEFAULT 'RUNNING',
|
||||
error_message TEXT DEFAULT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table: scanner_lock
|
||||
-- Single-instance guard for the directory scanner. Ensures only one scan
|
||||
-- runs at a time across all replicas. A lease (locked_at + lease_seconds)
|
||||
-- lets a live scanner keep the lock via heartbeats, and lets a crashed
|
||||
-- scanner's lock be taken over once it goes stale.
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS scanner_lock (
|
||||
lock_name VARCHAR(64) PRIMARY KEY,
|
||||
owner VARCHAR(128) NOT NULL COMMENT 'Instance id (host-pid-uuid) holding the lock',
|
||||
locked_at DATETIME NOT NULL COMMENT 'Last time the lock was acquired or heartbeated',
|
||||
lease_seconds INT NOT NULL DEFAULT 21600 COMMENT 'Lock is stale if older than this (6 hours)'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Insert default model entry
|
||||
-- -----------------------------------------------------
|
||||
INSERT IGNORE INTO models (version, status, path, calibration_temp, created_at)
|
||||
VALUES ('v0.0.0-placeholder', 'ACTIVE', '/models/placeholder', 1.0, NOW());
|
||||
|
||||
Reference in New Issue
Block a user