CREATE TABLE `background_tasks` (
	`id` varchar(36) NOT NULL,
	`userId` int NOT NULL,
	`type` enum('media_finalize','training_plan_generate','training_plan_adjust','analysis_corrections','pose_correction_multimodal') NOT NULL,
	`status` enum('queued','running','succeeded','failed') NOT NULL DEFAULT 'queued',
	`title` varchar(256) NOT NULL,
	`message` text,
	`progress` int NOT NULL DEFAULT 0,
	`payload` json NOT NULL,
	`result` json,
	`error` text,
	`attempts` int NOT NULL DEFAULT 0,
	`maxAttempts` int NOT NULL DEFAULT 3,
	`workerId` varchar(96),
	`runAfter` timestamp NOT NULL DEFAULT (now()),
	`lockedAt` timestamp,
	`startedAt` timestamp,
	`completedAt` timestamp,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `background_tasks_id` PRIMARY KEY(`id`)
);
