19 lines
664 B
SQL
19 lines
664 B
SQL
CREATE TABLE IF NOT EXISTS live_show_timer_runs (
|
|
id TEXT PRIMARY KEY,
|
|
show_id TEXT NOT NULL REFERENCES shows(id) ON DELETE CASCADE,
|
|
started_at_utc TEXT NOT NULL,
|
|
ended_at_utc TEXT,
|
|
CHECK (ended_at_utc IS NULL OR ended_at_utc >= started_at_utc)
|
|
);
|
|
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_one_open_show_timer_run
|
|
ON live_show_timer_runs(show_id)
|
|
WHERE ended_at_utc IS NULL;
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_live_show_timer_runs_show
|
|
ON live_show_timer_runs(show_id, started_at_utc);
|
|
|
|
INSERT OR IGNORE INTO live_show_timer_runs (id, show_id, started_at_utc, ended_at_utc)
|
|
SELECT 'migrated-' || id, show_id, started_at_utc, ended_at_utc
|
|
FROM live_usage_runs;
|