You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.3 KiB
27 lines
1.3 KiB
-- 该迁移用于已有数据库;新数据库请直接使用 001_schema.sql 中的最终结构。
|
|
-- 执行前应确认 live_session 没有重复活动会话,再创建活动机巢唯一约束。
|
|
|
|
ALTER TABLE live_session
|
|
ADD COLUMN requested_by BIGINT NULL,
|
|
ADD COLUMN stop_deadline DATETIME NULL,
|
|
ADD COLUMN updated_at DATETIME NULL,
|
|
ADD COLUMN active_dock_id VARCHAR(64) GENERATED ALWAYS AS (
|
|
CASE WHEN phase IN ('starting', 'streaming', 'reconnecting', 'stopping') THEN dock_id ELSE NULL END
|
|
) STORED,
|
|
ADD KEY idx_live_session_dock_phase (dock_id, phase, created_at),
|
|
ADD KEY idx_live_session_phase_deadline (phase, stop_deadline),
|
|
ADD UNIQUE KEY uk_live_session_active_dock (active_dock_id);
|
|
|
|
CREATE TABLE IF NOT EXISTS live_viewer_lease (
|
|
id BIGINT PRIMARY KEY,
|
|
stream_session_id VARCHAR(128) NOT NULL,
|
|
viewer_id BIGINT NOT NULL,
|
|
expires_at DATETIME NOT NULL,
|
|
released_at DATETIME NULL,
|
|
created_at DATETIME NULL,
|
|
updated_at DATETIME NULL,
|
|
UNIQUE KEY uk_live_viewer (stream_session_id, viewer_id),
|
|
KEY idx_live_lease_expire (stream_session_id, expires_at),
|
|
KEY idx_live_lease_active (stream_session_id, released_at, expires_at),
|
|
CONSTRAINT fk_live_lease_session FOREIGN KEY (stream_session_id) REFERENCES live_session(id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|