-- DROP VIEW public.dim_status;

DROP VIEW IF EXISTS dim_status;

CREATE OR REPLACE VIEW public.dim_status AS
    SELECT id_appointment_status, name, description, code_name
	FROM public.appointment_status
    where display = true
    ORDER BY	code_name;

ALTER TABLE public.dim_status
    OWNER TO postgres;
COMMENT ON VIEW public.dim_status
    IS 'Vista creada para mostrar los estados del RIS que se encuentren activos.  Esta vista es usada por la herramienta de BI';    

GRANT ALL ON TABLE public.dim_status TO postgres;

DO 
$do$
BEGIN
   IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'metabase_user')     
   THEN
		GRANT SELECT ON TABLE public.dim_status TO metabase_user;
   END IF;
END
$do$;    


