-- M20 分镜素材版本与视频任务回写

ALTER TABLE shot_assets
    ADD COLUMN project_id      BIGINT DEFAULT NULL COMMENT 'Project id',
    ADD COLUMN episode_id      BIGINT DEFAULT NULL COMMENT 'Episode id',
    ADD COLUMN source_task_id  BIGINT DEFAULT NULL COMMENT 'Source ai_tasks id',
    ADD COLUMN asset_version   INT NOT NULL DEFAULT 1 COMMENT 'Version within storyboard + asset type',
    ADD COLUMN characters      TEXT DEFAULT NULL COMMENT 'Referenced character image keys JSON',
    ADD COLUMN meta_json       LONGTEXT DEFAULT NULL COMMENT 'Asset metadata JSON',
    ADD COLUMN error_message   TEXT DEFAULT NULL COMMENT 'Failure message',
    ADD COLUMN updated_at      DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3);

CREATE INDEX idx_shot_assets_project ON shot_assets (project_id, tenant_id);
CREATE INDEX idx_shot_assets_task ON shot_assets (source_task_id);
CREATE INDEX idx_shot_assets_type_version ON shot_assets (storyboard_id, asset_type, asset_version);
