fp/services/migrations-schema/migrations/00034_move-segments-to-vods...

25 lines
607 B
SQL

-- segments get moved to vods
DROP TABLE api.segments_stream_links CASCADE;
-- segments to vod, many-to-one
CREATE TABLE api.segments_vod_links (
id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
vod_id text NOT NULL,
segment_id text NOT NULL
);
-- roles & permissions
GRANT all ON api.segments_vod_links TO automation;
GRANT SELECT ON api.segments_vod_links TO web_anon;
-- establish many-to-one relationship by adding a foreign key to segments
ALTER TABLE api.segments
ADD COLUMN vod_id TEXT;
ALTER TABLE api.segments
ADD CONSTRAINT vod_id_not_null
CHECK (vod_id IS NOT NULL) NOT VALID;