
-- apis_data

alter view apis_data owner to gavoadmin;
GRANT SELECT ON TABLE apis_data TO gavo;
GRANT ALL ON  apis_data TO lesia;
GRANT ALL ON  apis_data TO gavoadmin;
grant select on apis_data to public;
grant update on apis_data_id_seq to lesia;

-- bastet_secondary_targets

alter table bastet_secondary_targets owner to gavoadmin;
GRANT SELECT ON TABLE bastet_secondary_targets TO gavo;
GRANT ALL ON TABLE bastet_secondary_targets TO lesia;
GRANT ALL ON TABLE bastet_secondary_targets TO gavoadmin;
grant select on bastet_secondary_targets to public;

-- views

alter view apis_telescopes owner to gavoadmin;
GRANT SELECT ON apis_telescopes TO gavo;
GRANT ALL ON apis_telescopes TO lesia;
GRANT ALL ON apis_telescopes TO gavoadmin;
grant select on apis_telescopes to public;

alter view apis_targets owner to gavoadmin;
GRANT SELECT ON apis_targets TO gavo;
GRANT ALL ON apis_targets TO lesia;
GRANT ALL ON apis_targets TO gavoadmin;
grant select on apis_targets to public;

alter view apis_campaign owner to gavoadmin;
GRANT SELECT ON apis_campaign TO gavo;
GRANT ALL ON apis_campaign TO lesia;
GRANT ALL ON apis_campaign TO gavoadmin;
grant select on apis_campaign to public;

alter view apis_secondary_targets owner to gavoadmin;
GRANT SELECT ON apis_secondary_targets TO gavo;
GRANT ALL ON apis_secondary_targets TO lesia;
GRANT ALL ON apis_secondary_targets TO gavoadmin;
grant select on apis_secondary_targets to public;

-- apis_dataset

-- alter view apis_dataset owner to gavoadmin;
-- GRANT SELECT ON  apis_dataset TO gavo;
-- GRANT ALL ON  apis_dataset TO lesia;

-- epn_core

alter view epn_core owner to gavoadmin;

REVOKE ALL ON  epn_core FROM PUBLIC;
REVOKE ALL ON  epn_core FROM postgres;
GRANT ALL ON  epn_core TO postgres;
GRANT ALL ON  epn_core TO gavoadmin WITH GRANT OPTION;
GRANT ALL ON  epn_core TO gavo WITH GRANT OPTION;

GRANT SELECT ON  epn_core TO untrusted;
GRANT SELECT ON  epn_core TO gavo;
GRANT ALL ON  epn_core TO lesia ;
GRANT ALL ON  epn_core TO gavoadmin;

-- concat_selected_fields

GRANT USAGE ON LANGUAGE plpgsql TO gavo;
GRANT ALL ON LANGUAGE plpgsql TO gavoadmin;

alter function concat_selected_fields(text,  text, text) owner to gavoadmin;
GRANT EXECUTE ON FUNCTION concat_selected_fields(text,  text, text) TO gavo;
GRANT ALL ON FUNCTION concat_selected_fields(text,  text, text)  TO lesia;


-- bastet_data

alter table bastet_data owner to gavoadmin;
GRANT SELECT ON TABLE bastet_data TO gavo;
GRANT ALL ON TABLE bastet_data TO lesia;
GRANT ALL ON TABLE bastet_data TO gavoadmin;
grant select on bastet_data to public;
grant update on baster_data_id_seq to lesia;
grant delete on baster_data_id_seq to lesia;
grant insert on baster_data_id_seq to lesia;


-- nephtys_data

alter table nephtys_data owner to gavoadmin;
GRANT SELECT ON TABLE nephtys_data TO gavo;
GRANT ALL ON TABLE nephtys_data TO lesia;
GRANT ALL ON TABLE nephtys_data TO gavoadmin;
grant select on nephtys_data to public;
grant update on baster_data_id_seq to lesia;
grant delete on baster_data_id_seq to lesia;
grant insert on baster_data_id_seq to lesia;



-- hisaki_data

alter table hisaki_data owner to gavoadmin;
GRANT SELECT ON TABLE hisaki_data TO gavo;
GRANT ALL ON TABLE hisaki_data TO lesia;
GRANT ALL ON TABLE hisaki_data TO gavoadmin;
grant select on hisaki_data to public;
grant update on hisaki_data to lesia;
grant insert on hisaki_data to lesia;
grant delete on hisaki_data to lesia;

grant update on apis_data_id_seq to lesia;

