fp/services/migrations-schema/migrations/00051_set-vod-status.sql

21 lines
502 B
MySQL
Raw Normal View History

2024-08-31 10:42:28 +00:00
-- 'NEW' in this context is a segment row.
-- we update this function to also set the vod status to 'recording' if applicable.
CREATE OR REPLACE FUNCTION update_vod_on_segment_update()
RETURNS TRIGGER AS $$
BEGIN
UPDATE api.vods
SET
updated_at = NOW(),
status = CASE
WHEN NEW.filesize > OLD.filesize THEN 'recording'
ELSE status
END
WHERE id IN (
SELECT vod_id
FROM segments_vod_links
WHERE segment_id = NEW.id
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;