-- rozsirenie ENUM pre ACL
-- novymi moznostami su:
-- Regiotv: rtv_contract_package, rtv_headend_channel_ip, rtv_stb, rtv_stb_type
-- Globis: doc, doc_file, doc_tree
-- Ipfon: 

BEGIN;

CREATE TYPE enum_acl_dataset_name_new AS ENUM(
-- globis
'acl',
'billitem',
'contract',
'contract_status',
'contract_type',
'contract_type_person',
'country',
'doc',
'doc_file',
'doc_tree',
'entitled_person',
'entitled_person_type',
'nationality',
'person',
'person_contact',
'person_contact_status',
'person_contact_type',
'person_passwd_reset',
'person_representation',
'person_role',
'sk_obec',
'sk_okres',
'sk_ulica',
'tarif',
'tarifaccess',
'tarifitem',
'tarifitemrate',
'test_sqlconnector',

-- ipfon
'ea_areas',
'ea_prefix_mapping',
'ea_regions',
'ea_services',
'ea_tranformations',
'ew_dataset',
'ew_fields',
'ew_rights',
'ipfon_account',
'ipfon_account_event',
'ipfon_billitem',
'ipfon_cdr',
'ipfon_cdr_ic',
'ipfon_contract',
'ipfon_fax_account',
'ipfon_fax_job',
'ipfon_fax_try',
'ipfon_icpoint',
'ipfon_num',
'ipfon_numgrp',
'ipfon_operator',
'ipfon_partner',
'ipfon_quality',
'ipfon_rate',
'ipfon_rategrp',
'ipfon_sms_out_log',
'ipfon_sms_out_queue',
'ipfon_sms_senderid',
'ipfon_sms_tarifprefix',
'ipfon_speeddial',
'ipfon_tarifprefix',
'ipfon_telno',
'ipfon_telno_inp',
'old_ipfon_tarifitem',
'old_ipfon_tarifitemrate',
'old_ipfon_tarifplan',
'operator',
'staff',
'webshop_data',

-- regiotv
'rtv_channel',
'rtv_contactlist',
'rtv_contract',
'rtv_contract_package',
'rtv_customer',
'rtv_customer_status',
'rtv_headend',
'rtv_headend_channel',
'rtv_headend_channel_ip',
'rtv_package',
'rtv_package_channel',
'rtv_provider',
'rtv_stb',
'rtv_stb_type'
);
ALTER TABLE acl ADD COLUMN dataset_name_new enum_acl_dataset_name_new;
UPDATE acl SET dataset_name_new=dataset_name::text::enum_acl_dataset_name_new;
ALTER TABLE acl ALTER COLUMN dataset_name_new SET NOT NULL;

DROP INDEX acl_dataset_name_person_role_dataset_id;
ALTER TABLE acl DROP COLUMN dataset_name;
DROP TYPE enum_acl_dataset_name;
ALTER TABLE acl RENAME COLUMN dataset_name_new TO dataset_name;
ALTER TYPE enum_acl_dataset_name_new RENAME TO enum_acl_dataset_name;

CREATE INDEX acl_dataset_name_person_role_dataset_id
	ON acl (dataset_name, person, person_role, dataset_id);

COMMIT;

-- select
INSERT INTO acl (dataset_name, permit_select) VALUES ('doc_tree',true);
INSERT INTO acl (dataset_name, permit_select) VALUES ('rtv_stb_type',true);
