CREATE OR REPLACE VIEW itgr.vw_device_data_log AS
    SELECT 
        e.tenant_id,
        l.created_at,
        l.updated_at,
        l.deleted_at,
        l.is_active,
        l.is_deleted,
        l.id,
        s.name as log_status_name,
        l.error as log_error,
        l.original_id as device_data_id,
        l.device_created_at,
        l.table_name,
        l.pk,
        l.sf_id,
        l.external_id,
        l.device_id,
        l.user_id,
        l.group_id,
        e.id::BIGINT as execution_id,
        ss.name as execution_status_name,
        e.doc_meta_data as execution_doc_meta_data,
        null as execution_job_faktory_id,
        null as execution_worker_faktory_id
    FROM
        itgr.execution e
            inner join itgr.status ss on ss.id = e.status_id
            inner join itgr.device_data_log l on e.id = l.execution_id
            inner join itgr.status s on s.id = l.status_id
    WHERE
        l.is_active = TRUE and l.is_deleted = false
        and e.is_active = TRUE and e.is_deleted = false
    ORDER BY 
        l.id
;

