--
--


SELECT pg_catalog.set_config('search_path', '', false);

--
-- Name: fms_bhasika; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA fms_bhasika;


--
-- Name: SCHEMA fms_bhasika; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON SCHEMA fms_bhasika IS 'standard fms_bhasika schema';


--
-- Name: get_all_recepients_with_single_msg(); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.get_all_recepients_with_single_msg() RETURNS TABLE(ids bigint, created_at text, messages text, modes character varying, detail_id bigint, recipient_detail_name character varying, sources character varying, group_id bigint, state character varying)
    LANGUAGE plpgsql
    AS $$
begin
    return query
        select kk.id                  as id,
               kk.created_date,
               kk.message             as messages,
               kk.mode                as modes,
               kk.recipient_detail_id as detail_id,
               kk.recipientName       as recipient_detail_name,
               rd.source              as sources,
               kk.groupe              as group_id,
               kk.message_state       as state
        from (select row_number() over (partition by mm.recipient_detail_id ) user_ids, *
              from (select id,
                           to_char(created_date, 'yyyy-MM-dd hh:mi:ss AM') created_date,
                           last_modified_date,
                           message,
                           mode,
                           recipient_detail_id,
                           groupe,
                           recipientName,
                           message_state
                    from (select *
                          from (SELECT row_number() over (partition by individual order by created_date desc) rownum, *
                                FROM external_message em
                                         JOIN (SELECT mm.ourid    AS individual,
                                                      mm.group_id AS groupe,
                                                      mm.recipientName
                                               FROM (SELECT Row_number()
                                                            OVER (
                                                                partition BY rd.id) AS num,
                                                            rdg.id                  AS group_id,
                                                            rd.id                   AS ourId,
                                                            rd.recipient_name       as recipientName
                                                     FROM recipient_detail rd
                                                              LEFT JOIN recipient_group_mapping rgm
                                                                        ON rd.id = rgm.recipient_detail_id
                                                              LEFT JOIN recipient_detail_group rdg
                                                                        ON rdg.id = rgm.recipient_detail_group_id
                                                     GROUP BY rdg.id,
                                                              rd.id
                                                     ORDER BY rd.id DESC) mm
                                               WHERE num = 1) AS ss
                                              ON CASE
                                                     WHEN ss.groupe IS NULL THEN ss.individual = em.recipient_detail_id
                                                     ELSE em.recipient_detail_id IN
                                                          (SELECT re.*
                                                           FROM (SELECT viber_id AS recipient_detail
                                                                 FROM recipient_detail_group
                                                                 WHERE id = ss.groupe
                                                                 UNION ALL
                                                                 SELECT messenger_id
                                                                 FROM recipient_detail_group
                                                                 WHERE id = ss.groupe
                                                                 UNION ALL
                                                                 SELECT whatsapp_id
                                                                 FROM recipient_detail_group
                                                                 WHERE id = ss.groupe) re)
                                                  end
                                order by em.created_date desc) grouped
                          where rownum = 1) alll) mm) kk
                 join recipient_detail rd on rd.id = kk.recipient_detail_id
        where user_ids = 1
        order by created_date desc;
END
$$;


--
-- Name: get_recipient_detail_individual_group(bigint); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.get_recipient_detail_individual_group(recipientid bigint) RETURNS TABLE(id bigint, recipient character varying, recipient_name character varying, source character varying, email character varying, display_name character varying, recipient_group_id bigint)
    LANGUAGE plpgsql
    AS $$
DECLARE
recipient_group_id int8;
BEGIN
    -- Assign values to the var1 array
select re.recipient_detail_group_id
into recipient_group_id
from recipient_group_mapping re
where re.recipient_detail_id = recipientId;

if (recipient_group_id is not null) then
        return query
select rd.id,rd.recipient, rd.recipient_name, rd.source,rdg.email, rdg.display_name, rdg.id
from recipient_group_mapping rgm
         join recipient_detail rd on rd.id = rgm.recipient_detail_id
         join recipient_detail_group rdg on (case
                                                 when rd."source" = 'MESSENGER'
                                                     then rd.id = rdg.messenger_id
                                                 when rd."source" = 'VIBER' then rd.id = rdg.viber_id
                                                 when rd."source" = 'WHATSAPP' then rd.id = rdg.whatsapp_id
    end)
where rgm.recipient_detail_group_id = recipient_group_id;
else
        return query
select rd.id,rd.recipient, rd.recipient_name, rd.source,rd.email, rd.recipient_name, Null::bigint
from recipient_detail rd
where rd.id = recipientId;
end if;
END
$$;


--
-- Name: get_ticket_activity(bigint); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.get_ticket_activity(p_ticket_id bigint) RETURNS TABLE("createdBy" bigint, "activityId" bigint, "createdDate" text, "carbonEmailIds" character varying, module character varying, "actionType" character varying, "relatedUserEmail" character varying, "relatedUserId" character varying, "ticketId" bigint, message character varying)
    LANGUAGE plpgsql
    AS $$
begin
return query
select fal.created_by                                      as "createdBy",
       fal.id                                              as "activityId",
       to_char(fal.created_date, 'yyyy-mm-dd HH:MI:SS AM') as "createdDate",
       fal.cc                                              as "carbonEmailIds",
       fal.module                                          as "module",
       fal.action_type                                     as "actionType",
       fal.related_user_email                              as "relatedUserEmail",
       fal.related_user_id                                 as "relatedUserId",
       fal.ticket_id                                       as "ticketId",
       fal.message                                         as "message"

from fms_activity_log fal
where fal.ticket_id = p_ticket_id
order by id desc;
END;
$$;


--
-- Name: get_ticket_activity_updated(bigint); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.get_ticket_activity_updated(p_ticket_id bigint) RETURNS TABLE("createdBy" bigint, "activityId" bigint, "createdDate" text, "createdTime" text, "carbonEmailIds" character varying, module character varying, "actionType" character varying, "relatedUserEmail" character varying, "relatedUserId" character varying, "ticketId" bigint, message character varying)
    LANGUAGE plpgsql
    AS $$
begin
return query
select fal.created_by                           as "createdBy",
       fal.id                                   as "activityId",
       to_char(fal.created_date, 'yyyy-MM-dd')  as "createdDate",
       to_char(fal.created_date, 'HH:MI:SS AM') as "createdTime",
       fal.cc                                   as "carbonEmailIds",
       fal.module                               as "module",
       fal.action_type                          as "actionType",
       fal.related_user_email                   as "relatedUserEmail",
       fal.related_user_id                      as "relatedUserId",
       fal.ticket_id                            as "ticketId",
       fal.message                              as "message"
from fms_activity_log fal
where fal.ticket_id = p_ticket_id
order by id desc;
END;
$$;


--
-- Name: get_weekly_ticket_count(bigint); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.get_weekly_ticket_count(user_id bigint) RETURNS TABLE(day text, count bigint)
    LANGUAGE plpgsql
    AS $$
begin
    return query
        select to_char(t.date, 'D') as day,
               count(mdt.id)
        from ticket mdt
                 join (
            select generate_series(
                                       current_date - 5, current_date, '1 day' :: interval
                       ):: date as date
        ) as t on to_char(t.date, 'yyyy-mm-dd') = to_char(mdt.created_date, 'yyyy-mm-dd')
        where  mdt.assignee = user_id
        group by t.date
        order by day asc;
end;
$$;


--
-- Name: insert_or_update_search_index(); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.insert_or_update_search_index() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
begin
    IF (TG_TABLE_NAME = 'ticket') then
        IF (TG_OP = 'INSERT') then
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, t.ticket_id, 'TICKET'
                                                                             from ticket t
                                                                             where t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, t.title, 'TITLE'
                                                                             from ticket t
                                                                             where t.title is not null
                                                                               and t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, r.name, 'REQUESTOR'
                                                                             from ticket t join requester r on t.requester_id = r.id
                                                                             where t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, r.email, 'REQUESTOR_EMAIL'
                                                                             from ticket t join requester r on t.requester_id = r.id
                                                                             where t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, r.mobile_no, 'MOBILE'
                                                                             from ticket t join requester r on t.requester_id = r.id
                                                                             where r.mobile_no is not null
                                                                               and t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, u.email_address, 'ASSIGNEE_EMAIL'
                                                                             from ticket t
                                                                                      join users u on u.id = t.assignee
                                                                             where t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id,
                                                                                    concat(u.first_name, case
                                                                                                             when u.middle_name != ''
                                                                                                                 then concat(' ', u.middle_name, ' ')
                                                                                                             else ' ' end,
                                                                                           u.last_name),
                                                                                    'ASSIGNEE_NAME'
                                                                             from ticket t
                                                                                      join users u on u.id = t.assignee and t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source)
            select t.id, d.department_name, 'DEPARTMENT'
            from ticket t
                     join department d on d.id = t.department_id
            where t.id = new.id;
            INSERT INTO documents_search (ticket_id, document_text, source)
            select t.id, tc.name, 'CATEGORY'
            from ticket t
                     join ticket_category tc ON tc.id = t.category
            where t.id = new.id;
            UPDATE documents_search d1
            SET document_tokens = to_tsvector(d1.document_text)
            FROM documents_search d2
            where d2.document_tokens is null
              and d1.ticket_id = new.id;
        ELSIF (TG_OP = 'UPDATE') THEN
            delete
            from documents_search
            where ticket_id = NEW.id
              and source in ('MOBILE', 'ASSIGNEE_EMAIL', 'ASSIGNEE_NAME');
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, r.mobile_no, 'MOBILE'
                                                                             from ticket t join requester r on t.requester_id = r.id
                                                                             where r.mobile_no is not null
                                                                               and t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id, u.email_address, 'ASSIGNEE_EMAIL'
                                                                             from ticket t
                                                                                      join users u on u.id = t.assignee
                                                                             where t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source) (select t.id,
                                                                                    concat(u.first_name, case
                                                                                                             when u.middle_name != ''
                                                                                                                 then concat(' ', u.middle_name, ' ')
                                                                                                             else ' ' end,
                                                                                           u.last_name),
                                                                                    'ASSIGNEE_NAME'
                                                                             from ticket t
                                                                                      join users u on u.id = t.assignee and t.id = new.id);
            INSERT INTO documents_search (ticket_id, document_text, source)
            select t.id, d.department_name, 'DEPARTMENT'
            from ticket t
                     join department d on d.id = t.department_id
            where t.id = new.id;
            INSERT INTO documents_search (ticket_id, document_text, source)
            select t.id, tc.name, 'CATEGORY'
            from ticket t
                     join ticket_category tc ON tc.id = t.category
            where t.id = new.id;
            UPDATE documents_search d1
            SET document_tokens = to_tsvector(d1.document_text)
            FROM documents_search d2
            where d2.document_tokens is null
              and d1.ticket_id = new.id
              and d1.source in ('MOBILE', 'ASSIGNEE_EMAIL', 'ASSIGNEE_NAME', 'DEPARTMENT', 'CATEGORY');
        END IF;

--     elseif (TG_TABLE_NAME = 'ticket_description') then
--         IF (TG_OP = 'INSERT') then
--             INSERT INTO documents_search (ticket_id, document_text, source, desc_id)
--                 (select t.id, strip_tags(td.description), 'DESC', td.id
--                  from ticket t
--                           join ticket_description td on td.ticket_id = t.id
--                  where td.description is not null
--                    and td.id = new.id);
--             UPDATE documents_search d1
--             SET document_tokens = to_tsvector(d1.document_text)
--             FROM documents_search d2
--                      join ticket_description td on td.id = d2.desc_id
--             where d2.document_tokens is null
--               and td.id = new.id
--               and source in ('DESC');
--         ELSIF (TG_OP = 'UPDATE') then
--             delete from documents_search s where s.desc_id = new.id and source in ('DESC');
--             INSERT INTO documents_search (ticket_id, document_text, source)
--                 (select t.id, strip_tags(td.description), 'DESC', desc_id
--                  from ticket t
--                           join ticket_description td on td.ticket_id = t.id
--                  where td.description is not null
--                    and td.id = new.id);
--             UPDATE documents_search d1
--             SET document_tokens = to_tsvector(d1.document_text)
--             FROM documents_search d2
--                      join ticket_description td on td.id = d2.desc_id
--             where d2.document_tokens is null
--               and td.id = new.id
--               and source in ('DESC');
--         END IF;
    END IF;
    RETURN NEW;
END;
$$;


--
-- Name: search_anything(text); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.search_anything(texts text) RETURNS TABLE(tid bigint, value text, sources character varying)
    LANGUAGE plpgsql
    AS $$
begin
    return query
        select ss.ticket_id as tId, ss.document_text, ss.source
        from (
                 select distinct ticket_id, document_text, source, document_tokens
                 FROM documents_search
                 WHERE document_tokens @@ to_tsquery(replace(texts, ' ', '&'))) ss
                 join ticket t on t.id = ss.ticket_id
                 join ticket_description td on td.id = t.description_id;
END
$$;


--
-- Name: search_anything_verbose(text); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.search_anything_verbose(texts text) RETURNS TABLE("createdDate" text, requestor character varying, title text, description text, "departmentName" character varying, "categoryName" character varying, assignee character varying, "assigneeEmail" character varying, "ticketId" bigint, "documentText" text, src character varying)
    LANGUAGE plpgsql
    AS $_$
begin
    return query
        select to_char(
                       t.created_date, 'yyyy-MM-dd HH:mi:ss AM'
                   )           as "createdDate",
               t.requestor,
               t.title,
               td.description,
               d.department_name,
               tc."name"       as "categoryName",
               u.screen_name   as "assignee",
               u.email_address as "assigneeEmail",
               ss.*
        from (
                 select distinct ticket_id,
                                 document_text,
                                 source
                 from documents_search
                 where document_tokens @@ to_tsquery(
                         replace($1, ' ', '&')
                     )
             ) ss
                 join ticket t on
            t.id = ss.ticket_id
                 join (
            select *
            from ticket_description td
            where created_date in (
                select mm.date
                from (
                         select max(created_date) as date,
                                td.ticket_id
                         from ticket_description td
                         where td.ticket_id in (
                             select td.ticket_id
                             from ticket_description td
                             group by td.ticket_id
                         )
                         group by td.ticket_id
                     ) mm
            )
        ) td on
            t.id = td.ticket_id
                 left join department d on
            t.department_id = d.id
                 join ticket_category tc on
            t.category = tc.id
                 left join users u on
            t.assignee = u.id;
end
$_$;


--
-- Name: ticket_report(text[], text[], text[], text[], text[], text, text, text, text, character varying); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.ticket_report(t_status text[], t_priority text[], t_category text[], t_department text[], t_assignee text[], t_created_from_date text, t_created_to_date text, t_status_update_from_date text, t_status_update_to_date text, t_case character varying) RETURNS TABLE("titleStatus" character varying, "ticketPriority" character varying, "isActive" boolean, category character varying, "categoryId" bigint, department character varying, "departmentId" integer, assignee character varying, "assigneeId" integer, "ticketCount" bigint)
    LANGUAGE plpgsql
    AS $$
begin
    return query
        select t.status          as "titleStatus",
               t.priority        as "ticketPriority",
               t.is_active       as "isActive",
               tc.name           as "category",
               tc.id             as "categoryId",
               d.department_name as "department",
               d.id              as "departmentId",
               u.screen_name     as "assignee",
               u.id              as "assigneeId",
               count(t.id)       as "ticketCount"
        from ticket t
                 join department d on d.id = t.department_id
                 join ticket_category tc on tc.id = t.category
                 left join users u on u.id = t.assignee
        where case when t_status = '{-1}' then true else t.status in (select unnest(t_status :: text[])) end
          and case when t_priority = '{-1}' then true else t.priority in (select unnest(t_priority :: text[])) end
          and case when t_category = '{0}' then true else t.category::text in (select unnest(t_category :: text[])) end
          and case
                  when t_department = '{0}' then true
                  else t.department_id ::text in (select unnest(t_department :: text[]))
            end
          and case
                  when t_case = 'ALL' then true
                  when t_case = 'ASSIGNED_ONLY' then t.assignee is not null
                  when t_case = 'UNASSIGNED' then t.assignee is null
                  when t_case = 'BOTH' then t.assignee is null or
                                            t.assignee::text IN (SELECT unnest(t_assignee::text[]))
                  else t.assignee::text IN (SELECT unnest(t_assignee::text[]))
            end
          and case
                  when t_created_from_date = '0000-00-00' then true
                  else to_char(t.created_date, 'yyyy-mm-dd') between t_created_from_date and t_created_to_date end
          and case
                  when t_status_update_from_date = '0000-00-00' then true
                  else to_char(t.status_update_date_time, 'yyyy-mm-dd') between t_status_update_from_date and t_status_update_to_date end
          and not t.is_merge
          and t.is_active
        group by t.status, t.priority, t.is_active, tc.name, d.department_name, u.screen_name, u.id, tc.id, d.id
        order by status;
END

$$;


--
-- Name: ticket_report(character varying, character varying, text[], character varying, text[], bigint, character varying, character varying, character varying, character varying, bigint, bigint[], character varying, bigint[], character varying, bigint[]); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.ticket_report(requester character varying, priorityfilter character varying, prioritylist text[], statusfilter character varying, statuslist text[], assigneeid bigint, fromdate character varying, todate character varying, duefromdate character varying, duetodate character varying, userid bigint, departmentid bigint[], dynamicfieldvalueid character varying, dynamicfieldvalueidlist bigint[], dynamicfieldid character varying, dynamicfieldvidlist bigint[]) RETURNS TABLE("titleStatus" character varying, "ticketPriority" character varying, "isActive" boolean, category character varying, "categoryId" bigint, department character varying, "departmentId" integer, assignee character varying, "assigneeId" integer, "ticketCount" bigint)
    LANGUAGE plpgsql
    AS $$
begin
return query
select t.status          as "titleStatus",
       t.priority        as "ticketPriority",
       t.is_active       as "isActive",
       tc.name           as "category",
       tc.id             as "categoryId",
       d.department_name as "department",
       d.id              as "departmentId",
       u.screen_name     as "assignee",
       u.id              as "assigneeId",
       count(t.id)       as "ticketCount"
from ticket t
         inner join ticket_category tc
                    on tc.id = t.category
         join requester r on r.id = t.requester_id
         left join users u on u.id = t.assignee
         left join notes n on n.description_id = t.description_id
         left join notes_user_mapping num on n.id = num.notes_id
         join ticket_visibility tv ON t.department_id = tv.department_id
         left join users_department_mapping udm on udm.department_id = tv.department_id and udm.user_id = userId
         left join ticket_collaborator tco on tco.ticket_id = t.id
         left join dynamic_field_ticket_value_mapping dftvm on dftvm.ticket_id = t.id
where case
          when requester = '-1'
              then true
          else r.name ilike concat('%', requester, '%') end
  and case
          when priorityFilter = 'ALL' then true
          else t.priority in (priorityList) end
  and case when statusFilter = 'ALL' then t.status not in ('RESOLVED', 'CLOSED') else t.status in (statusList) end
  and case
          when assigneeId = -1
              then t.assignee is null
          when assigneeId = 0 then true
          else t.assignee = assigneeId end
  and case
          when fromDate = '0000-00-00'
              then true
          else to_char(t.created_date, 'yyyy-MM-dd')
              between fromDate and toDate end
  and case
          when dueFromDate = '0000-00-00' then true
          else to_char(t.due_date, 'yyyy-MM-dd')
              between dueFromDate and dueToDate end
  and ((tv.visible_to_name = 'PUBLIC') OR
       (((tv.visible_to_name = 'COLLABORATOR' and udm.is_collaborator = true) or tco.collaborator_id = userId)) OR
       (tv.visible_to_name = 'ALL_USER_OF_DEPARTMENT' and udm.department_id = t.department_id) and
       t.department_id IN (departmentId) OR
       (tv.visible_to_name = 'ASSIGNEE' AND t.assignee = userId))
  and t.department_id in (departmentId)
  and (t.is_merge is false or t.is_merge is null)
  and case when dynamicFieldValueId = '-1' then true else dftvm.dynamic_field_value_id in (dynamicFieldValueIdList) end
  and case when dynamicFieldId = '-1' then true else dftvm.dynamic_filed_id in (dynamicFieldVIdList) end
group by t.status, t.priority, t.is_active, tc.name, d.department_name, u.screen_name, u.id, tc.id, d.id
order by status;
END
$$;


--
-- Name: update_message_state(bigint, text); Type: FUNCTION; Schema: fms_bhasika; Owner: -
--

CREATE FUNCTION fms_bhasika.update_message_state(p_recipient_detail_id bigint, p_message_state text) RETURNS boolean
    LANGUAGE plpgsql
    AS $$
DECLARE
updated_rows integer;
BEGIN
WITH messages_selected AS (SELECT em.id id, em.message_state as state
                           FROM recipient_detail_group rdg
                                    JOIN external_message em ON em.recipient_detail_id = rdg.messenger_id
                               OR em.recipient_detail_id = rdg.viber_id
                               OR em.recipient_detail_id = rdg.whatsapp_id
                           WHERE rdg.messenger_id = p_recipient_detail_id
                              OR rdg.viber_id = p_recipient_detail_id
                              OR rdg.whatsapp_id = p_recipient_detail_id)
UPDATE external_message em
SET message_state = p_message_state FROM messages_selected
WHERE messages_selected.state = 'NEW'
  AND messages_selected.id = em.id
    RETURNING em.id
INTO updated_rows;
IF
updated_rows > 0 THEN
    RETURN true;
ELSE
    RETURN false;
END IF;
END;
$$;


--
-- Name: authorities_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.authorities_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;




--
-- Name: authority; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.authority (
    id bigint NOT NULL,
    authority_name character varying(255) NOT NULL,
    is_create boolean DEFAULT true,
    is_delete boolean DEFAULT true,
    is_udpate boolean DEFAULT true,
    is_view boolean DEFAULT true,
    department_id bigint NOT NULL
);


--
-- Name: bulk_email_log; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.bulk_email_log (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    attachment_path text,
    bcc_email text,
    cc_email text,
    context text,
    subject character varying(255),
    to_email text
);


--
-- Name: bulk_email_log_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.bulk_email_log_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: can_response; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.can_response (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    assignee bigint,
    attachments character varying(255),
    carbon_email_ids text,
    description text,
    priority character varying(255),
    response_name character varying(255) NOT NULL,
    response_type character varying(255) NOT NULL,
    status character varying(255),
    title text,
    category bigint
);


--
-- Name: can_response_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.can_response_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: company; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.company (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    address character varying(255),
    company_code character varying(255) NOT NULL,
    company_logo character varying(255),
    company_message character varying(255),
    company_name character varying(255) NOT NULL,
    contact_number character varying(255),
    contact_person character varying(255),
    description character varying(255),
    email_address character varying(255) NOT NULL,
    location character varying(255),
    description_id bigint NOT NULL
);


--
-- Name: company_description; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.company_description (
    id bigint NOT NULL,
    expiration_date date NOT NULL,
    is_expired boolean DEFAULT false,
    subscription_date date NOT NULL,
    subscription_plan_type character varying(255) NOT NULL
);


--
-- Name: company_description_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.company_description_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: company_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.company_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: company_token; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.company_token (
    sms_api_key character varying(255) NOT NULL
);


--
-- Name: company_token_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.company_token_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: department; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.department (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    department_name character varying(255),
    description character varying(255),
    is_default boolean DEFAULT false
);


--
-- Name: department_menu_mapping; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.department_menu_mapping (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    is_default boolean DEFAULT true,
    department_id bigint,
    menu_id bigint
);


--
-- Name: department_menu_mapping_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.department_menu_mapping_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: department_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.department_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: documents_search; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.documents_search (
    document_id integer NOT NULL,
    document_text text,
    ticket_id bigint NOT NULL,
    source character varying(20),
    document_tokens tsvector,
    desc_id bigint
);


--
-- Name: documents_search_document_id_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.documents_search_document_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: documents_search_document_id_seq; Type: SEQUENCE OWNED BY; Schema: fms_bhasika; Owner: -
--

ALTER SEQUENCE fms_bhasika.documents_search_document_id_seq OWNED BY fms_bhasika.documents_search.document_id;


--
-- Name: dynamic_field; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.dynamic_field (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    department_id bigint,
    is_required boolean,
    is_searchable boolean,
    label character varying(255) NOT NULL,
    field_type_id bigint NOT NULL
);


--
-- Name: dynamic_field_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.dynamic_field_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: dynamic_field_ticket_value; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.dynamic_field_ticket_value (
    ticket_id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    dynamic_field_value jsonb NOT NULL
);


--
-- Name: dynamic_field_ticket_value_mapping; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.dynamic_field_ticket_value_mapping (
    id bigint NOT NULL,
    dynamic_filed_id bigint NOT NULL,
    dynamic_field_value_id bigint NOT NULL,
    ticket_id bigint NOT NULL
);


--
-- Name: dynamic_field_ticket_value_mapping_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.dynamic_field_ticket_value_mapping_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: dynamic_field_type; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.dynamic_field_type (
    id bigint NOT NULL,
    has_child boolean,
    name character varying(255) NOT NULL
);


--
-- Name: dynamic_field_type_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.dynamic_field_type_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: dynamic_field_type_value; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.dynamic_field_type_value (
    id bigint NOT NULL,
    value character varying(255) NOT NULL,
    dynamice_field_id bigint NOT NULL
);


--
-- Name: dynamic_field_type_value_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.dynamic_field_type_value_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: dynamic_ticket_form; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.dynamic_ticket_form (
    id integer NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    form_json text,
    form_type character varying(255),
    title character varying(255),
    company_id bigint
);


--
-- Name: dynamic_ticket_form_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.dynamic_ticket_form_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: external_message; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.external_message (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    contains_attachments boolean,
    message text,
    message_state character varying(255),
    mode character varying(255),
    recipient_detail_id bigint
);


--
-- Name: external_message_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.external_message_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: flyway_schema_history; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.flyway_schema_history (
    installed_rank integer NOT NULL,
    version character varying(50),
    description character varying(200) NOT NULL,
    type character varying(20) NOT NULL,
    script character varying(1000) NOT NULL,
    checksum integer,
    installed_by character varying(100) NOT NULL,
    installed_on timestamp without time zone DEFAULT now() NOT NULL,
    execution_time integer NOT NULL,
    success boolean NOT NULL
);


--
-- Name: fms_activity_log; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.fms_activity_log (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    action_type character varying(255),
    additional_info character varying(255),
    cc text,
    message character varying(255),
    module character varying(255) NOT NULL,
    related_user_email character varying(255),
    related_user_id character varying(255),
    ticket_id bigint
);


--
-- Name: fms_activity_log_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.fms_activity_log_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: forward; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.forward (
    id bigint NOT NULL,
    carbon_email_ids text,
    to_email_id text,
    ticket_id bigint,
    description_id bigint
);


--
-- Name: internal_message_attachment; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.internal_message_attachment (
    id bigint NOT NULL,
    attachment_location text,
    attachment_name character varying,
    attachment_size double precision
);


--
-- Name: mail_properties; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.mail_properties (
    company_id bigint NOT NULL,
    host character varying(255),
    password character varying(255),
    port integer NOT NULL,
    uri character varying(255),
    username character varying(255)
);


--
-- Name: menu; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.menu (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    can_edit boolean DEFAULT true,
    description character varying(255),
    menu_name character varying(255) NOT NULL,
    role_type character varying(255)
);


--
-- Name: menu_group; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.menu_group (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    menu_id bigint,
    menu_name character varying(255),
    parent_id bigint
);


--
-- Name: menu_group_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.menu_group_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: menu_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.menu_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: merged_ticket; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.merged_ticket (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    last_merged_to_ticket_id bigint,
    last_parent_description_id bigint,
    merged_by bigint,
    merged_ticket bigint,
    merged_ticket_code character varying(255),
    ticket_id bigint
);


--
-- Name: merged_ticket_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.merged_ticket_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: message_attachment; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.message_attachment (
    id bigint NOT NULL,
    attachment_location text,
    attachment_name character varying,
    attachment_size double precision,
    message_id bigint
);


--
-- Name: message_attachments_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.message_attachments_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: notes; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.notes (
    id bigint NOT NULL,
    is_reminder boolean DEFAULT false,
    ticket_id bigint,
    description_id bigint
);


--
-- Name: notes_user_mapping; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.notes_user_mapping (
    notes_id bigint NOT NULL,
    user_id bigint NOT NULL
);


--
-- Name: oauth_access_token; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.oauth_access_token (
    token_id character varying(256),
    token bytea,
    authentication_id character varying(256),
    user_name character varying(256),
    client_id character varying(256),
    authentication bytea,
    refresh_token character varying(256)
);


--
-- Name: oauth_approvals; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.oauth_approvals (
    userid character varying(256),
    clientid character varying(256),
    scope character varying(256),
    status character varying(10),
    expiresat timestamp without time zone,
    lastmodifiedat timestamp without time zone
);


--
-- Name: oauth_client_details; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.oauth_client_details (
    client_id character varying(256) NOT NULL,
    resource_ids character varying(256),
    client_secret character varying(256),
    scope character varying(256),
    authorized_grant_types character varying(256),
    web_server_redirect_uri character varying(256),
    authorities character varying(256),
    access_token_validity integer,
    refresh_token_validity integer,
    additional_information character varying(4096),
    autoapprove character varying(256)
);


--
-- Name: oauth_client_token; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.oauth_client_token (
    token_id character varying(256),
    token bytea,
    authentication_id character varying(256),
    user_name character varying(256),
    client_id character varying(256)
);


--
-- Name: oauth_code; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.oauth_code (
    code character varying(256),
    authentication bytea
);


--
-- Name: oauth_refresh_token; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.oauth_refresh_token (
    token_id character varying(256),
    token bytea,
    authentication bytea
);


--
-- Name: password_reset_token; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.password_reset_token (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    expiry_date timestamp without time zone,
    status integer,
    token character varying(40),
    user_id bigint
);


--
-- Name: password_reset_token_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.password_reset_token_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: recipient_detail; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.recipient_detail (
    id bigint NOT NULL,
    email character varying(255),
    latest_message_id bigint,
    message_date_time timestamp without time zone,
    recipient character varying(255),
    recipient_name character varying(255),
    source character varying(255),
    source_id character varying(255)
);


--
-- Name: recipient_detail_group; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.recipient_detail_group (
    id bigint NOT NULL,
    display_name character varying(255),
    email character varying(255),
    messenger_id bigint,
    viber_id bigint,
    whatsapp_id bigint
);


--
-- Name: recipient_detail_group_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.recipient_detail_group_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: recipient_detail_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.recipient_detail_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: recipient_group_mapping; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.recipient_group_mapping (
    id bigint NOT NULL,
    recipient_detail_id bigint,
    recipient_detail_group_id bigint
);


--
-- Name: recipient_group_mapping_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.recipient_group_mapping_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: reply; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.reply (
    id bigint NOT NULL,
    carbon_email_ids text,
    to_email_id text,
    ticket_id bigint NOT NULL,
    description_id bigint NOT NULL
);


--
-- Name: requester; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.requester (
    id bigint NOT NULL,
    email character varying(255) NOT NULL,
    mobile_no character varying(255),
    name character varying(255)
);


--
-- Name: requester_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.requester_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: response_email_content; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.response_email_content (
    id bigint NOT NULL,
    cc_email text,
    description_id bigint,
    from_email character varying(255),
    from_name character varying(255),
    subject character varying(255),
    to_email text
);


--
-- Name: response_email_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.response_email_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: sms; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.sms (
    id bigint NOT NULL,
    to_phone_numbers text,
    ticket_id bigint NOT NULL,
    description_id bigint NOT NULL
);


--
-- Name: temporary_attachments; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.temporary_attachments (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    file_size double precision,
    location character varying(255),
    name character varying(255)
);


--
-- Name: temporary_attachments_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.temporary_attachments_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    carbon_email_ids text,
    department_id bigint,
    due_date date,
    is_merge boolean DEFAULT false,
    priority character varying(255),
    status character varying(255),
    status_update_date_time timestamp without time zone,
    ticket_id character varying(10),
    ticket_state character varying(255),
    title text NOT NULL,
    assignee bigint,
    category bigint,
    description_id bigint,
    requester_id bigint
);


--
-- Name: ticket_attachments; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket_attachments (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    attachment_location text,
    attachment_name character varying,
    attachment_size double precision,
    description_id bigint
);


--
-- Name: ticket_attachments_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_attachments_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_category; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket_category (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    code character varying(255),
    description character varying(255),
    due_days integer,
    name character varying(255)
);


--
-- Name: ticket_category_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_category_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_collaborator; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket_collaborator (
    ticket_id bigint NOT NULL,
    collaborator_id bigint NOT NULL
);


--
-- Name: ticket_description; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket_description (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    contains_attachment boolean DEFAULT false,
    description text,
    is_draft boolean DEFAULT false,
    table_name character varying(200),
    ticket_id bigint
);


--
-- Name: ticket_description_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_description_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_forward_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_forward_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_notes_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_notes_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_reminder; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket_reminder (
    id bigint NOT NULL,
    reminder_date timestamp without time zone,
    reminder_status character varying(255),
    reminder_text text,
    status_changed_by_user_id bigint,
    ticket_id bigint,
    description_id bigint
);


--
-- Name: ticket_reminder_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_reminder_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_reply_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_reply_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_sms_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_sms_gen
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: ticket_visibility; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.ticket_visibility (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    department_id bigint,
    visible_to_id integer,
    visible_to_name character varying(255)
);


--
-- Name: ticket_visibility_gen; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.ticket_visibility_gen
    START WITH 1
    INCREMENT BY 50
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: user_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.user_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: users; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.users (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    account_non_locked boolean DEFAULT true,
    email_address character varying(255),
    first_name character varying(255) NOT NULL,
    is_email_address_verified boolean,
    last_name character varying(255),
    login_ip character varying(255),
    middle_name character varying(255),
    password character varying(255),
    screen_name character varying(255),
    signature text,
    user_type character varying(255),
    company_id bigint
);


--
-- Name: users_department_mapping; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.users_department_mapping (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    is_assignee boolean DEFAULT true,
    is_collaborator boolean DEFAULT false,
    is_default boolean DEFAULT false,
    department_id bigint,
    user_id bigint
);


--
-- Name: users_department_mapping_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.users_department_mapping_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: users_menu_mapping; Type: TABLE; Schema: fms_bhasika; Owner: -
--

CREATE TABLE fms_bhasika.users_menu_mapping (
    id bigint NOT NULL,
    created_date timestamp without time zone,
    last_modified_date timestamp without time zone,
    created_by bigint,
    last_modified_by bigint,
    is_active boolean,
    is_default boolean DEFAULT true,
    menu_id bigint,
    user_id bigint
);


--
-- Name: users_menu_mapping_seq; Type: SEQUENCE; Schema: fms_bhasika; Owner: -
--

CREATE SEQUENCE fms_bhasika.users_menu_mapping_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: documents_search document_id; Type: DEFAULT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.documents_search ALTER COLUMN document_id SET DEFAULT nextval('fms_bhasika.documents_search_document_id_seq'::regclass);


--
-- Data for Name: authority; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.authority (id, authority_name, is_create, is_delete, is_udpate, is_view, department_id) FROM stdin;
\.


--
-- Data for Name: bulk_email_log; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.bulk_email_log (id, created_date, last_modified_date, created_by, last_modified_by, attachment_path, bcc_email, cc_email, context, subject, to_email) FROM stdin;
\.


--
-- Data for Name: can_response; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.can_response (id, created_date, last_modified_date, created_by, last_modified_by, is_active, assignee, attachments, carbon_email_ids, description, priority, response_name, response_type, status, title, category) FROM stdin;
\.


--
-- Data for Name: company; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.company (id, created_date, last_modified_date, created_by, last_modified_by, is_active, address, company_code, company_logo, company_message, company_name, contact_number, contact_person, description, email_address, location, description_id) FROM stdin;
1	2020-12-15 04:30:45.062	2025-02-21 22:13:18.919912	1	1	t	Kathmandu Nepal	LEAF001	/home/azureuser/projects/fms-prod-multitenant/documents/fms/1/company/logo/2025-02-21/1740155295149-5655450a-360f-4af7-9aca-f6257a304fcc.jpg	\N	Leaf Education	9844443863	Leaf Education	<p>It is an it company</p>	leafadmin@gmail.com		1
\.


--
-- Data for Name: company_description; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.company_description (id, expiration_date, is_expired, subscription_date, subscription_plan_type) FROM stdin;
1	2029-02-10	f	2025-02-20	FREE_TIRE
\.


--
-- Data for Name: company_token; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.company_token (sms_api_key) FROM stdin;
\.


--
-- Data for Name: department; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.department (id, created_date, last_modified_date, created_by, last_modified_by, is_active, department_name, description, is_default) FROM stdin;
1	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	Front Desk	This department is the default department and all the tickets created will land here eventually	t
\.


--
-- Data for Name: department_menu_mapping; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.department_menu_mapping (id, created_date, last_modified_date, created_by, last_modified_by, is_active, is_default, department_id, menu_id) FROM stdin;
\.


--
-- Data for Name: documents_search; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.documents_search (document_id, document_text, ticket_id, source, document_tokens, desc_id) FROM stdin;
\.


--
-- Data for Name: dynamic_field; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.dynamic_field (id, created_date, last_modified_date, created_by, last_modified_by, is_active, department_id, is_required, is_searchable, label, field_type_id) FROM stdin;
\.


--
-- Data for Name: dynamic_field_ticket_value; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.dynamic_field_ticket_value (ticket_id, created_date, last_modified_date, created_by, last_modified_by, is_active, dynamic_field_value) FROM stdin;
\.


--
-- Data for Name: dynamic_field_ticket_value_mapping; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.dynamic_field_ticket_value_mapping (id, dynamic_filed_id, dynamic_field_value_id, ticket_id) FROM stdin;
\.


--
-- Data for Name: dynamic_field_type; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.dynamic_field_type (id, has_child, name) FROM stdin;
\.


--
-- Data for Name: dynamic_field_type_value; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.dynamic_field_type_value (id, value, dynamice_field_id) FROM stdin;
\.


--
-- Data for Name: dynamic_ticket_form; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.dynamic_ticket_form (id, created_date, last_modified_date, created_by, last_modified_by, is_active, form_json, form_type, title, company_id) FROM stdin;
\.


--
-- Data for Name: external_message; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.external_message (id, created_date, last_modified_date, created_by, last_modified_by, contains_attachments, message, message_state, mode, recipient_detail_id) FROM stdin;
\.


--
-- Data for Name: flyway_schema_history; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.flyway_schema_history (installed_rank, version, description, type, script, checksum, installed_by, installed_on, execution_time, success) FROM stdin;
1	1	search anything	SQL	V1__search_anything.sql	-268915607	postgres	2025-02-19 16:11:08.34171	39	t
2	2	search anything verbose	SQL	V2__search_anything_verbose.sql	-1941906463	postgres	2025-02-19 16:11:08.416614	10	t
3	3	testFunction	SQL	V3__testFunction.sql	-277469015	postgres	2025-02-19 16:11:08.445578	2	t
4	4	weekly ticket report	SQL	V4__weekly_ticket_report.sql	-337987346	postgres	2025-02-19 16:11:08.461139	5	t
5	5	trigger ticket insert update 	SQL	V5__trigger_ticket_insert_update_.sql	-2045488485	postgres	2025-02-19 16:14:43.088697	55	t
6	6	get recepient detail individual group	SQL	V6__get_recepient_detail_individual_group.sql	1385230288	postgres	2025-02-19 16:14:43.166758	4	t
7	7	get all recepients with single msg	SQL	V7__get_all_recepients_with_single_msg.sql	-80981930	postgres	2025-02-19 16:14:43.185814	4	t
8	8	update message state	SQL	V8__update_message_state.sql	-1008570335	postgres	2025-02-19 16:14:43.199798	3	t
9	9	report	SQL	V9__report.sql	-599367850	postgres	2025-02-19 16:14:43.215948	11	t
10	9.1	report	SQL	V9.1__report.sql	-512511353	postgres	2025-02-19 16:14:43.2423	7	t
11	10	get ticket activity	SQL	V10__get_ticket_activity.sql	-716444698	postgres	2025-02-19 16:14:43.262348	6	t
12	11	get ticket activity updated	SQL	V11__get_ticket_activity_updated.sql	1764934642	postgres	2025-02-19 16:14:43.282258	3	t
\.


--
-- Data for Name: fms_activity_log; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.fms_activity_log (id, created_date, last_modified_date, created_by, last_modified_by, action_type, additional_info, cc, message, module, related_user_email, related_user_id, ticket_id) FROM stdin;
\.


--
-- Data for Name: forward; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.forward (id, carbon_email_ids, to_email_id, ticket_id, description_id) FROM stdin;
\.


--
-- Data for Name: internal_message_attachment; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.internal_message_attachment (id, attachment_location, attachment_name, attachment_size) FROM stdin;
\.


--
-- Data for Name: mail_properties; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.mail_properties (company_id, host, password, port, uri, username) FROM stdin;
\.


--
-- Data for Name: menu; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.menu (id, created_date, last_modified_date, created_by, last_modified_by, is_active, can_edit, description, menu_name, role_type) FROM stdin;
16	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the notes details.	Add Note	INTERNAL
22	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the authority details.	Authority	INTERNAL
24	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	Description for bulk email control	Bulk Email	INTERNAL
9	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of category.	Category	INTERNAL
7	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of chat.	Chat	INTERNAL
10	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of company.	Company	INTERNAL
20	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves to delete the details.	Delete	INTERNAL
11	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of department.	Department	INTERNAL
19	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the dyanamic field details.	Dynamic Field	INTERNAL
14	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the reply details.	Forward	INTERNAL
18	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the general department details.	General 	INTERNAL
3	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This get method menu serves to get the data from the system.	Get	INTERNAL
1	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves home details of the system.	Home	INTERNAL
6	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of menu.	Menu	INTERNAL
21	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the ticket to merge.	Merge	INTERNAL
4	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This post method menu serves to post the data.	Post	INTERNAL
23	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of fms_bhasika tickets.	Public Ticket	INTERNAL
12	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of quick response.	Quick Response	INTERNAL
17	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the reminder details.	Reminder	INTERNAL
13	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the reply details.	Reply	INTERNAL
8	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the details of report.	Report	INTERNAL
15	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the sms details.	SMS	INTERNAL
2	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This menu serves the ticket details of the system.	Ticket	INTERNAL
5	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	This users menu serves the details of users.	Users	INTERNAL
\.


--
-- Data for Name: menu_group; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.menu_group (id, created_date, last_modified_date, created_by, last_modified_by, is_active, menu_id, menu_name, parent_id) FROM stdin;
6	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	16	Add Note	1
7	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	22	Authority	2
8	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	9	Category	2
9	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	7	Chat	5
10	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	10	Company	2
11	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	20	Delete	3
12	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	11	Department	2
4	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	\N	Department Field	\N
13	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	19	Dynamic Field	4
14	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	14	Forward	1
15	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	18	General 	4
16	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	3	Get	3
17	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	1	Home	5
5	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	\N	Main Menu	\N
18	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	6	Menu	2
19	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	21	Merge	1
3	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	\N	Method	\N
20	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	4	Post	3
21	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	4	Post	3
22	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	4	4	t	23	Public Ticket	2
23	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	12	Quick Response	2
24	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	17	Reminder	1
25	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	17	Reminder	1
26	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	13	Reply	1
27	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	8	Report	5
28	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	15	SMS	1
2	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	\N	Settings	\N
1	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	\N	Ticket	\N
29	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	2	Ticket	5
30	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	5	Users	2
\.


--
-- Data for Name: merged_ticket; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.merged_ticket (id, created_date, last_modified_date, created_by, last_modified_by, is_active, last_merged_to_ticket_id, last_parent_description_id, merged_by, merged_ticket, merged_ticket_code, ticket_id) FROM stdin;
\.


--
-- Data for Name: message_attachment; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.message_attachment (id, attachment_location, attachment_name, attachment_size, message_id) FROM stdin;
\.


--
-- Data for Name: notes; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.notes (id, is_reminder, ticket_id, description_id) FROM stdin;
\.


--
-- Data for Name: notes_user_mapping; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.notes_user_mapping (notes_id, user_id) FROM stdin;
\.


--
-- Data for Name: oauth_access_token; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.oauth_access_token (token_id, token, authentication_id, user_name, client_id, authentication, refresh_token) FROM stdin;
\.


--
-- Data for Name: oauth_approvals; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.oauth_approvals (userid, clientid, scope, status, expiresat, lastmodifiedat) FROM stdin;
\.


--
-- Data for Name: oauth_client_details; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.oauth_client_details (client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove) FROM stdin;
clientId	\N	{bcrypt}$2a$10$vCXMWCn7fDZWOcLnIEhmK.74dvK1Eh8ae2WrWlhr2ETPLoxQctN4.	read,write	password,refresh_token,client_credentials	\N	ROLE_CLIENT	3600000	\N	\N	\N
\.


--
-- Data for Name: oauth_client_token; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.oauth_client_token (token_id, token, authentication_id, user_name, client_id) FROM stdin;
\.


--
-- Data for Name: oauth_code; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.oauth_code (code, authentication) FROM stdin;
\.


--
-- Data for Name: oauth_refresh_token; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.oauth_refresh_token (token_id, token, authentication) FROM stdin;
\.


--
-- Data for Name: password_reset_token; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.password_reset_token (id, created_date, last_modified_date, created_by, last_modified_by, is_active, expiry_date, status, token, user_id) FROM stdin;
1	2025-02-21 22:41:45.938068	2025-02-21 22:41:45.938068	\N	\N	t	2025-02-23 22:41:45.92711	1	96fa5b0a-69e9-4d89-aa9e-4496a2a89382	1
\.


--
-- Data for Name: recipient_detail; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.recipient_detail (id, email, latest_message_id, message_date_time, recipient, recipient_name, source, source_id) FROM stdin;
\.


--
-- Data for Name: recipient_detail_group; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.recipient_detail_group (id, display_name, email, messenger_id, viber_id, whatsapp_id) FROM stdin;
\.


--
-- Data for Name: recipient_group_mapping; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.recipient_group_mapping (id, recipient_detail_id, recipient_detail_group_id) FROM stdin;
\.


--
-- Data for Name: reply; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.reply (id, carbon_email_ids, to_email_id, ticket_id, description_id) FROM stdin;
\.


--
-- Data for Name: requester; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.requester (id, email, mobile_no, name) FROM stdin;
\.


--
-- Data for Name: response_email_content; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.response_email_content (id, cc_email, description_id, from_email, from_name, subject, to_email) FROM stdin;
\.


--
-- Data for Name: sms; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.sms (id, to_phone_numbers, ticket_id, description_id) FROM stdin;
\.


--
-- Data for Name: temporary_attachments; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.temporary_attachments (id, created_date, last_modified_date, created_by, last_modified_by, is_active, file_size, location, name) FROM stdin;
1	2025-02-21 22:13:15.223827	2025-02-21 22:13:15.223827	1	1	t	0.04040050506591797	/home/azureuser/projects/fms-prod-multitenant/tempDocument/doc/1740155295149-5655450a-360f-4af7-9aca-f6257a304fcc.jpg	leaf education.jpg
\.


--
-- Data for Name: ticket; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket (id, created_date, last_modified_date, created_by, last_modified_by, is_active, carbon_email_ids, department_id, due_date, is_merge, priority, status, status_update_date_time, ticket_id, ticket_state, title, assignee, category, description_id, requester_id) FROM stdin;
\.


--
-- Data for Name: ticket_attachments; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket_attachments (id, created_date, last_modified_date, created_by, last_modified_by, is_active, attachment_location, attachment_name, attachment_size, description_id) FROM stdin;
\.


--
-- Data for Name: ticket_category; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket_category (id, created_date, last_modified_date, created_by, last_modified_by, is_active, code, description, due_days, name) FROM stdin;
\.


--
-- Data for Name: ticket_collaborator; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket_collaborator (ticket_id, collaborator_id) FROM stdin;
\.


--
-- Data for Name: ticket_description; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket_description (id, created_date, last_modified_date, created_by, last_modified_by, is_active, contains_attachment, description, is_draft, table_name, ticket_id) FROM stdin;
\.


--
-- Data for Name: ticket_reminder; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket_reminder (id, reminder_date, reminder_status, reminder_text, status_changed_by_user_id, ticket_id, description_id) FROM stdin;
\.


--
-- Data for Name: ticket_visibility; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.ticket_visibility (id, created_date, last_modified_date, created_by, last_modified_by, is_active, department_id, visible_to_id, visible_to_name) FROM stdin;
\.


--
-- Data for Name: users; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.users (id, created_date, last_modified_date, created_by, last_modified_by, is_active, account_non_locked, email_address, first_name, is_email_address_verified, last_name, login_ip, middle_name, password, screen_name, signature, user_type, company_id) FROM stdin;
1	2025-02-20 10:31:10.251	2025-02-20 10:31:10.251	0	0	t	t	leafadmin@gmail.com	Leaf	f	Admin	\N	\N	{bcrypt}$2a$10$v0IAoOWUaeqfJ7SXPnDjIuUobaZfk/F2H3Z7g9SDPJUF1YtYTd2Yq	Leaf	\N	INTERNAL	1
\.


--
-- Data for Name: users_department_mapping; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.users_department_mapping (id, created_date, last_modified_date, created_by, last_modified_by, is_active, is_assignee, is_collaborator, is_default, department_id, user_id) FROM stdin;
1	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	f	t	1	1
\.


--
-- Data for Name: users_menu_mapping; Type: TABLE DATA; Schema: fms_bhasika; Owner: -
--

COPY fms_bhasika.users_menu_mapping (id, created_date, last_modified_date, created_by, last_modified_by, is_active, is_default, menu_id, user_id) FROM stdin;
2	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	1	1
3	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	2	1
4	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	3	1
5	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	4	1
6	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	5	1
7	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	6	1
8	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	7	1
9	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	8	1
10	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	9	1
11	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	10	1
12	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	11	1
13	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	12	1
14	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	13	1
15	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	14	1
16	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	15	1
17	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	16	1
18	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	17	1
19	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	18	1
20	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	19	1
21	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	20	1
22	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	21	1
23	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	22	1
24	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	23	1
25	2025-02-21 22:55:55.703	2025-02-21 22:55:55.703	1	1	t	t	24	1
\.


--
-- Name: authorities_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.authorities_seq', 1, false);


--
-- Name: bulk_email_log_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.bulk_email_log_seq', 1, false);


--
-- Name: can_response_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.can_response_seq', 1, false);


--
-- Name: company_description_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.company_description_seq', 1, false);


--
-- Name: company_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.company_seq', 1, false);


--
-- Name: company_token_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.company_token_seq', 1, false);


--
-- Name: department_menu_mapping_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.department_menu_mapping_seq', 1, false);


--
-- Name: department_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.department_seq', 1, true);


--
-- Name: documents_search_document_id_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.documents_search_document_id_seq', 1, false);


--
-- Name: dynamic_field_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.dynamic_field_seq', 1, false);


--
-- Name: dynamic_field_ticket_value_mapping_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.dynamic_field_ticket_value_mapping_seq', 1, false);


--
-- Name: dynamic_field_type_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.dynamic_field_type_seq', 1, false);


--
-- Name: dynamic_field_type_value_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.dynamic_field_type_value_seq', 1, false);


--
-- Name: dynamic_ticket_form_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.dynamic_ticket_form_seq', 1, false);


--
-- Name: external_message_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.external_message_seq', 1, false);


--
-- Name: fms_activity_log_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.fms_activity_log_seq', 1, false);


--
-- Name: menu_group_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.menu_group_seq', 30, true);


--
-- Name: menu_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.menu_seq', 24, true);


--
-- Name: merged_ticket_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.merged_ticket_gen', 1, false);


--
-- Name: message_attachments_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.message_attachments_gen', 1, false);


--
-- Name: password_reset_token_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.password_reset_token_seq', 1, true);


--
-- Name: recipient_detail_group_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.recipient_detail_group_seq', 1, false);


--
-- Name: recipient_detail_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.recipient_detail_seq', 1, false);


--
-- Name: recipient_group_mapping_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.recipient_group_mapping_seq', 1, false);


--
-- Name: requester_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.requester_seq', 1, false);


--
-- Name: response_email_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.response_email_seq', 1, false);


--
-- Name: temporary_attachments_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.temporary_attachments_gen', 1, true);


--
-- Name: ticket_attachments_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_attachments_gen', 1, false);


--
-- Name: ticket_category_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_category_gen', 1, false);


--
-- Name: ticket_description_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_description_gen', 1, false);


--
-- Name: ticket_forward_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_forward_gen', 1, false);


--
-- Name: ticket_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_gen', 1, false);


--
-- Name: ticket_notes_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_notes_gen', 1, false);


--
-- Name: ticket_reminder_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_reminder_gen', 1, false);


--
-- Name: ticket_reply_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_reply_gen', 1, false);


--
-- Name: ticket_sms_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_sms_gen', 1, false);


--
-- Name: ticket_visibility_gen; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.ticket_visibility_gen', 1, false);


--
-- Name: user_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.user_seq', 1, false);


--
-- Name: users_department_mapping_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.users_department_mapping_seq', 1, true);


--
-- Name: users_menu_mapping_seq; Type: SEQUENCE SET; Schema: fms_bhasika; Owner: -
--

SELECT pg_catalog.setval('fms_bhasika.users_menu_mapping_seq', 25, true);


--
-- Name: authority authority_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.authority
    ADD CONSTRAINT authority_pkey PRIMARY KEY (id);


--
-- Name: bulk_email_log bulk_email_log_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.bulk_email_log
    ADD CONSTRAINT bulk_email_log_pkey PRIMARY KEY (id);


--
-- Name: can_response can_response_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.can_response
    ADD CONSTRAINT can_response_pkey PRIMARY KEY (id);


--
-- Name: company_description company_description_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.company_description
    ADD CONSTRAINT company_description_pkey PRIMARY KEY (id);


--
-- Name: company company_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.company
    ADD CONSTRAINT company_pkey PRIMARY KEY (id);


--
-- Name: company_token company_token_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.company_token
    ADD CONSTRAINT company_token_pkey PRIMARY KEY (sms_api_key);


--
-- Name: department_menu_mapping department_menu_mapping_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.department_menu_mapping
    ADD CONSTRAINT department_menu_mapping_pkey PRIMARY KEY (id);


--
-- Name: department department_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.department
    ADD CONSTRAINT department_pkey PRIMARY KEY (id);


--
-- Name: documents_search documents_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.documents_search
    ADD CONSTRAINT documents_pkey PRIMARY KEY (document_id);


--
-- Name: dynamic_field dynamic_field_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field
    ADD CONSTRAINT dynamic_field_pkey PRIMARY KEY (id);


--
-- Name: dynamic_field_ticket_value_mapping dynamic_field_ticket_value_mapping_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field_ticket_value_mapping
    ADD CONSTRAINT dynamic_field_ticket_value_mapping_pkey PRIMARY KEY (id);


--
-- Name: dynamic_field_ticket_value dynamic_field_ticket_value_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field_ticket_value
    ADD CONSTRAINT dynamic_field_ticket_value_pkey PRIMARY KEY (ticket_id);


--
-- Name: dynamic_field_type dynamic_field_type_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field_type
    ADD CONSTRAINT dynamic_field_type_pkey PRIMARY KEY (id);


--
-- Name: dynamic_field_type_value dynamic_field_type_value_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field_type_value
    ADD CONSTRAINT dynamic_field_type_value_pkey PRIMARY KEY (id);


--
-- Name: dynamic_ticket_form dynamic_ticket_form_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_ticket_form
    ADD CONSTRAINT dynamic_ticket_form_pkey PRIMARY KEY (id);


--
-- Name: requester email; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.requester
    ADD CONSTRAINT email UNIQUE (email);


--
-- Name: external_message external_message_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.external_message
    ADD CONSTRAINT external_message_pkey PRIMARY KEY (id);


--
-- Name: flyway_schema_history flyway_schema_history_pk; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.flyway_schema_history
    ADD CONSTRAINT flyway_schema_history_pk PRIMARY KEY (installed_rank);


--
-- Name: fms_activity_log fms_activity_log_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.fms_activity_log
    ADD CONSTRAINT fms_activity_log_pkey PRIMARY KEY (id);


--
-- Name: forward forward_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.forward
    ADD CONSTRAINT forward_pkey PRIMARY KEY (id);


--
-- Name: internal_message_attachment internal_message_attachment_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.internal_message_attachment
    ADD CONSTRAINT internal_message_attachment_pkey PRIMARY KEY (id);


--
-- Name: mail_properties mail_properties_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.mail_properties
    ADD CONSTRAINT mail_properties_pkey PRIMARY KEY (company_id);


--
-- Name: menu_group menu_group_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.menu_group
    ADD CONSTRAINT menu_group_pkey PRIMARY KEY (id);


--
-- Name: menu menu_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.menu
    ADD CONSTRAINT menu_pkey PRIMARY KEY (id);


--
-- Name: merged_ticket merged_ticket_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.merged_ticket
    ADD CONSTRAINT merged_ticket_pkey PRIMARY KEY (id);


--
-- Name: message_attachment message_attachment_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.message_attachment
    ADD CONSTRAINT message_attachment_pkey PRIMARY KEY (id);


--
-- Name: notes notes_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.notes
    ADD CONSTRAINT notes_pkey PRIMARY KEY (id);


--
-- Name: oauth_client_details oauth_client_details_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.oauth_client_details
    ADD CONSTRAINT oauth_client_details_pkey PRIMARY KEY (client_id);


--
-- Name: password_reset_token password_reset_token_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.password_reset_token
    ADD CONSTRAINT password_reset_token_pkey PRIMARY KEY (id);


--
-- Name: recipient_detail_group recipient_detail_group_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.recipient_detail_group
    ADD CONSTRAINT recipient_detail_group_pkey PRIMARY KEY (id);


--
-- Name: recipient_detail recipient_detail_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.recipient_detail
    ADD CONSTRAINT recipient_detail_pkey PRIMARY KEY (id);


--
-- Name: recipient_group_mapping recipient_group_mapping_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.recipient_group_mapping
    ADD CONSTRAINT recipient_group_mapping_pkey PRIMARY KEY (id);


--
-- Name: reply reply_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.reply
    ADD CONSTRAINT reply_pkey PRIMARY KEY (id);


--
-- Name: requester requester_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.requester
    ADD CONSTRAINT requester_pkey PRIMARY KEY (id);


--
-- Name: response_email_content response_email_content_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.response_email_content
    ADD CONSTRAINT response_email_content_pkey PRIMARY KEY (id);


--
-- Name: sms sms_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.sms
    ADD CONSTRAINT sms_pkey PRIMARY KEY (id);


--
-- Name: temporary_attachments temporary_attachments_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.temporary_attachments
    ADD CONSTRAINT temporary_attachments_pkey PRIMARY KEY (id);


--
-- Name: ticket_attachments ticket_attachments_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_attachments
    ADD CONSTRAINT ticket_attachments_pkey PRIMARY KEY (id);


--
-- Name: ticket_category ticket_category_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_category
    ADD CONSTRAINT ticket_category_pkey PRIMARY KEY (id);


--
-- Name: ticket_description ticket_description_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_description
    ADD CONSTRAINT ticket_description_pkey PRIMARY KEY (id);


--
-- Name: ticket ticket_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket
    ADD CONSTRAINT ticket_pkey PRIMARY KEY (id);


--
-- Name: ticket_reminder ticket_reminder_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_reminder
    ADD CONSTRAINT ticket_reminder_pkey PRIMARY KEY (id);


--
-- Name: ticket_visibility ticket_visibility_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_visibility
    ADD CONSTRAINT ticket_visibility_pkey PRIMARY KEY (id);


--
-- Name: authority unique_authority_name; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.authority
    ADD CONSTRAINT unique_authority_name UNIQUE (authority_name);


--
-- Name: company unique_company_code; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.company
    ADD CONSTRAINT unique_company_code UNIQUE (company_code);


--
-- Name: company unique_company_email; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.company
    ADD CONSTRAINT unique_company_email UNIQUE (email_address);


--
-- Name: department unique_department_name; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.department
    ADD CONSTRAINT unique_department_name UNIQUE (department_name);


--
-- Name: users unique_email_address; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users
    ADD CONSTRAINT unique_email_address UNIQUE (email_address);


--
-- Name: dynamic_field_ticket_value_mapping unique_mapping_ticket_id_dynamic_filed_id; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field_ticket_value_mapping
    ADD CONSTRAINT unique_mapping_ticket_id_dynamic_filed_id UNIQUE (ticket_id, dynamic_filed_id, dynamic_field_value_id);


--
-- Name: menu unique_menu_name; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.menu
    ADD CONSTRAINT unique_menu_name UNIQUE (menu_name);


--
-- Name: ticket_category unique_name; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_category
    ADD CONSTRAINT unique_name UNIQUE (name);


--
-- Name: can_response unique_response_name; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.can_response
    ADD CONSTRAINT unique_response_name UNIQUE (response_name);


--
-- Name: users unique_screen_name; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users
    ADD CONSTRAINT unique_screen_name UNIQUE (screen_name);


--
-- Name: users_department_mapping unique_user_department; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_department_mapping
    ADD CONSTRAINT unique_user_department UNIQUE (user_id, department_id);


--
-- Name: users_menu_mapping unique_user_menu; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_menu_mapping
    ADD CONSTRAINT unique_user_menu UNIQUE (user_id, menu_id);


--
-- Name: users_department_mapping users_department_mapping_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_department_mapping
    ADD CONSTRAINT users_department_mapping_pkey PRIMARY KEY (id);


--
-- Name: users_menu_mapping users_menu_mapping_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_menu_mapping
    ADD CONSTRAINT users_menu_mapping_pkey PRIMARY KEY (id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: flyway_schema_history_s_idx; Type: INDEX; Schema: fms_bhasika; Owner: -
--

CREATE INDEX flyway_schema_history_s_idx ON fms_bhasika.flyway_schema_history USING btree (success);


--
-- Name: ticket_description ticket_description_trigger; Type: TRIGGER; Schema: fms_bhasika; Owner: -
--

CREATE TRIGGER ticket_description_trigger AFTER INSERT OR UPDATE ON fms_bhasika.ticket_description FOR EACH ROW EXECUTE FUNCTION fms_bhasika.insert_or_update_search_index();


--
-- Name: ticket ticket_trigger; Type: TRIGGER; Schema: fms_bhasika; Owner: -
--

CREATE TRIGGER ticket_trigger AFTER INSERT OR UPDATE ON fms_bhasika.ticket FOR EACH ROW EXECUTE FUNCTION fms_bhasika.insert_or_update_search_index();


--
-- Name: authority fk_authority_department; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.authority
    ADD CONSTRAINT fk_authority_department FOREIGN KEY (department_id) REFERENCES fms_bhasika.department(id);


--
-- Name: company fk_company_description; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.company
    ADD CONSTRAINT fk_company_description FOREIGN KEY (description_id) REFERENCES fms_bhasika.company_description(id);


--
-- Name: department_menu_mapping fk_department_menu; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.department_menu_mapping
    ADD CONSTRAINT fk_department_menu FOREIGN KEY (department_id) REFERENCES fms_bhasika.department(id);


--
-- Name: users_department_mapping fk_department_user; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_department_mapping
    ADD CONSTRAINT fk_department_user FOREIGN KEY (department_id) REFERENCES fms_bhasika.department(id);


--
-- Name: dynamic_field fk_dynamic_field_type; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field
    ADD CONSTRAINT fk_dynamic_field_type FOREIGN KEY (field_type_id) REFERENCES fms_bhasika.dynamic_field_type(id);


--
-- Name: dynamic_ticket_form fk_dynamic_ticket_form_company; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_ticket_form
    ADD CONSTRAINT fk_dynamic_ticket_form_company FOREIGN KEY (company_id) REFERENCES fms_bhasika.company(id);


--
-- Name: dynamic_field_type_value fk_dynamice_field_id; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.dynamic_field_type_value
    ADD CONSTRAINT fk_dynamice_field_id FOREIGN KEY (dynamice_field_id) REFERENCES fms_bhasika.dynamic_field(id);


--
-- Name: department_menu_mapping fk_menu_department; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.department_menu_mapping
    ADD CONSTRAINT fk_menu_department FOREIGN KEY (menu_id) REFERENCES fms_bhasika.menu(id);


--
-- Name: users_menu_mapping fk_menu_user; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_menu_mapping
    ADD CONSTRAINT fk_menu_user FOREIGN KEY (menu_id) REFERENCES fms_bhasika.menu(id);


--
-- Name: message_attachment fk_message_attachments_external_message; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.message_attachment
    ADD CONSTRAINT fk_message_attachments_external_message FOREIGN KEY (message_id) REFERENCES fms_bhasika.external_message(id);


--
-- Name: notes_user_mapping fk_notes_user; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.notes_user_mapping
    ADD CONSTRAINT fk_notes_user FOREIGN KEY (notes_id) REFERENCES fms_bhasika.notes(id);


--
-- Name: password_reset_token fk_password_reset_token_user; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.password_reset_token
    ADD CONSTRAINT fk_password_reset_token_user FOREIGN KEY (user_id) REFERENCES fms_bhasika.users(id);


--
-- Name: external_message fk_recipient_detail; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.external_message
    ADD CONSTRAINT fk_recipient_detail FOREIGN KEY (recipient_detail_id) REFERENCES fms_bhasika.recipient_detail(id);


--
-- Name: recipient_detail_group fk_recipient_detail; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.recipient_detail_group
    ADD CONSTRAINT fk_recipient_detail FOREIGN KEY (messenger_id) REFERENCES fms_bhasika.recipient_detail(id);


--
-- Name: recipient_group_mapping fk_recipient_detail; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.recipient_group_mapping
    ADD CONSTRAINT fk_recipient_detail FOREIGN KEY (recipient_detail_id) REFERENCES fms_bhasika.recipient_detail(id);


--
-- Name: recipient_group_mapping fk_recipient_detail_group; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.recipient_group_mapping
    ADD CONSTRAINT fk_recipient_detail_group FOREIGN KEY (recipient_detail_group_id) REFERENCES fms_bhasika.recipient_detail_group(id);


--
-- Name: reply fk_reply_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.reply
    ADD CONSTRAINT fk_reply_ticket FOREIGN KEY (ticket_id) REFERENCES fms_bhasika.ticket(id);


--
-- Name: reply fk_reply_ticket_description; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.reply
    ADD CONSTRAINT fk_reply_ticket_description FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: ticket fk_requester_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket
    ADD CONSTRAINT fk_requester_ticket FOREIGN KEY (requester_id) REFERENCES fms_bhasika.requester(id);


--
-- Name: sms fk_sms_description; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.sms
    ADD CONSTRAINT fk_sms_description FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: sms fk_sms_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.sms
    ADD CONSTRAINT fk_sms_ticket FOREIGN KEY (ticket_id) REFERENCES fms_bhasika.ticket(id);


--
-- Name: ticket_attachments fk_ticket_attachments_ticket_description; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_attachments
    ADD CONSTRAINT fk_ticket_attachments_ticket_description FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: can_response fk_ticket_category; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.can_response
    ADD CONSTRAINT fk_ticket_category FOREIGN KEY (category) REFERENCES fms_bhasika.ticket_category(id);


--
-- Name: ticket fk_ticket_category; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket
    ADD CONSTRAINT fk_ticket_category FOREIGN KEY (category) REFERENCES fms_bhasika.ticket_category(id);


--
-- Name: ticket_reminder fk_ticket_description_reminder; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_reminder
    ADD CONSTRAINT fk_ticket_description_reminder FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: ticket fk_ticket_description_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket
    ADD CONSTRAINT fk_ticket_description_ticket FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: forward fk_ticket_forward_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.forward
    ADD CONSTRAINT fk_ticket_forward_ticket FOREIGN KEY (ticket_id) REFERENCES fms_bhasika.ticket(id);


--
-- Name: forward fk_ticket_forward_ticket_description; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.forward
    ADD CONSTRAINT fk_ticket_forward_ticket_description FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: notes fk_ticket_notes_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.notes
    ADD CONSTRAINT fk_ticket_notes_ticket FOREIGN KEY (ticket_id) REFERENCES fms_bhasika.ticket(id);


--
-- Name: notes fk_ticket_notes_ticket_description; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.notes
    ADD CONSTRAINT fk_ticket_notes_ticket_description FOREIGN KEY (description_id) REFERENCES fms_bhasika.ticket_description(id);


--
-- Name: ticket_reminder fk_ticket_reminder; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_reminder
    ADD CONSTRAINT fk_ticket_reminder FOREIGN KEY (ticket_id) REFERENCES fms_bhasika.ticket(id);


--
-- Name: ticket_collaborator fk_user_collaborator_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_collaborator
    ADD CONSTRAINT fk_user_collaborator_ticket FOREIGN KEY (ticket_id) REFERENCES fms_bhasika.ticket(id);


--
-- Name: users fk_user_company; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users
    ADD CONSTRAINT fk_user_company FOREIGN KEY (company_id) REFERENCES fms_bhasika.company(id);


--
-- Name: users_department_mapping fk_user_department; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_department_mapping
    ADD CONSTRAINT fk_user_department FOREIGN KEY (user_id) REFERENCES fms_bhasika.users(id);


--
-- Name: users_menu_mapping fk_user_menu; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.users_menu_mapping
    ADD CONSTRAINT fk_user_menu FOREIGN KEY (user_id) REFERENCES fms_bhasika.users(id);


--
-- Name: notes_user_mapping fk_user_notes; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.notes_user_mapping
    ADD CONSTRAINT fk_user_notes FOREIGN KEY (user_id) REFERENCES fms_bhasika.users(id);


--
-- Name: ticket fk_user_ticket; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket
    ADD CONSTRAINT fk_user_ticket FOREIGN KEY (assignee) REFERENCES fms_bhasika.users(id);


--
-- Name: ticket_collaborator fkh60auxrmnvay12ty516pgcisu; Type: FK CONSTRAINT; Schema: fms_bhasika; Owner: -
--

ALTER TABLE ONLY fms_bhasika.ticket_collaborator
    ADD CONSTRAINT fkh60auxrmnvay12ty516pgcisu FOREIGN KEY (collaborator_id) REFERENCES fms_bhasika.users(id);


--
--

