-- zmeny v databaze regiotv

GRANT SELECT, UPDATE, INSERT ON rtv_channel TO extranet;
GRANT USAGE ON rtv_channel_id_seq TO extranet;

ALTER TABLE rtv_channel ADD PRIMARY KEY (id);

GRANT SELECT ON rtv_provider TO extranet;

-- z dna 10.9.2014
GRANT SELECT, INSERT, UPDATE ON rtv_package_channel TO extranet;
GRANT USAGE ON rtv_package_channel_id_seq TO extranet;
GRANT SELECT, INSERT, UPDATE ON rtv_headend_channel TO extranet;
GRANT USAGE ON rtv_headend_channel_id_seq TO extranet;

ALTER TABLE rtv_package_channel ADD PRIMARY KEY (id);
ALTER TABLE rtv_headend_channel ADD PRIMARY KEY (id);

-- z dna 12.9.2014
ALTER TABLE rtv_headend ADD PRIMARY KEY (id);

CREATE TABLE rtv_headend_channel_ip (
	id SERIAL NOT NULL,
	headend INT NOT NULL REFERENCES rtv_headend (id) ON UPDATE CASCADE ON DELETE CASCADE,
	channel INT NOT NULL REFERENCES rtv_channel (id) ON UPDATE CASCADE ON DELETE CASCADE,
	ip INET NOT NULL,
	port INT NOT NULL,
	active SMALLINT NOT NULL DEFAULT 1,
	priority SMALLINT NOT NULL DEFAULT 0,
	PRIMARY KEY (id)
);

CREATE INDEX rtv_headend_channel_ip_headend ON rtv_headend_channel_ip (headend);
CREATE INDEX rtv_headend_channel_ip_channel ON rtv_headend_channel_ip (channel);

COMMENT ON COLUMN rtv_headend_channel_ip.priority IS 'Priorita zaznamu (ak je viac zaznamov)';
COMMENT ON COLUMN rtv_headend_channel_ip.ip IS 'Multicast IP adresa';
COMMENT ON COLUMN rtv_headend_channel_ip.port IS 'Cislo portu pre multicast';
COMMENT ON COLUMN rtv_headend_channel_ip.active IS 'Ci je tento zaznam aktivny (1=ano, 0=nie)';

ALTER TABLE rtv_headend_channel DROP COLUMN ip;
ALTER TABLE rtv_headend_channel DROP COLUMN port;
ALTER TABLE rtv_headend_channel DROP COLUMN active;
ALTER TABLE rtv_headend_channel DROP COLUMN priority;

GRANT SELECT, UPDATE, INSERT ON rtv_headend_channel_ip TO extranet;
GRANT USAGE ON rtv_headend_channel_ip_id_seq TO extranet;
