--
--


SET transaction_timeout = 0;
SELECT pg_catalog.set_config('search_path', '', false);

--
-- Name: citext; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;


--
-- Name: EXTENSION citext; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION citext IS 'data type for case-insensitive character strings';


--
-- Name: ltree; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS ltree WITH SCHEMA public;


--
-- Name: EXTENSION ltree; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION ltree IS 'data type for hierarchical tree-like structures';


--
-- Name: pg_uuidv7; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pg_uuidv7 WITH SCHEMA public;


--
-- Name: EXTENSION pg_uuidv7; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION pg_uuidv7 IS 'pg_uuidv7: create UUIDv7 values in postgres';


--
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public;


--
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions';


--
-- Name: postgis; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;


--
-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION postgis IS 'PostGIS geometry and geography spatial types and functions';


--
-- Name: auth_level; Type: TYPE; Schema: public; Owner: taf
--

CREATE TYPE public.auth_level AS ENUM (
    'aal1',
    'aal2'
);


ALTER TYPE public.auth_level OWNER TO taf;

--
-- Name: mfa_type; Type: TYPE; Schema: public; Owner: taf
--

CREATE TYPE public.mfa_type AS ENUM (
    'totp',
    'webauthn'
);


ALTER TYPE public.mfa_type OWNER TO taf;

--
-- Name: owner_access_mode; Type: TYPE; Schema: public; Owner: taf
--

CREATE TYPE public.owner_access_mode AS ENUM (
    'none',
    'read',
    'manage'
);


ALTER TYPE public.owner_access_mode OWNER TO taf;

--
-- Name: price_mode; Type: TYPE; Schema: public; Owner: taf
--

CREATE TYPE public.price_mode AS ENUM (
    'VIP',
    'VEP'
);


ALTER TYPE public.price_mode OWNER TO taf;

--
-- Name: token_purpose; Type: TYPE; Schema: public; Owner: taf
--

CREATE TYPE public.token_purpose AS ENUM (
    'verify_email',
    'reset_password',
    'invite',
    'magic_link'
);


ALTER TYPE public.token_purpose OWNER TO taf;

--
-- Name: vat_mode; Type: TYPE; Schema: public; Owner: taf
--

CREATE TYPE public.vat_mode AS ENUM (
    'auto',
    'manual'
);


ALTER TYPE public.vat_mode OWNER TO taf;

--
-- Name: attach_updatedat_trigger(); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.attach_updatedat_trigger() RETURNS event_trigger
    LANGUAGE plpgsql
    AS $_$
DECLARE cmd record;
DECLARE has_col boolean;
DECLARE table_name text;
DECLARE schema_name text;
BEGIN
  FOR cmd IN SELECT * FROM pg_event_trigger_ddl_commands()
  LOOP
    IF cmd.command_tag IN ('CREATE TABLE','CREATE TABLE AS','ALTER TABLE') THEN
      -- Only handle real tables in user schemas
      IF cmd.schema_name IS NOT NULL
         AND cmd.schema_name NOT IN ('pg_catalog','information_schema') THEN

        -- Parse object_identity to get table name
        table_name := split_part(cmd.object_identity, '.', 2);

        SELECT EXISTS (
          SELECT 1
          FROM pg_attribute a
          JOIN pg_class     c ON c.oid = a.attrelid
          JOIN pg_namespace n ON n.oid = c.relnamespace
          WHERE n.nspname = cmd.schema_name
            AND c.relname = table_name
            AND a.attname = 'updatedat'
            AND a.attnum > 0 AND NOT a.attisdropped
        ) INTO has_col;

        IF has_col THEN
          EXECUTE format('DROP TRIGGER IF EXISTS trg_set_updatedat ON %I.%I',
                         cmd.schema_name, table_name);
          EXECUTE format($fmt$
            CREATE TRIGGER trg_set_updatedat
            BEFORE UPDATE ON %I.%I
            FOR EACH ROW
            EXECUTE FUNCTION set_updatedat()
          $fmt$, cmd.schema_name, table_name);
        END IF;
      END IF;
    END IF;
  END LOOP;
END
$_$;


ALTER FUNCTION public.attach_updatedat_trigger() OWNER TO taf;

--
-- Name: create_default_program_groups(); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.create_default_program_groups() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    default_group_record RECORD;
    new_group_id uuid;
BEGIN
    -- Only process if enrollment is active
    IF NEW.status = 'active' THEN
        -- Create default groups for this program enrollment
        FOR default_group_record IN
            SELECT pdg.program_default_group_id, pdg.group_name, pdg.group_description
            FROM program_default_groups pdg
            WHERE pdg.program_id = NEW.program_id
            AND pdg.is_auto_create = true
            AND pdg.isDeleted = false
        LOOP
            -- Create the group for this org
            INSERT INTO groups (name, description, org_id)
            VALUES (default_group_record.group_name, default_group_record.group_description, NEW.org_id)
            RETURNING group_id INTO new_group_id;

            -- Create permissions for this group
            INSERT INTO group_module_permissions (group_id, module_id, action)
            SELECT new_group_id, pdgp.module_id, pdgp.action
            FROM program_default_group_permissions pdgp
            WHERE pdgp.program_default_group_id = default_group_record.program_default_group_id
            AND pdgp.permission_type = 'module'
            AND pdgp.isDeleted = false;
        END LOOP;
    END IF;

    RETURN NEW;
END;
$$;


ALTER FUNCTION public.create_default_program_groups() OWNER TO taf;

--
-- Name: get_case_documents(uuid); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.get_case_documents(p_case_id uuid) RETURNS TABLE(document_id uuid, title text, description text, type character varying, source_table text, source_context text, tags json, metadata json, updated_at timestamp with time zone)
    LANGUAGE plpgsql
    AS $$
BEGIN
  RETURN QUERY SELECT * FROM get_entity_documents('case', p_case_id);
END;
$$;


ALTER FUNCTION public.get_case_documents(p_case_id uuid) OWNER TO taf;

--
-- Name: FUNCTION get_case_documents(p_case_id uuid); Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON FUNCTION public.get_case_documents(p_case_id uuid) IS 'Returns all documents associated with a case, including source tracking and aggregated metadata';


--
-- Name: get_entity_documents(text, uuid); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.get_entity_documents(p_entity_type text, p_entity_id uuid) RETURNS TABLE(document_id uuid, title text, description text, type character varying, source_table text, source_context text, tags json, metadata json, updated_at timestamp with time zone)
    LANGUAGE plpgsql
    AS $$
DECLARE
  v_metadata_key text;
BEGIN
  v_metadata_key := p_entity_type || '_id';
  
  RETURN QUERY
  SELECT 
    d.document_id,
    d.title,
    d.description,
    d.type,
    dm_source.metadata_value as source_table,
    dm_context.metadata_value as source_context,
    COALESCE(json_agg(DISTINCT dt.tag) FILTER (WHERE dt.tag IS NOT NULL), '[]'::json) as tags,
    COALESCE(
      json_object_agg(dm.metadata_key, dm.metadata_value) 
      FILTER (WHERE dm.metadata_key IS NOT NULL AND dm.metadata_key NOT LIKE 'source_%'),
      '{}'::json
    ) as metadata,
    d.updatedAt
  FROM documents d
  INNER JOIN document_metadata dm_entity ON 
    dm_entity.document_id = d.document_id 
    AND dm_entity.metadata_key = v_metadata_key
    AND dm_entity.metadata_value = p_entity_id::text
  LEFT JOIN document_metadata dm_source ON 
    dm_source.document_id = d.document_id 
    AND dm_source.metadata_key = 'source_table'
  LEFT JOIN document_metadata dm_context ON 
    dm_context.document_id = d.document_id 
    AND dm_context.metadata_key = 'source_context'
  LEFT JOIN document_tags dt ON dt.document_id = d.document_id
  LEFT JOIN document_metadata dm ON dm.document_id = d.document_id
  WHERE d.isDeleted = FALSE AND d.isArchived = FALSE
  GROUP BY d.document_id, d.title, d.description, d.type, d.updatedAt,
           dm_source.metadata_value, dm_context.metadata_value;
END;
$$;


ALTER FUNCTION public.get_entity_documents(p_entity_type text, p_entity_id uuid) OWNER TO taf;

--
-- Name: link_document_to_case(uuid, uuid, boolean); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.link_document_to_case(p_document_id uuid, p_case_id uuid, p_auto_tag boolean DEFAULT true) RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
  v_case_number text;
  v_case_title text;
  v_client_id uuid;
  v_client_name text;
  v_metadata jsonb;
BEGIN
  -- Get case details
  SELECT case_number, title, client_id 
  INTO v_case_number, v_case_title, v_client_id
  FROM cases WHERE case_id = p_case_id;

  -- Get client name
  SELECT name INTO v_client_name FROM clients WHERE client_id = v_client_id;

  -- Build metadata jsonb
  v_metadata := jsonb_build_object(
    'case_number', v_case_number,
    'case_title', v_case_title,
    'client_id', v_client_id::text,
    'client_name', v_client_name
  );

  -- Call generic function
  PERFORM link_document_to_entity(p_document_id, 'case', p_case_id, v_metadata, p_auto_tag);
END;
$$;


ALTER FUNCTION public.link_document_to_case(p_document_id uuid, p_case_id uuid, p_auto_tag boolean) OWNER TO taf;

--
-- Name: FUNCTION link_document_to_case(p_document_id uuid, p_case_id uuid, p_auto_tag boolean); Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON FUNCTION public.link_document_to_case(p_document_id uuid, p_case_id uuid, p_auto_tag boolean) IS 'Helper function to link a document to a case with automatic metadata and tagging';


--
-- Name: link_document_to_entity(uuid, text, uuid, jsonb, boolean); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.link_document_to_entity(p_document_id uuid, p_entity_type text, p_entity_id uuid, p_entity_metadata jsonb DEFAULT '{}'::jsonb, p_auto_tag boolean DEFAULT true) RETURNS void
    LANGUAGE plpgsql
    AS $_$
DECLARE
  v_key text;
  v_value text;
BEGIN
  -- Add core linking metadata (entity_type_id = entity_id)
  EXECUTE format('
    INSERT INTO document_metadata (document_id, metadata_key, metadata_value, value_type)
    VALUES ($1, $2, $3, ''uuid'')
    ON CONFLICT (document_id, metadata_key) 
    DO UPDATE SET metadata_value = EXCLUDED.metadata_value, updatedAt = now()'
  ) USING p_document_id, p_entity_type || '_id', p_entity_id::text;

  -- Add all metadata from jsonb object
  FOR v_key, v_value IN SELECT * FROM jsonb_each_text(p_entity_metadata)
  LOOP
    INSERT INTO document_metadata (document_id, metadata_key, metadata_value, value_type)
    VALUES (p_document_id, v_key, v_value, 'text')
    ON CONFLICT (document_id, metadata_key) 
    DO UPDATE SET metadata_value = EXCLUDED.metadata_value, updatedAt = now();
  END LOOP;

  -- Add system tag for entity type
  IF p_auto_tag THEN
    INSERT INTO document_tags (document_id, tag, tag_type)
    VALUES (p_document_id, p_entity_type, 'system')
    ON CONFLICT (document_id, tag) DO NOTHING;
    
    -- Add specific entity tag if number/name available
    IF p_entity_metadata ? (p_entity_type || '_number') THEN
      INSERT INTO document_tags (document_id, tag, tag_type)
      VALUES (p_document_id, p_entity_type || ':' || (p_entity_metadata->>( p_entity_type || '_number')), 'system')
      ON CONFLICT (document_id, tag) DO NOTHING;
    ELSIF p_entity_metadata ? 'name' THEN
      INSERT INTO document_tags (document_id, tag, tag_type)
      VALUES (p_document_id, p_entity_type || ':' || (p_entity_metadata->>'name'), 'system')
      ON CONFLICT (document_id, tag) DO NOTHING;
    END IF;
  END IF;
END;
$_$;


ALTER FUNCTION public.link_document_to_entity(p_document_id uuid, p_entity_type text, p_entity_id uuid, p_entity_metadata jsonb, p_auto_tag boolean) OWNER TO taf;

--
-- Name: notify_notification_queue(); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.notify_notification_queue() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
  PERFORM pg_notify('taf_queue', row_to_json(NEW)::text);
  RETURN NEW;
END;
$$;


ALTER FUNCTION public.notify_notification_queue() OWNER TO taf;

--
-- Name: orgs_set_root_path(); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.orgs_set_root_path() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE p_root uuid; p_path ltree;
BEGIN
  IF NEW.parent_org_id IS NULL THEN
    NEW.root_org_id := COALESCE(NEW.root_org_id, NEW.org_id);
    NEW.path := text2ltree('t' || replace(NEW.org_id::text,'-',''));
  ELSE
    SELECT root_org_id, path INTO p_root, p_path FROM orgs WHERE org_id = NEW.parent_org_id;
    NEW.root_org_id := p_root;
    NEW.path := p_path || text2ltree('o' || replace(NEW.org_id::text,'-',''));
  END IF;
  RETURN NEW;
END$$;


ALTER FUNCTION public.orgs_set_root_path() OWNER TO taf;

--
-- Name: set_time_entry_rate(); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.set_time_entry_rate() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    NEW.rate := COALESCE(
        (SELECT (options->>'hourly_rate')::numeric 
         FROM user_org_memberships 
         WHERE user_id = NEW.user_id 
         AND org_id = '0194a8b2-5678-7123-8123-123456789abd'::uuid 
         AND isDeleted = FALSE),
        0  -- Default if not found
    );
    RETURN NEW;
END$$;


ALTER FUNCTION public.set_time_entry_rate() OWNER TO taf;

--
-- Name: set_updatedat(); Type: FUNCTION; Schema: public; Owner: taf
--

CREATE FUNCTION public.set_updatedat() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
  NEW.updatedat := now();  -- transaction_timestamp()
  RETURN NEW;
END
$$;


ALTER FUNCTION public.set_updatedat() OWNER TO taf;



--
-- Name: account_ai_feedback; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.account_ai_feedback (
    id integer NOT NULL,
    transaction_id integer,
    suggested_code character varying(50) DEFAULT NULL::character varying,
    chosen_code character varying(50) DEFAULT NULL::character varying,
    rationale text,
    accepted boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.account_ai_feedback OWNER TO taf;

--
-- Name: account_ai_feedback_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.account_ai_feedback_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.account_ai_feedback_id_seq OWNER TO taf;

--
-- Name: account_ai_feedback_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.account_ai_feedback_id_seq OWNED BY public.account_ai_feedback.id;


--
-- Name: appeals; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.appeals (
    id integer NOT NULL,
    case_id integer NOT NULL,
    employee_id integer NOT NULL,
    reason text,
    status character varying(100) DEFAULT 'submitted'::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.appeals OWNER TO taf;

--
-- Name: appeals_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.appeals_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.appeals_id_seq OWNER TO taf;

--
-- Name: appeals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.appeals_id_seq OWNED BY public.appeals.id;


--
-- Name: applications; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.applications (
    application_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    branch_id uuid,
    open_position_id uuid NOT NULL,
    first_name character varying(100) NOT NULL,
    last_name character varying(100) NOT NULL,
    email character varying(255) NOT NULL,
    phone character varying(50) DEFAULT NULL::character varying,
    address text,
    date_of_birth date,
    application_date date DEFAULT now() NOT NULL,
    status character varying(100) DEFAULT NULL::character varying,
    notes text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.applications OWNER TO taf;

--
-- Name: appraisal_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.appraisal_templates (
    id integer NOT NULL,
    tenant_id integer,
    role_id integer,
    language_code character varying(10) DEFAULT NULL::character varying,
    template_json json,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.appraisal_templates OWNER TO taf;

--
-- Name: appraisal_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.appraisal_templates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.appraisal_templates_id_seq OWNER TO taf;

--
-- Name: appraisal_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.appraisal_templates_id_seq OWNED BY public.appraisal_templates.id;


--
-- Name: attendance; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.attendance (
    id integer NOT NULL,
    employee character varying(255) NOT NULL,
    date date NOT NULL,
    restricted_start time without time zone,
    restricted_end time without time zone,
    hours_worked numeric(5,2) DEFAULT 0.00 NOT NULL,
    overtime numeric(5,2) DEFAULT 0.00 NOT NULL,
    injury_flag boolean DEFAULT false NOT NULL,
    restricted_duty boolean DEFAULT false NOT NULL,
    pay_code character varying(20) DEFAULT NULL::character varying,
    approval_status character varying(20) DEFAULT 'Approved'::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.attendance OWNER TO taf;

--
-- Name: attendance_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.attendance_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.attendance_id_seq OWNER TO taf;

--
-- Name: attendance_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.attendance_id_seq OWNED BY public.attendance.id;


--
-- Name: audit_logs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.audit_logs (
    id integer NOT NULL,
    user_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    action character varying(255) NOT NULL,
    entity character varying(255) DEFAULT NULL::character varying,
    description text,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.audit_logs OWNER TO taf;

--
-- Name: audit_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.audit_logs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.audit_logs_id_seq OWNER TO taf;

--
-- Name: audit_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.audit_logs_id_seq OWNED BY public.audit_logs.id;


--
-- Name: auth_events; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.auth_events (
    event_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    user_id uuid,
    event_type text NOT NULL,
    provider text,
    ip inet,
    user_agent text,
    metadata jsonb,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.auth_events OWNER TO taf;

--
-- Name: auto_orders; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.auto_orders (
    auto_order_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid,
    minimum_stock_qty integer,
    order_qty integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.auto_orders OWNER TO taf;

--
-- Name: bank_detail_changes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.bank_detail_changes (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    bankname character varying(255) DEFAULT NULL::character varying,
    accountname character varying(255) DEFAULT NULL::character varying,
    accountnumber character varying(255) DEFAULT NULL::character varying,
    status character varying(100) DEFAULT 'Pending'::character varying,
    approved_at timestamp without time zone,
    approved_by integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.bank_detail_changes OWNER TO taf;

--
-- Name: bank_detail_changes_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.bank_detail_changes_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.bank_detail_changes_id_seq OWNER TO taf;

--
-- Name: bank_detail_changes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.bank_detail_changes_id_seq OWNED BY public.bank_detail_changes.id;


--
-- Name: branches; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.branches (
    branch_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    name text,
    latitude numeric(10,8) DEFAULT NULL::numeric,
    longitude numeric(11,8) DEFAULT NULL::numeric,
    settings jsonb,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.branches OWNER TO taf;

--
-- Name: budgets; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.budgets (
    budget_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    department character varying(255) NOT NULL,
    project character varying(255) NOT NULL,
    costcenter character varying(100) NOT NULL,
    accountcode character varying(100) NOT NULL,
    timeperiod character varying(50) NOT NULL,
    budgettype character varying(50) NOT NULL,
    category character varying(255) NOT NULL,
    budgetedamount numeric(12,2) NOT NULL,
    actualamount numeric(12,2) DEFAULT 0.00,
    variance numeric(12,2) GENERATED ALWAYS AS ((budgetedamount - actualamount)) STORED,
    percentageused numeric(5,2) GENERATED ALWAYS AS (
CASE
    WHEN (budgetedamount > (0)::numeric) THEN round(((actualamount / budgetedamount) * (100)::numeric), 2)
    ELSE (0)::numeric
END) STORED,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT budgets_budgettype_check CHECK (((budgettype)::text = ANY ((ARRAY['Initial'::character varying, 'Revised'::character varying, 'Carry Forward'::character varying])::text[]))),
    CONSTRAINT budgets_timeperiod_check CHECK (((timeperiod)::text = ANY ((ARRAY['Monthly'::character varying, 'Quarterly'::character varying, 'Annual'::character varying])::text[])))
);


ALTER TABLE public.budgets OWNER TO taf;

--
-- Name: calendar_accounts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.calendar_accounts (
    id integer NOT NULL,
    user_id integer NOT NULL,
    provider character varying(50) NOT NULL,
    access_token text,
    refresh_token text,
    token_expires timestamp without time zone,
    created_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.calendar_accounts OWNER TO taf;

--
-- Name: calendar_accounts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.calendar_accounts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.calendar_accounts_id_seq OWNER TO taf;

--
-- Name: calendar_accounts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.calendar_accounts_id_seq OWNED BY public.calendar_accounts.id;


--
-- Name: calendar_availability; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.calendar_availability (
    id integer NOT NULL,
    user_id integer NOT NULL,
    start_time timestamp without time zone NOT NULL,
    end_time timestamp without time zone NOT NULL,
    type character varying(100) NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.calendar_availability OWNER TO taf;

--
-- Name: calendar_availability_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.calendar_availability_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.calendar_availability_id_seq OWNER TO taf;

--
-- Name: calendar_availability_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.calendar_availability_id_seq OWNED BY public.calendar_availability.id;


--
-- Name: calendar_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.calendar_categories (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.calendar_categories OWNER TO taf;

--
-- Name: calendar_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.calendar_categories_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.calendar_categories_id_seq OWNER TO taf;

--
-- Name: calendar_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.calendar_categories_id_seq OWNED BY public.calendar_categories.id;


--
-- Name: calendar_event_documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.calendar_event_documents (
    id integer NOT NULL,
    event_id integer NOT NULL,
    document_id uuid NOT NULL,
    uploaded_by integer,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.calendar_event_documents OWNER TO taf;

--
-- Name: calendar_event_documents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.calendar_event_documents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.calendar_event_documents_id_seq OWNER TO taf;

--
-- Name: calendar_event_documents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.calendar_event_documents_id_seq OWNED BY public.calendar_event_documents.id;


--
-- Name: calendar_event_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.calendar_event_permissions (
    id integer NOT NULL,
    event_id integer NOT NULL,
    user_id integer NOT NULL,
    role character varying(100) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.calendar_event_permissions OWNER TO taf;

--
-- Name: calendar_event_permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.calendar_event_permissions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.calendar_event_permissions_id_seq OWNER TO taf;

--
-- Name: calendar_event_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.calendar_event_permissions_id_seq OWNED BY public.calendar_event_permissions.id;


--
-- Name: calendar_events; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.calendar_events (
    id integer NOT NULL,
    title character varying(255) NOT NULL,
    description text,
    provider character varying(255) DEFAULT NULL::character varying,
    start_time timestamp without time zone NOT NULL,
    end_time timestamp without time zone,
    location character varying(255) DEFAULT NULL::character varying,
    recurrence_rule character varying(255) DEFAULT NULL::character varying,
    recurrence_end timestamp without time zone,
    parent_event_id integer,
    kanban_task_id integer,
    created_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    category_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.calendar_events OWNER TO taf;

--
-- Name: calendar_events_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.calendar_events_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.calendar_events_id_seq OWNER TO taf;

--
-- Name: calendar_events_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.calendar_events_id_seq OWNED BY public.calendar_events.id;


--
-- Name: career_paths; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.career_paths (
    id integer NOT NULL,
    tenant_id integer,
    role_id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.career_paths OWNER TO taf;

--
-- Name: career_paths_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.career_paths_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.career_paths_id_seq OWNER TO taf;

--
-- Name: career_paths_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.career_paths_id_seq OWNED BY public.career_paths.id;


--
-- Name: career_steps; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.career_steps (
    id integer NOT NULL,
    path_id integer NOT NULL,
    step_number integer NOT NULL,
    title character varying(255) NOT NULL,
    role_id integer,
    requirements text,
    tenant_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.career_steps OWNER TO taf;

--
-- Name: career_steps_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.career_steps_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.career_steps_id_seq OWNER TO taf;

--
-- Name: career_steps_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.career_steps_id_seq OWNED BY public.career_steps.id;


--
-- Name: case_evidence; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.case_evidence (
    id integer NOT NULL,
    case_id integer NOT NULL,
    file_path character varying(255) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.case_evidence OWNER TO taf;

--
-- Name: case_evidence_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.case_evidence_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.case_evidence_id_seq OWNER TO taf;

--
-- Name: case_evidence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.case_evidence_id_seq OWNED BY public.case_evidence.id;


--
-- Name: case_instructions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.case_instructions (
    case_instruction_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    case_id uuid NOT NULL,
    instruction_date timestamp with time zone,
    instruction text,
    document_ids text,
    created_by uuid,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.case_instructions OWNER TO taf;

--
-- Name: case_notes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.case_notes (
    id integer NOT NULL,
    matter_id integer NOT NULL,
    note text,
    created_by integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.case_notes OWNER TO taf;

--
-- Name: case_notes_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.case_notes_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.case_notes_id_seq OWNER TO taf;

--
-- Name: case_notes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.case_notes_id_seq OWNED BY public.case_notes.id;


--
-- Name: case_participants; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.case_participants (
    id integer NOT NULL,
    matter_id integer NOT NULL,
    person_id integer NOT NULL,
    role character varying(100) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.case_participants OWNER TO taf;

--
-- Name: case_participants_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.case_participants_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.case_participants_id_seq OWNER TO taf;

--
-- Name: case_participants_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.case_participants_id_seq OWNED BY public.case_participants.id;


--
-- Name: case_tasks; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.case_tasks (
    id integer NOT NULL,
    matter_id integer NOT NULL,
    subject character varying(255) DEFAULT NULL::character varying,
    due_date timestamp without time zone,
    assigned_to integer,
    status character varying(50) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.case_tasks OWNER TO taf;

--
-- Name: case_tasks_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.case_tasks_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.case_tasks_id_seq OWNER TO taf;

--
-- Name: case_tasks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.case_tasks_id_seq OWNED BY public.case_tasks.id;


--
-- Name: cases; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.cases (
    case_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    client_id uuid NOT NULL,
    case_number text,
    title text,
    status text,
    opened_at timestamp with time zone,
    closed_at timestamp with time zone,
    lead_rep_id uuid,
    description text,
    initial_instructions text,
    org_id uuid,
    user_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.cases OWNER TO taf;

--
-- Name: cash_sessions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.cash_sessions (
    id integer NOT NULL,
    cashier_id integer NOT NULL,
    opened_at timestamp without time zone NOT NULL,
    closed_at timestamp without time zone,
    opening_balance numeric(10,2) NOT NULL,
    closing_balance numeric(10,2) DEFAULT NULL::numeric,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.cash_sessions OWNER TO taf;

--
-- Name: cash_sessions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.cash_sessions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.cash_sessions_id_seq OWNER TO taf;

--
-- Name: cash_sessions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.cash_sessions_id_seq OWNED BY public.cash_sessions.id;


--
-- Name: certificate_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.certificate_templates (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    file_path text NOT NULL,
    tenant_id integer,
    isdeleted boolean DEFAULT false,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.certificate_templates OWNER TO taf;

--
-- Name: certificate_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.certificate_templates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.certificate_templates_id_seq OWNER TO taf;

--
-- Name: certificate_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.certificate_templates_id_seq OWNED BY public.certificate_templates.id;


--
-- Name: check_ins; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.check_ins (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    manager_id integer,
    scheduled_at timestamp without time zone,
    completed_at timestamp without time zone,
    notes text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.check_ins OWNER TO taf;

--
-- Name: check_ins_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.check_ins_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.check_ins_id_seq OWNER TO taf;

--
-- Name: check_ins_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.check_ins_id_seq OWNED BY public.check_ins.id;


--
-- Name: clients; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.clients (
    client_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    user_id uuid,
    name text,
    phone text,
    email text,
    address text,
    city text,
    country text,
    description text,
    comments text,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.clients OWNER TO taf;

--
-- Name: companies; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.companies (
    id integer NOT NULL,
    country_id integer NOT NULL,
    name character varying(255) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.companies OWNER TO taf;

--
-- Name: companies_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.companies_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.companies_id_seq OWNER TO taf;

--
-- Name: companies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.companies_id_seq OWNED BY public.companies.id;


--
-- Name: competencies; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.competencies (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.competencies OWNER TO taf;

--
-- Name: competencies_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.competencies_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.competencies_id_seq OWNER TO taf;

--
-- Name: competencies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.competencies_id_seq OWNED BY public.competencies.id;


--
-- Name: competency_assessments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.competency_assessments (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    competency_id integer NOT NULL,
    assessor_id integer NOT NULL,
    rating integer NOT NULL,
    notes text,
    assessment_date timestamp without time zone,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.competency_assessments OWNER TO taf;

--
-- Name: competency_assessments_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.competency_assessments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.competency_assessments_id_seq OWNER TO taf;

--
-- Name: competency_assessments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.competency_assessments_id_seq OWNED BY public.competency_assessments.id;


--
-- Name: contract_approvals; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.contract_approvals (
    id integer NOT NULL,
    document_id uuid NOT NULL,
    step_order integer NOT NULL,
    approver_role character varying(100) NOT NULL,
    status character varying(50) DEFAULT 'pending'::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.contract_approvals OWNER TO taf;

--
-- Name: contract_approvals_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.contract_approvals_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.contract_approvals_id_seq OWNER TO taf;

--
-- Name: contract_approvals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.contract_approvals_id_seq OWNED BY public.contract_approvals.id;


--
-- Name: contract_versions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.contract_versions (
    id integer NOT NULL,
    contract_id integer NOT NULL,
    storage_key character varying(255) NOT NULL,
    version_number integer NOT NULL,
    version_hash character varying(64) DEFAULT NULL::character varying,
    created_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.contract_versions OWNER TO taf;

--
-- Name: contract_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.contract_versions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.contract_versions_id_seq OWNER TO taf;

--
-- Name: contract_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.contract_versions_id_seq OWNED BY public.contract_versions.id;


--
-- Name: contracts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.contracts (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    contract_type character varying(50) NOT NULL,
    start_date date NOT NULL,
    end_date date,
    expiry_date date,
    renewal_status character varying(50) DEFAULT NULL::character varying,
    status character varying(50) DEFAULT NULL::character varying,
    file_path character varying(255) DEFAULT NULL::character varying,
    created_by integer,
    updated_by integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.contracts OWNER TO taf;

--
-- Name: contracts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.contracts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.contracts_id_seq OWNER TO taf;

--
-- Name: contracts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.contracts_id_seq OWNED BY public.contracts.id;


--
-- Name: corrective_actions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.corrective_actions (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    name character varying(255) DEFAULT NULL::character varying,
    description text,
    steps text,
    responsible_user_id integer,
    status character varying(50) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.corrective_actions OWNER TO taf;

--
-- Name: corrective_actions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.corrective_actions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.corrective_actions_id_seq OWNER TO taf;

--
-- Name: corrective_actions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.corrective_actions_id_seq OWNED BY public.corrective_actions.id;


--
-- Name: countries; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.countries (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.countries OWNER TO taf;

--
-- Name: countries_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.countries_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.countries_id_seq OWNER TO taf;

--
-- Name: countries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.countries_id_seq OWNED BY public.countries.id;


--
-- Name: country_holidays; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.country_holidays (
    id integer NOT NULL,
    country_id integer NOT NULL,
    holiday_name character varying(100) NOT NULL,
    holiday_date date NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.country_holidays OWNER TO taf;

--
-- Name: country_holidays_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.country_holidays_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.country_holidays_id_seq OWNER TO taf;

--
-- Name: country_holidays_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.country_holidays_id_seq OWNED BY public.country_holidays.id;


--
-- Name: custom_field_values; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.custom_field_values (
    id integer NOT NULL,
    field_id integer NOT NULL,
    record_id integer NOT NULL,
    field_value text,
    tenant_id integer NOT NULL,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.custom_field_values OWNER TO taf;

--
-- Name: custom_field_values_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.custom_field_values_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.custom_field_values_id_seq OWNER TO taf;

--
-- Name: custom_field_values_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.custom_field_values_id_seq OWNED BY public.custom_field_values.id;


--
-- Name: custom_fields; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.custom_fields (
    id integer NOT NULL,
    tenant_id integer NOT NULL,
    branch_id integer,
    model character varying(100) NOT NULL,
    field_name character varying(100) NOT NULL,
    field_type character varying(50) NOT NULL,
    is_required boolean DEFAULT false NOT NULL,
    options json,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.custom_fields OWNER TO taf;

--
-- Name: custom_fields_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.custom_fields_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.custom_fields_id_seq OWNER TO taf;

--
-- Name: custom_fields_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.custom_fields_id_seq OWNED BY public.custom_fields.id;


--
-- Name: customer_history; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.customer_history (
    id integer NOT NULL,
    customerid integer NOT NULL,
    action character varying(255) NOT NULL,
    description text,
    performedby integer NOT NULL,
    performedat timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.customer_history OWNER TO taf;

--
-- Name: customer_history_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.customer_history_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.customer_history_id_seq OWNER TO taf;

--
-- Name: customer_history_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.customer_history_id_seq OWNED BY public.customer_history.id;


--
-- Name: customer_settings; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.customer_settings (
    id integer NOT NULL,
    customer_id integer NOT NULL,
    name character varying(100) NOT NULL,
    value text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.customer_settings OWNER TO taf;

--
-- Name: customer_settings_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.customer_settings_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.customer_settings_id_seq OWNER TO taf;

--
-- Name: customer_settings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.customer_settings_id_seq OWNED BY public.customer_settings.id;


--
-- Name: customers; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.customers (
    customer_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    customer_type text NOT NULL,
    name text NOT NULL,
    email text,
    phone_number text,
    address text,
    tin text,
    risk_rating text,
    compliance_status text,
    balance numeric(10,2) DEFAULT 0,
    org_id uuid,
    user_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.customers OWNER TO taf;

--
-- Name: dashboard_card_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.dashboard_card_permissions (
    id integer NOT NULL,
    card_slug character varying(255) NOT NULL,
    group_id integer,
    user_id integer,
    tenant_id integer,
    branch_id integer,
    can_view boolean DEFAULT true NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.dashboard_card_permissions OWNER TO taf;

--
-- Name: dashboard_card_permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.dashboard_card_permissions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.dashboard_card_permissions_id_seq OWNER TO taf;

--
-- Name: dashboard_card_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.dashboard_card_permissions_id_seq OWNED BY public.dashboard_card_permissions.id;


--
-- Name: deduction_rates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.deduction_rates (
    deduction_rate_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    deduction_type_id uuid NOT NULL,
    start_salary numeric(10,2) DEFAULT NULL::numeric,
    end_salary numeric(10,2) DEFAULT NULL::numeric,
    rate numeric(10,4) DEFAULT NULL::numeric,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.deduction_rates OWNER TO taf;

--
-- Name: deduction_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.deduction_types (
    deduction_type_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name text,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.deduction_types OWNER TO taf;

--
-- Name: demo_graph_data; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.demo_graph_data (
    id integer NOT NULL,
    tenant_id integer,
    x_value numeric,
    y_value numeric,
    z_value numeric,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.demo_graph_data OWNER TO taf;

--
-- Name: demo_graph_data_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.demo_graph_data_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.demo_graph_data_id_seq OWNER TO taf;

--
-- Name: demo_graph_data_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.demo_graph_data_id_seq OWNED BY public.demo_graph_data.id;


--
-- Name: departments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.departments (
    department_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    branch_id uuid,
    name text NOT NULL,
    description text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.departments OWNER TO taf;

--
-- Name: detail_view_elements; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.detail_view_elements (
    id integer NOT NULL,
    detail_view_id integer NOT NULL,
    config jsonb DEFAULT '{"groupBy": "", "timeUnit": "", "aggregateFunc": ""}'::jsonb,
    tenant_id integer,
    branch_id integer,
    order_index integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.detail_view_elements OWNER TO taf;

--
-- Name: detail_view_elements_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.detail_view_elements_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.detail_view_elements_id_seq OWNER TO taf;

--
-- Name: detail_view_elements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.detail_view_elements_id_seq OWNED BY public.detail_view_elements.id;


--
-- Name: detail_views; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.detail_views (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    config jsonb DEFAULT '{"groupBy": "", "timeUnit": "", "aggregateFunc": ""}'::jsonb,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.detail_views OWNER TO taf;

--
-- Name: detail_views_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.detail_views_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.detail_views_id_seq OWNER TO taf;

--
-- Name: detail_views_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.detail_views_id_seq OWNED BY public.detail_views.id;


--
-- Name: disciplinary_actions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.disciplinary_actions (
    id integer NOT NULL,
    case_id integer NOT NULL,
    action character varying(255) NOT NULL,
    effective_date date NOT NULL,
    approved_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.disciplinary_actions OWNER TO taf;

--
-- Name: disciplinary_actions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.disciplinary_actions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.disciplinary_actions_id_seq OWNER TO taf;

--
-- Name: disciplinary_actions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.disciplinary_actions_id_seq OWNED BY public.disciplinary_actions.id;


--
-- Name: disciplinary_cases; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.disciplinary_cases (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    violation_id integer NOT NULL,
    severity character varying(100) NOT NULL,
    summary text,
    status character varying(100) DEFAULT 'open'::character varying,
    assigned_to integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.disciplinary_cases OWNER TO taf;

--
-- Name: disciplinary_cases_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.disciplinary_cases_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.disciplinary_cases_id_seq OWNER TO taf;

--
-- Name: disciplinary_cases_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.disciplinary_cases_id_seq OWNED BY public.disciplinary_cases.id;


--
-- Name: districts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.districts (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.districts OWNER TO taf;

--
-- Name: districts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.districts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.districts_id_seq OWNER TO taf;

--
-- Name: districts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.districts_id_seq OWNED BY public.districts.id;


--
-- Name: document_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_categories (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.document_categories OWNER TO taf;

--
-- Name: document_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.document_categories_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.document_categories_id_seq OWNER TO taf;

--
-- Name: document_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.document_categories_id_seq OWNED BY public.document_categories.id;


--
-- Name: document_comments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_comments (
    document_comment_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    document_id uuid NOT NULL,
    user_id uuid NOT NULL,
    comment text NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.document_comments OWNER TO taf;

--
-- Name: document_folders; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_folders (
    id integer NOT NULL,
    parent_id integer,
    name character varying(255) NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.document_folders OWNER TO taf;

--
-- Name: document_folders_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.document_folders_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.document_folders_id_seq OWNER TO taf;

--
-- Name: document_folders_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.document_folders_id_seq OWNED BY public.document_folders.id;


--
-- Name: document_metadata; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_metadata (
    document_metadata_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    document_version_id uuid,
    document_id uuid,
    metadata_key character varying(100) NOT NULL,
    metadata_value text,
    value_type character varying(20) DEFAULT 'text'::character varying,
    searchable boolean DEFAULT true,
    indexed boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT document_metadata_value_type_check CHECK (((value_type)::text = ANY ((ARRAY['text'::character varying, 'number'::character varying, 'date'::character varying, 'uuid'::character varying, 'json'::character varying])::text[])))
);


ALTER TABLE public.document_metadata OWNER TO taf;

--
-- Name: TABLE document_metadata; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON TABLE public.document_metadata IS 'Enhanced metadata system for documents with support for case/client linking and searchable key-value pairs';


--
-- Name: COLUMN document_metadata.document_id; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_metadata.document_id IS 'Direct reference to document (replaces document_version_id for most use cases)';


--
-- Name: COLUMN document_metadata.metadata_key; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_metadata.metadata_key IS 'Standardized metadata key (e.g., case_id, client_id, source_table)';


--
-- Name: COLUMN document_metadata.metadata_value; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_metadata.metadata_value IS 'Metadata value stored as text, with value_type indicating how to interpret it';


--
-- Name: COLUMN document_metadata.value_type; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_metadata.value_type IS 'Data type hint: text, number, date, uuid, or json';


--
-- Name: COLUMN document_metadata.searchable; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_metadata.searchable IS 'Whether this metadata should be included in document searches';


--
-- Name: document_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_permissions (
    document_permission_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    document_id uuid NOT NULL,
    user_id uuid NOT NULL,
    can_view boolean DEFAULT false NOT NULL,
    can_edit boolean DEFAULT false NOT NULL,
    can_comment boolean DEFAULT false NOT NULL,
    org_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.document_permissions OWNER TO taf;

--
-- Name: document_tags; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_tags (
    document_tag_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    document_id uuid NOT NULL,
    tag character varying(255) NOT NULL,
    parent_tag_id uuid,
    tag_type character varying(50) DEFAULT 'custom'::character varying,
    color character varying(7) DEFAULT NULL::character varying,
    icon character varying(50) DEFAULT NULL::character varying,
    sort_order integer DEFAULT 0,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT document_tags_tag_type_check CHECK (((tag_type)::text = ANY ((ARRAY['system'::character varying, 'category'::character varying, 'custom'::character varying, 'auto'::character varying])::text[])))
);


ALTER TABLE public.document_tags OWNER TO taf;

--
-- Name: TABLE document_tags; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON TABLE public.document_tags IS 'Hierarchical tag system for documents with support for system-generated and user-created tags';


--
-- Name: COLUMN document_tags.parent_tag_id; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_tags.parent_tag_id IS 'Parent tag for hierarchical organization (e.g., case:MC001 under case)';


--
-- Name: COLUMN document_tags.tag_type; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_tags.tag_type IS 'Tag origin: system (auto-generated), category (folder replacement), custom (user-created), auto (from AI/rules)';


--
-- Name: COLUMN document_tags.color; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_tags.color IS 'UI display color in hex format (e.g., #3B82F6)';


--
-- Name: COLUMN document_tags.icon; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.document_tags.icon IS 'Icon identifier for UI display (e.g., fa-folder, fa-tag)';


--
-- Name: document_versions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.document_versions (
    document_version_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    file_path character varying(255) NOT NULL,
    document_id uuid NOT NULL,
    storage_key character varying(255) NOT NULL,
    isarchived boolean DEFAULT false NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.document_versions OWNER TO taf;

--
-- Name: documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.documents (
    document_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    parent_document_id uuid,
    folder_id uuid,
    category_id uuid,
    org_id uuid,
    title text NOT NULL,
    description text,
    language_code text DEFAULT 'en'::text,
    owner_id uuid NOT NULL,
    connector_id uuid,
    type character varying(50) DEFAULT NULL::character varying,
    expiry_date date,
    isarchived boolean DEFAULT false NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.documents OWNER TO taf;

--
-- Name: element_options; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.element_options (
    id integer NOT NULL,
    element_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    display_text character varying(100) NOT NULL,
    value character varying(100) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.element_options OWNER TO taf;

--
-- Name: element_options_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.element_options_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.element_options_id_seq OWNER TO taf;

--
-- Name: element_options_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.element_options_id_seq OWNED BY public.element_options.id;


--
-- Name: element_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.element_types (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    name character varying(100) NOT NULL,
    html_type character varying(50) DEFAULT NULL::character varying,
    display_class character varying(100) DEFAULT NULL::character varying,
    sql_type character varying(50) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.element_types OWNER TO taf;

--
-- Name: element_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.element_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.element_types_id_seq OWNER TO taf;

--
-- Name: element_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.element_types_id_seq OWNED BY public.element_types.id;


--
-- Name: employee_authorized_locations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_authorized_locations (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    location_id integer NOT NULL,
    start_date date NOT NULL,
    end_date date,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_authorized_locations OWNER TO taf;

--
-- Name: employee_authorized_locations_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_authorized_locations_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_authorized_locations_id_seq OWNER TO taf;

--
-- Name: employee_authorized_locations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_authorized_locations_id_seq OWNED BY public.employee_authorized_locations.id;


--
-- Name: employee_certificates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_certificates (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    cert_name character varying(255) DEFAULT NULL::character varying,
    file_path character varying(255) DEFAULT NULL::character varying,
    issued_date date,
    expiry_date date,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_certificates OWNER TO taf;

--
-- Name: employee_certificates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_certificates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_certificates_id_seq OWNER TO taf;

--
-- Name: employee_certificates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_certificates_id_seq OWNED BY public.employee_certificates.id;


--
-- Name: employee_competencies; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_competencies (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    competency_id integer NOT NULL,
    self_rating integer,
    manager_rating integer,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.employee_competencies OWNER TO taf;

--
-- Name: employee_competencies_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_competencies_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_competencies_id_seq OWNER TO taf;

--
-- Name: employee_competencies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_competencies_id_seq OWNED BY public.employee_competencies.id;


--
-- Name: employee_custom_fields; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_custom_fields (
    id integer NOT NULL,
    tenant_id integer NOT NULL,
    branch_id integer,
    field_name character varying(100) NOT NULL,
    field_type character varying(50) NOT NULL,
    is_required boolean DEFAULT false NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_custom_fields OWNER TO taf;

--
-- Name: employee_custom_fields_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_custom_fields_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_custom_fields_id_seq OWNER TO taf;

--
-- Name: employee_custom_fields_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_custom_fields_id_seq OWNED BY public.employee_custom_fields.id;


--
-- Name: employee_custom_values; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_custom_values (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    field_id integer NOT NULL,
    field_value text,
    tenant_id integer NOT NULL,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_custom_values OWNER TO taf;

--
-- Name: employee_custom_values_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_custom_values_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_custom_values_id_seq OWNER TO taf;

--
-- Name: employee_custom_values_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_custom_values_id_seq OWNED BY public.employee_custom_values.id;


--
-- Name: employee_documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_documents (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    doc_type character varying(100) NOT NULL,
    file_name character varying(255) DEFAULT NULL::character varying,
    file_path text NOT NULL,
    signed_at timestamp without time zone,
    uploaded_by integer,
    uploaded_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_documents OWNER TO taf;

--
-- Name: employee_documents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_documents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_documents_id_seq OWNER TO taf;

--
-- Name: employee_documents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_documents_id_seq OWNED BY public.employee_documents.id;


--
-- Name: employee_exits; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_exits (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    employee_id integer NOT NULL,
    resignation_date date NOT NULL,
    status character varying(50) DEFAULT 'pending'::character varying,
    final_pay numeric(10,2) DEFAULT 0.00,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_exits OWNER TO taf;

--
-- Name: employee_exits_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_exits_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_exits_id_seq OWNER TO taf;

--
-- Name: employee_exits_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_exits_id_seq OWNED BY public.employee_exits.id;


--
-- Name: employee_items; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_items (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    item_name character varying(100) NOT NULL,
    is_ppe boolean DEFAULT false NOT NULL,
    expiry_date date,
    assignee_user_id integer,
    assignee_group_id integer,
    assigned_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    due_date date,
    completed_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_items OWNER TO taf;

--
-- Name: employee_items_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_items_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_items_id_seq OWNER TO taf;

--
-- Name: employee_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_items_id_seq OWNED BY public.employee_items.id;


--
-- Name: employee_location_changes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_location_changes (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    stations character varying(255) NOT NULL,
    action character varying(20) NOT NULL,
    effective_date date NOT NULL,
    processed_at timestamp without time zone
);


ALTER TABLE public.employee_location_changes OWNER TO taf;

--
-- Name: employee_location_changes_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_location_changes_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_location_changes_id_seq OWNER TO taf;

--
-- Name: employee_location_changes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_location_changes_id_seq OWNED BY public.employee_location_changes.id;


--
-- Name: employee_shifts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_shifts (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    shift_id integer NOT NULL,
    shift_date date NOT NULL,
    start_time time without time zone,
    end_time time without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_shifts OWNER TO taf;

--
-- Name: employee_shifts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_shifts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_shifts_id_seq OWNER TO taf;

--
-- Name: employee_shifts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_shifts_id_seq OWNED BY public.employee_shifts.id;


--
-- Name: employee_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employee_types (
    id integer NOT NULL,
    type character varying(50) NOT NULL,
    default_items text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employee_types OWNER TO taf;

--
-- Name: employee_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employee_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employee_types_id_seq OWNER TO taf;

--
-- Name: employee_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employee_types_id_seq OWNED BY public.employee_types.id;


--
-- Name: employees2locations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employees2locations (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    location_id integer NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employees2locations OWNER TO taf;

--
-- Name: employees2locations_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employees2locations_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employees2locations_id_seq OWNER TO taf;

--
-- Name: employees2locations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employees2locations_id_seq OWNED BY public.employees2locations.id;


--
-- Name: employees2users; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.employees2users (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    user_id integer NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.employees2users OWNER TO taf;

--
-- Name: employees2users_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.employees2users_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.employees2users_id_seq OWNER TO taf;

--
-- Name: employees2users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.employees2users_id_seq OWNED BY public.employees2users.id;


--
-- Name: event_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.event_categories (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.event_categories OWNER TO taf;

--
-- Name: event_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.event_categories_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.event_categories_id_seq OWNER TO taf;

--
-- Name: event_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.event_categories_id_seq OWNED BY public.event_categories.id;


--
-- Name: exit_approvals; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.exit_approvals (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    exit_id integer NOT NULL,
    approver_id integer NOT NULL,
    level integer NOT NULL,
    status character varying(50) DEFAULT 'pending'::character varying,
    approved_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.exit_approvals OWNER TO taf;

--
-- Name: exit_approvals_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.exit_approvals_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.exit_approvals_id_seq OWNER TO taf;

--
-- Name: exit_approvals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.exit_approvals_id_seq OWNED BY public.exit_approvals.id;


--
-- Name: exit_clearances; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.exit_clearances (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    exit_id integer NOT NULL,
    item character varying(100) DEFAULT NULL::character varying,
    returned boolean DEFAULT false,
    access_revoked boolean DEFAULT false,
    notes text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.exit_clearances OWNER TO taf;

--
-- Name: exit_clearances_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.exit_clearances_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.exit_clearances_id_seq OWNER TO taf;

--
-- Name: exit_clearances_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.exit_clearances_id_seq OWNED BY public.exit_clearances.id;


--
-- Name: exit_feedback; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.exit_feedback (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    exit_interview_id integer NOT NULL,
    question character varying(255) DEFAULT NULL::character varying,
    response text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.exit_feedback OWNER TO taf;

--
-- Name: exit_feedback_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.exit_feedback_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.exit_feedback_id_seq OWNER TO taf;

--
-- Name: exit_feedback_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.exit_feedback_id_seq OWNED BY public.exit_feedback.id;


--
-- Name: exit_interviews; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.exit_interviews (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    exit_id integer NOT NULL,
    interviewer_id integer,
    scheduled_at timestamp without time zone,
    completed_at timestamp without time zone,
    notes text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.exit_interviews OWNER TO taf;

--
-- Name: exit_interviews_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.exit_interviews_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.exit_interviews_id_seq OWNER TO taf;

--
-- Name: exit_interviews_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.exit_interviews_id_seq OWNED BY public.exit_interviews.id;


--
-- Name: expense_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.expense_types (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    description text,
    tenant_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.expense_types OWNER TO taf;

--
-- Name: expense_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.expense_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.expense_types_id_seq OWNER TO taf;

--
-- Name: expense_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.expense_types_id_seq OWNED BY public.expense_types.id;


--
-- Name: expenses; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.expenses (
    expense_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    reference_table text,
    reference_id uuid,
    date date,
    vendor_id uuid,
    invoice_number text,
    amount numeric(10,2) DEFAULT 0,
    description text,
    status text DEFAULT 'Pending'::text,
    comments text,
    approved boolean DEFAULT false,
    billed_to_client boolean DEFAULT false,
    added_to_cost_schedule boolean DEFAULT false,
    billable boolean DEFAULT false NOT NULL,
    user_id uuid NOT NULL,
    document_ids text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.expenses OWNER TO taf;

--
-- Name: feedback_notes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.feedback_notes (
    id integer NOT NULL,
    from_user_id integer NOT NULL,
    to_user_id integer NOT NULL,
    request_id integer,
    note text NOT NULL,
    sentiment_score numeric(3,2) DEFAULT NULL::numeric,
    is_private boolean DEFAULT true,
    moderated boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.feedback_notes OWNER TO taf;

--
-- Name: feedback_notes_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.feedback_notes_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.feedback_notes_id_seq OWNER TO taf;

--
-- Name: feedback_notes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.feedback_notes_id_seq OWNED BY public.feedback_notes.id;


--
-- Name: feedback_requests; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.feedback_requests (
    id integer NOT NULL,
    requestor_id integer NOT NULL,
    target_id integer NOT NULL,
    type character varying(20) NOT NULL,
    anonymous boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.feedback_requests OWNER TO taf;

--
-- Name: feedback_requests_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.feedback_requests_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.feedback_requests_id_seq OWNER TO taf;

--
-- Name: feedback_requests_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.feedback_requests_id_seq OWNED BY public.feedback_requests.id;


--
-- Name: field_definitions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.field_definitions (
    id integer NOT NULL,
    form_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    label character varying(100) NOT NULL,
    field_name character varying(100) NOT NULL,
    field_type character varying(50) NOT NULL,
    options json,
    is_required boolean DEFAULT false NOT NULL,
    order_index integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.field_definitions OWNER TO taf;

--
-- Name: field_definitions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.field_definitions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.field_definitions_id_seq OWNER TO taf;

--
-- Name: field_definitions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.field_definitions_id_seq OWNED BY public.field_definitions.id;


--
-- Name: final_settlements; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.final_settlements (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    exit_id integer NOT NULL,
    outstanding_salary numeric(10,2) DEFAULT 0.00,
    unused_leave numeric(10,2) DEFAULT 0.00,
    deductions numeric(10,2) DEFAULT 0.00,
    net_amount numeric(10,2) DEFAULT 0.00,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.final_settlements OWNER TO taf;

--
-- Name: final_settlements_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.final_settlements_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.final_settlements_id_seq OWNER TO taf;

--
-- Name: final_settlements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.final_settlements_id_seq OWNED BY public.final_settlements.id;


--
-- Name: fishbone_diagrams; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.fishbone_diagrams (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    problem character varying(255) NOT NULL,
    categories jsonb,
    diagram_data jsonb,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.fishbone_diagrams OWNER TO taf;

--
-- Name: fishbone_diagrams_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.fishbone_diagrams_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.fishbone_diagrams_id_seq OWNER TO taf;

--
-- Name: fishbone_diagrams_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.fishbone_diagrams_id_seq OWNED BY public.fishbone_diagrams.id;


--
-- Name: form_buttons; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_buttons (
    id integer NOT NULL,
    form_id integer NOT NULL,
    label character varying(100) NOT NULL,
    action_type character varying(50) NOT NULL,
    action_payload text,
    order_index integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_buttons OWNER TO taf;

--
-- Name: form_buttons_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_buttons_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_buttons_id_seq OWNER TO taf;

--
-- Name: form_buttons_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_buttons_id_seq OWNED BY public.form_buttons.id;


--
-- Name: form_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_categories (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_categories OWNER TO taf;

--
-- Name: form_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_categories_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_categories_id_seq OWNER TO taf;

--
-- Name: form_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_categories_id_seq OWNED BY public.form_categories.id;


--
-- Name: form_certificates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_certificates (
    id integer NOT NULL,
    form_id integer NOT NULL,
    submission_id integer NOT NULL,
    template_id integer NOT NULL,
    status character varying(100) DEFAULT NULL::character varying,
    issued_at date,
    expiry_date date,
    file_path text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_certificates OWNER TO taf;

--
-- Name: form_certificates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_certificates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_certificates_id_seq OWNER TO taf;

--
-- Name: form_certificates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_certificates_id_seq OWNED BY public.form_certificates.id;


--
-- Name: form_definitions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_definitions (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    base_form_id integer,
    name character varying(100) NOT NULL,
    description text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_definitions OWNER TO taf;

--
-- Name: form_definitions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_definitions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_definitions_id_seq OWNER TO taf;

--
-- Name: form_definitions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_definitions_id_seq OWNED BY public.form_definitions.id;


--
-- Name: form_submission_reviews; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_submission_reviews (
    id integer NOT NULL,
    submission_id integer NOT NULL,
    reviewer_id integer NOT NULL,
    review_date date,
    status character varying(50) DEFAULT 'pending'::character varying,
    notes text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_submission_reviews OWNER TO taf;

--
-- Name: form_submission_reviews_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_submission_reviews_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_submission_reviews_id_seq OWNER TO taf;

--
-- Name: form_submission_reviews_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_submission_reviews_id_seq OWNED BY public.form_submission_reviews.id;


--
-- Name: form_submission_values; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_submission_values (
    id integer NOT NULL,
    submission_id integer NOT NULL,
    element_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    value text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_submission_values OWNER TO taf;

--
-- Name: form_submission_values_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_submission_values_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_submission_values_id_seq OWNER TO taf;

--
-- Name: form_submission_values_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_submission_values_id_seq OWNED BY public.form_submission_values.id;


--
-- Name: form_submissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_submissions (
    id integer NOT NULL,
    form_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    submitted_by integer,
    submitted_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_submissions OWNER TO taf;

--
-- Name: form_submissions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_submissions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_submissions_id_seq OWNER TO taf;

--
-- Name: form_submissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_submissions_id_seq OWNED BY public.form_submissions.id;


--
-- Name: form_wizard_steps; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_wizard_steps (
    id integer NOT NULL,
    wizard_id integer NOT NULL,
    step_number integer NOT NULL,
    form_id integer NOT NULL,
    condition_field character varying(100) DEFAULT NULL::character varying,
    condition_value character varying(100) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_wizard_steps OWNER TO taf;

--
-- Name: form_wizard_steps_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_wizard_steps_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_wizard_steps_id_seq OWNER TO taf;

--
-- Name: form_wizard_steps_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_wizard_steps_id_seq OWNED BY public.form_wizard_steps.id;


--
-- Name: form_wizards; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.form_wizards (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.form_wizards OWNER TO taf;

--
-- Name: form_wizards_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.form_wizards_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.form_wizards_id_seq OWNER TO taf;

--
-- Name: form_wizards_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.form_wizards_id_seq OWNED BY public.form_wizards.id;


--
-- Name: forms; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.forms (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    category_id integer,
    name character varying(100) NOT NULL,
    description text,
    mapped_table character varying(100) DEFAULT NULL::character varying,
    on_submit_workflow_id integer,
    columns integer DEFAULT 1 NOT NULL,
    layout_type character varying(10) DEFAULT 'grid'::character varying NOT NULL,
    elements jsonb,
    share_scope character varying(16) DEFAULT 'none'::character varying NOT NULL,
    share_slug text,
    share_enabled boolean DEFAULT false NOT NULL,
    share_published_at timestamp with time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.forms OWNER TO taf;

--
-- Name: forms_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.forms_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.forms_id_seq OWNER TO taf;

--
-- Name: forms_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.forms_id_seq OWNED BY public.forms.id;


--
-- Name: goal_alignment; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.goal_alignment (
    id integer NOT NULL,
    parent_goal_id integer,
    child_goal_id integer NOT NULL,
    department_id integer,
    strategy_id integer,
    tenant_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.goal_alignment OWNER TO taf;

--
-- Name: goal_alignment_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.goal_alignment_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.goal_alignment_id_seq OWNER TO taf;

--
-- Name: goal_alignment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.goal_alignment_id_seq OWNED BY public.goal_alignment.id;


--
-- Name: goal_documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.goal_documents (
    id integer NOT NULL,
    goal_id integer NOT NULL,
    document_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.goal_documents OWNER TO taf;

--
-- Name: goal_documents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.goal_documents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.goal_documents_id_seq OWNER TO taf;

--
-- Name: goal_documents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.goal_documents_id_seq OWNED BY public.goal_documents.id;


--
-- Name: goal_milestones; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.goal_milestones (
    id integer NOT NULL,
    goal_id integer NOT NULL,
    milestone character varying(255) NOT NULL,
    due_date date,
    progress_pct numeric(5,2) DEFAULT 0.00,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.goal_milestones OWNER TO taf;

--
-- Name: goal_milestones_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.goal_milestones_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.goal_milestones_id_seq OWNER TO taf;

--
-- Name: goal_milestones_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.goal_milestones_id_seq OWNED BY public.goal_milestones.id;


--
-- Name: goal_score_labels; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.goal_score_labels (
    id integer NOT NULL,
    country_code character varying(5) NOT NULL,
    score_value integer NOT NULL,
    label character varying(100) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.goal_score_labels OWNER TO taf;

--
-- Name: goal_score_labels_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.goal_score_labels_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.goal_score_labels_id_seq OWNER TO taf;

--
-- Name: goal_score_labels_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.goal_score_labels_id_seq OWNED BY public.goal_score_labels.id;


--
-- Name: goal_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.goal_templates (
    id integer NOT NULL,
    tenant_id integer,
    department_id integer,
    role_id integer,
    title character varying(255) NOT NULL,
    description text,
    kpi_id integer,
    language_code character varying(10) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.goal_templates OWNER TO taf;

--
-- Name: goal_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.goal_templates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.goal_templates_id_seq OWNER TO taf;

--
-- Name: goal_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.goal_templates_id_seq OWNED BY public.goal_templates.id;


--
-- Name: goods_receipts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.goods_receipts (
    goods_receipt_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    purchase_order_id uuid NOT NULL,
    received_date date NOT NULL,
    quantity_received integer NOT NULL,
    notes text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.goods_receipts OWNER TO taf;

--
-- Name: graphs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.graphs (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    config jsonb DEFAULT '{"groupBy": "", "timeUnit": "", "aggregateFunc": ""}'::jsonb,
    tenant_id integer,
    branch_id integer,
    createdat timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.graphs OWNER TO taf;

--
-- Name: graphs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.graphs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.graphs_id_seq OWNER TO taf;

--
-- Name: graphs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.graphs_id_seq OWNED BY public.graphs.id;


--
-- Name: group_column_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.group_column_permissions (
    group_column_permission_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    group_id uuid NOT NULL,
    table_name text NOT NULL,
    column_name text NOT NULL,
    access_mode text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT group_column_permissions_access_mode_check CHECK ((access_mode = ANY (ARRAY['hidden'::text, 'readonly'::text, 'readwrite'::text])))
);


ALTER TABLE public.group_column_permissions OWNER TO taf;

--
-- Name: group_module_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.group_module_permissions (
    group_module_permission_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    group_id uuid NOT NULL,
    module_id uuid NOT NULL,
    action text DEFAULT 'allow'::text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.group_module_permissions OWNER TO taf;

--
-- Name: group_table_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.group_table_permissions (
    group_table_permission_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    group_id uuid NOT NULL,
    table_name text NOT NULL,
    access_mode text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT group_table_permissions_access_mode_check CHECK ((access_mode = ANY (ARRAY['hidden'::text, 'readonly'::text, 'readwrite'::text])))
);


ALTER TABLE public.group_table_permissions OWNER TO taf;

--
-- Name: groups; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.groups (
    group_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    parent_group_id uuid,
    org_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.groups OWNER TO taf;

--
-- Name: idp_providers; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.idp_providers (
    provider_code text NOT NULL,
    kind text NOT NULL,
    name text NOT NULL,
    CONSTRAINT idp_providers_kind_check CHECK ((kind = ANY (ARRAY['OIDC'::text, 'LDAP'::text])))
);


ALTER TABLE public.idp_providers OWNER TO taf;

--
-- Name: import_export_configs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.import_export_configs (
    config_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name text NOT NULL,
    description text,
    type text NOT NULL,
    table_name text NOT NULL,
    config jsonb NOT NULL,
    org_id uuid,
    created_by uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    createdat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT import_export_configs_type_check CHECK ((type = ANY (ARRAY['import'::text, 'export'::text, 'both'::text])))
);


ALTER TABLE public.import_export_configs OWNER TO taf;

--
-- Name: TABLE import_export_configs; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON TABLE public.import_export_configs IS 'Import/export configurations for POS transactions stored in sales_receipts and lineitems_payments tables';


--
-- Name: COLUMN import_export_configs.config; Type: COMMENT; Schema: public; Owner: taf
--

COMMENT ON COLUMN public.import_export_configs.config IS 'JSON configuration including field mappings, transformations, validations, etc.';


--
-- Name: incident_alert_rules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.incident_alert_rules (
    id integer NOT NULL,
    incident_type_id integer,
    severity character varying(50) DEFAULT NULL::character varying,
    location_id integer,
    send_alert_to integer,
    email character varying(255) DEFAULT NULL::character varying,
    send_email boolean DEFAULT false,
    phone character varying(50) DEFAULT NULL::character varying,
    send_sms boolean DEFAULT false,
    send_push boolean DEFAULT false,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.incident_alert_rules OWNER TO taf;

--
-- Name: incident_alert_rules_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.incident_alert_rules_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.incident_alert_rules_id_seq OWNER TO taf;

--
-- Name: incident_alert_rules_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.incident_alert_rules_id_seq OWNED BY public.incident_alert_rules.id;


--
-- Name: ingredients; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ingredients (
    ingredients_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name text,
    description text,
    quantity numeric(8,2) DEFAULT NULL::numeric,
    units text,
    price numeric(8,2) DEFAULT NULL::numeric,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ingredients OWNER TO taf;

--
-- Name: ingredients_to_products; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ingredients_to_products (
    ingredients_to_products_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    ingredients_id uuid,
    product_id uuid,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ingredients_to_products OWNER TO taf;

--
-- Name: inspection_assignment_rules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.inspection_assignment_rules (
    id integer NOT NULL,
    district_id integer,
    email character varying(255) DEFAULT NULL::character varying,
    send_email boolean DEFAULT false NOT NULL,
    phone character varying(50) DEFAULT NULL::character varying,
    send_sms boolean DEFAULT false NOT NULL,
    send_push boolean DEFAULT false NOT NULL,
    inspector_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.inspection_assignment_rules OWNER TO taf;

--
-- Name: inspection_assignment_rules_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.inspection_assignment_rules_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.inspection_assignment_rules_id_seq OWNER TO taf;

--
-- Name: inspection_assignment_rules_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.inspection_assignment_rules_id_seq OWNED BY public.inspection_assignment_rules.id;


--
-- Name: inspection_requests; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.inspection_requests (
    id integer NOT NULL,
    workplace_id integer,
    description text,
    preferred_date date,
    status character varying DEFAULT 'Pending'::character varying,
    requested_by integer,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.inspection_requests OWNER TO taf;

--
-- Name: inspection_requests_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.inspection_requests_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.inspection_requests_id_seq OWNER TO taf;

--
-- Name: inspection_requests_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.inspection_requests_id_seq OWNED BY public.inspection_requests.id;


--
-- Name: interview_logs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.interview_logs (
    id integer NOT NULL,
    case_id integer NOT NULL,
    person character varying(255) NOT NULL,
    notes text,
    logged_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.interview_logs OWNER TO taf;

--
-- Name: interview_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.interview_logs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.interview_logs_id_seq OWNER TO taf;

--
-- Name: interview_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.interview_logs_id_seq OWNED BY public.interview_logs.id;


--
-- Name: interviewers; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.interviewers (
    interviewer_id uuid NOT NULL,
    interview_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.interviewers OWNER TO taf;

--
-- Name: interviews; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.interviews (
    interview_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    application_id uuid NOT NULL,
    interview_date date NOT NULL,
    status character varying(100) DEFAULT 'Scheduled'::character varying,
    notes text,
    feedback text,
    interview_number integer NOT NULL,
    rating integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT interviews_rating_check CHECK (((rating >= 1) AND (rating <= 5)))
);


ALTER TABLE public.interviews OWNER TO taf;

--
-- Name: inventory; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.inventory (
    inventory_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_batch_number_id uuid NOT NULL,
    branch_id uuid,
    warehouse_id uuid,
    reference_id uuid,
    reference_table text,
    current_qty integer NOT NULL,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.inventory OWNER TO taf;

--
-- Name: inventory_receive; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.inventory_receive (
    inventory_receive_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    truck text,
    branch_id uuid,
    vendor_id uuid,
    org_id uuid,
    user_id uuid,
    date timestamp with time zone,
    delivery_note_number text,
    lpo_id uuid,
    lpo_number text,
    invoice_number text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.inventory_receive OWNER TO taf;

--
-- Name: inventory_txn; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.inventory_txn (
    inventory_txn_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid,
    change integer NOT NULL,
    branch_id uuid,
    user_id uuid,
    reference_id uuid,
    org_id uuid,
    reference_table text,
    reason text NOT NULL,
    data jsonb,
    processed_at timestamp with time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.inventory_txn OWNER TO taf;

--
-- Name: invitations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.invitations (
    invitation_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    inviter_user_id uuid,
    email public.citext NOT NULL,
    root_org_id uuid,
    org_id uuid,
    role text,
    message text,
    expires_at timestamp with time zone NOT NULL,
    accepted_at timestamp with time zone,
    revoked_at timestamp with time zone
);


ALTER TABLE public.invitations OWNER TO taf;

--
-- Name: invoice_payments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.invoice_payments (
    id integer NOT NULL,
    invoice_id integer,
    request_id integer,
    amount double precision,
    paymenttype character varying(100) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.invoice_payments OWNER TO taf;

--
-- Name: invoice_payments_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.invoice_payments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.invoice_payments_id_seq OWNER TO taf;

--
-- Name: invoice_payments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.invoice_payments_id_seq OWNED BY public.invoice_payments.id;


--
-- Name: invoice_settings; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.invoice_settings (
    id integer NOT NULL,
    tenant_id integer,
    template_id integer,
    case_template_id integer,
    logo_document_id integer,
    name character varying(100) DEFAULT NULL::character varying,
    instructions text,
    disclaimer text,
    bank_details text,
    number_format character varying(50) DEFAULT NULL::character varying,
    starting_number integer,
    rollover_date date,
    isdeleted boolean DEFAULT false,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.invoice_settings OWNER TO taf;

--
-- Name: invoice_settings_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.invoice_settings_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.invoice_settings_id_seq OWNER TO taf;

--
-- Name: invoice_settings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.invoice_settings_id_seq OWNED BY public.invoice_settings.id;


--
-- Name: invoice_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.invoice_templates (
    invoice_template_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name character varying(100) NOT NULL,
    file_path text NOT NULL,
    tenant_id integer,
    isdeleted boolean DEFAULT false,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.invoice_templates OWNER TO taf;

--
-- Name: invoice_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.invoice_types (
    invoice_type_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name character varying(100) NOT NULL,
    description text,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.invoice_types OWNER TO taf;

--
-- Name: invoices; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.invoices (
    invoice_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    type_id uuid,
    name text,
    reference_table text,
    reference_id uuid,
    invoice_template_id uuid,
    invoice_date date DEFAULT now() NOT NULL,
    number_format text,
    starting_number text,
    details text,
    tax text,
    invoice_number text,
    amount numeric(10,2) DEFAULT 0,
    amount_paid numeric(10,2) DEFAULT 0,
    status text,
    sent_at timestamp with time zone,
    line_items jsonb,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.invoices OWNER TO taf;

--
-- Name: items; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.items (
    item_id uuid DEFAULT public.uuid_generate_v7(),
    org_id uuid,
    itemname character varying(255) NOT NULL,
    price numeric(10,2) NOT NULL,
    vatpercent integer NOT NULL,
    vatincluded character varying(3) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT items_vatincluded_check CHECK (((vatincluded)::text = ANY ((ARRAY['Yes'::character varying, 'No'::character varying])::text[]))),
    CONSTRAINT items_vatpercent_check CHECK ((vatpercent = ANY (ARRAY[0, 5, 10, 15, 18, 20])))
);


ALTER TABLE public.items OWNER TO taf;

--
-- Name: job_opening_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.job_opening_templates (
    id integer NOT NULL,
    tenant_id integer,
    name character varying(255) NOT NULL,
    description text,
    form_fields json,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.job_opening_templates OWNER TO taf;

--
-- Name: job_opening_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.job_opening_templates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.job_opening_templates_id_seq OWNER TO taf;

--
-- Name: job_opening_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.job_opening_templates_id_seq OWNED BY public.job_opening_templates.id;


--
-- Name: kanban_boards; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.kanban_boards (
    id integer NOT NULL,
    project_id integer,
    tenant_id integer,
    branch_id integer,
    calendar_category_id integer,
    name character varying(255) NOT NULL,
    description text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.kanban_boards OWNER TO taf;

--
-- Name: kanban_boards_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.kanban_boards_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.kanban_boards_id_seq OWNER TO taf;

--
-- Name: kanban_boards_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.kanban_boards_id_seq OWNED BY public.kanban_boards.id;


--
-- Name: kanban_columns; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.kanban_columns (
    id integer NOT NULL,
    board_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    title character varying(255) NOT NULL,
    "position" integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.kanban_columns OWNER TO taf;

--
-- Name: kanban_columns_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.kanban_columns_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.kanban_columns_id_seq OWNER TO taf;

--
-- Name: kanban_columns_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.kanban_columns_id_seq OWNED BY public.kanban_columns.id;


--
-- Name: kanban_comments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.kanban_comments (
    id integer NOT NULL,
    task_id integer NOT NULL,
    user_id integer NOT NULL,
    comment text NOT NULL,
    tenant_id integer,
    branch_id integer,
    created_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.kanban_comments OWNER TO taf;

--
-- Name: kanban_comments_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.kanban_comments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.kanban_comments_id_seq OWNER TO taf;

--
-- Name: kanban_comments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.kanban_comments_id_seq OWNED BY public.kanban_comments.id;


--
-- Name: kanban_tasks; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.kanban_tasks (
    id integer NOT NULL,
    column_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    title character varying(255) NOT NULL,
    description text,
    assignee_id integer,
    due_date date,
    record_table character varying(255) DEFAULT NULL::character varying,
    record_id integer,
    status character varying(50) DEFAULT 'pending'::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.kanban_tasks OWNER TO taf;

--
-- Name: kanban_tasks_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.kanban_tasks_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.kanban_tasks_id_seq OWNER TO taf;

--
-- Name: kanban_tasks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.kanban_tasks_id_seq OWNED BY public.kanban_tasks.id;


--
-- Name: leave_balances; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.leave_balances (
    leave_balance_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    user_id uuid NOT NULL,
    org_id uuid,
    leave_type_id uuid,
    balance numeric(5,2) DEFAULT 0 NOT NULL,
    "isDeleted" boolean DEFAULT false NOT NULL,
    "updatedAt" timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.leave_balances OWNER TO taf;

--
-- Name: leave_requests; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.leave_requests (
    leave_request_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    user_id uuid,
    org_id uuid,
    leavetype character varying(50) DEFAULT NULL::character varying,
    startdate date,
    enddate date,
    reason text,
    status character varying(20) DEFAULT 'Pending'::character varying NOT NULL,
    approvedat timestamp with time zone,
    approvedby uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.leave_requests OWNER TO taf;

--
-- Name: leave_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.leave_types (
    leave_type_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name character varying(100) NOT NULL,
    code character varying(10) NOT NULL,
    org_id uuid,
    description text,
    daysperyear integer NOT NULL,
    accrualtype character varying(50) NOT NULL,
    carryforward boolean DEFAULT false NOT NULL,
    maxcarry integer,
    approvalrequired boolean DEFAULT true NOT NULL,
    paid boolean DEFAULT true NOT NULL,
    active boolean DEFAULT true NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.leave_types OWNER TO taf;

--
-- Name: legacy_resources; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.legacy_resources (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.legacy_resources OWNER TO taf;

--
-- Name: legacy_resources_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.legacy_resources_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.legacy_resources_id_seq OWNER TO taf;

--
-- Name: legacy_resources_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.legacy_resources_id_seq OWNED BY public.legacy_resources.id;


--
-- Name: line_items; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.line_items (
    id integer NOT NULL,
    invoice_id integer,
    request_id integer,
    name character varying(200) DEFAULT NULL::character varying,
    quantity integer,
    unitprice integer,
    labels character varying(200) DEFAULT NULL::character varying,
    totalamount integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.line_items OWNER TO taf;

--
-- Name: line_items_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.line_items_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.line_items_id_seq OWNER TO taf;

--
-- Name: line_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.line_items_id_seq OWNED BY public.line_items.id;


--
-- Name: lineitems_payments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.lineitems_payments (
    sales_receipt_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    line_items jsonb,
    payments jsonb,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.lineitems_payments OWNER TO taf;

--
-- Name: locations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.locations (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    latitude numeric(10,6) DEFAULT NULL::numeric,
    longitude numeric(10,6) DEFAULT NULL::numeric,
    radius_m integer DEFAULT 50 NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.locations OWNER TO taf;

--
-- Name: locations_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.locations_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.locations_id_seq OWNER TO taf;

--
-- Name: locations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.locations_id_seq OWNED BY public.locations.id;


--
-- Name: meeting_links; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.meeting_links (
    id integer NOT NULL,
    event_id integer NOT NULL,
    url character varying(255) NOT NULL,
    created_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.meeting_links OWNER TO taf;

--
-- Name: meeting_links_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.meeting_links_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.meeting_links_id_seq OWNER TO taf;

--
-- Name: meeting_links_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.meeting_links_id_seq OWNED BY public.meeting_links.id;


--
-- Name: models; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.models (
    model_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    model_name text NOT NULL,
    table_name text NOT NULL,
    primary_key text NOT NULL,
    fields jsonb NOT NULL,
    joins jsonb,
    calculated_fields jsonb,
    metadata jsonb,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.models OWNER TO taf;

--
-- Name: modules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.modules (
    module_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    parent_module_id uuid,
    name character varying(255) NOT NULL,
    config jsonb,
    org_id uuid,
    icon character varying(50) DEFAULT NULL::character varying,
    branch_id integer,
    aria_label character varying(255) DEFAULT NULL::character varying,
    description text,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.modules OWNER TO taf;

--
-- Name: notification_log; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.notification_log (
    id integer NOT NULL,
    type character varying(50) NOT NULL,
    recipient character varying(255) NOT NULL,
    subject character varying(255) DEFAULT NULL::character varying,
    message text,
    status character varying(20) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.notification_log OWNER TO taf;

--
-- Name: notification_log_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.notification_log_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.notification_log_id_seq OWNER TO taf;

--
-- Name: notification_log_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.notification_log_id_seq OWNED BY public.notification_log.id;


--
-- Name: notification_queue; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.notification_queue (
    id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    tenant_id uuid,
    branch_id uuid,
    user_id uuid,
    entity character varying(50) NOT NULL,
    record_id uuid,
    event_type character varying(20) NOT NULL,
    payload jsonb,
    status character varying(20) DEFAULT 'queued'::character varying NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.notification_queue OWNER TO taf;

--
-- Name: numbering_sequences; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.numbering_sequences (
    org_id uuid NOT NULL,
    type text NOT NULL,
    year integer NOT NULL,
    next_seq integer DEFAULT 1 NOT NULL
);


ALTER TABLE public.numbering_sequences OWNER TO taf;

--
-- Name: ohs_action_signoffs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_action_signoffs (
    id integer NOT NULL,
    item_id integer NOT NULL,
    item_type character varying(20) NOT NULL,
    user_id integer NOT NULL,
    signature text,
    document_id integer,
    signed_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_action_signoffs OWNER TO taf;

--
-- Name: ohs_action_signoffs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_action_signoffs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_action_signoffs_id_seq OWNER TO taf;

--
-- Name: ohs_action_signoffs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_action_signoffs_id_seq OWNED BY public.ohs_action_signoffs.id;


--
-- Name: ohs_actions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_actions (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    description text,
    responsible_user_id integer,
    target_date date,
    status character varying(50) DEFAULT NULL::character varying,
    completed_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_actions OWNER TO taf;

--
-- Name: ohs_actions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_actions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_actions_id_seq OWNER TO taf;

--
-- Name: ohs_actions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_actions_id_seq OWNED BY public.ohs_actions.id;


--
-- Name: ohs_assignment_rules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_assignment_rules (
    id integer NOT NULL,
    location character varying(100) DEFAULT NULL::character varying,
    type character varying(50) DEFAULT NULL::character varying,
    severity character varying(50) DEFAULT NULL::character varying,
    location_id integer,
    investigator_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_assignment_rules OWNER TO taf;

--
-- Name: ohs_assignment_rules_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_assignment_rules_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_assignment_rules_id_seq OWNER TO taf;

--
-- Name: ohs_assignment_rules_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_assignment_rules_id_seq OWNED BY public.ohs_assignment_rules.id;


--
-- Name: ohs_compliance_logs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_compliance_logs (
    id integer NOT NULL,
    task_id integer NOT NULL,
    log_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    notes text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_compliance_logs OWNER TO taf;

--
-- Name: ohs_compliance_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_compliance_logs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_compliance_logs_id_seq OWNER TO taf;

--
-- Name: ohs_compliance_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_compliance_logs_id_seq OWNED BY public.ohs_compliance_logs.id;


--
-- Name: ohs_compliance_tasks; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_compliance_tasks (
    id integer NOT NULL,
    regulation_id integer,
    title character varying(255) NOT NULL,
    due_date timestamp without time zone,
    assigned_to integer,
    status character varying(100) DEFAULT 'pending'::character varying,
    reminder_sent boolean DEFAULT false,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_compliance_tasks OWNER TO taf;

--
-- Name: ohs_compliance_tasks_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_compliance_tasks_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_compliance_tasks_id_seq OWNER TO taf;

--
-- Name: ohs_compliance_tasks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_compliance_tasks_id_seq OWNED BY public.ohs_compliance_tasks.id;


--
-- Name: ohs_emergency_contacts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_emergency_contacts (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    contact_name character varying(255) NOT NULL,
    phone character varying(50) NOT NULL,
    relation character varying(100) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    pendingsync boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_emergency_contacts OWNER TO taf;

--
-- Name: ohs_emergency_contacts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_emergency_contacts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_emergency_contacts_id_seq OWNER TO taf;

--
-- Name: ohs_emergency_contacts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_emergency_contacts_id_seq OWNED BY public.ohs_emergency_contacts.id;


--
-- Name: ohs_emergency_drills; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_emergency_drills (
    id integer NOT NULL,
    drill_type character varying(100) NOT NULL,
    scheduled_for timestamp without time zone NOT NULL,
    conducted_by integer,
    notes text,
    tenant_id integer,
    branch_id integer,
    reminder_sent boolean DEFAULT false,
    pendingsync boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_emergency_drills OWNER TO taf;

--
-- Name: ohs_emergency_drills_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_emergency_drills_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_emergency_drills_id_seq OWNER TO taf;

--
-- Name: ohs_emergency_drills_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_emergency_drills_id_seq OWNED BY public.ohs_emergency_drills.id;


--
-- Name: ohs_fault_trees; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_fault_trees (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    tree_data jsonb,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_fault_trees OWNER TO taf;

--
-- Name: ohs_fault_trees_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_fault_trees_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_fault_trees_id_seq OWNER TO taf;

--
-- Name: ohs_fault_trees_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_fault_trees_id_seq OWNED BY public.ohs_fault_trees.id;


--
-- Name: ohs_field_incidents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_field_incidents (
    id integer NOT NULL,
    incident_type character varying(100) DEFAULT NULL::character varying,
    location character varying(255) DEFAULT NULL::character varying,
    description text,
    document_ids character varying(255) DEFAULT NULL::character varying,
    gps character varying(255) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_field_incidents OWNER TO taf;

--
-- Name: ohs_field_incidents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_field_incidents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_field_incidents_id_seq OWNER TO taf;

--
-- Name: ohs_field_incidents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_field_incidents_id_seq OWNED BY public.ohs_field_incidents.id;


--
-- Name: ohs_five_whys; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_five_whys (
    id integer NOT NULL,
    incident_id integer,
    whys jsonb NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.ohs_five_whys OWNER TO taf;

--
-- Name: ohs_five_whys_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_five_whys_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_five_whys_id_seq OWNER TO taf;

--
-- Name: ohs_five_whys_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_five_whys_id_seq OWNED BY public.ohs_five_whys.id;


--
-- Name: ohs_hazard_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_hazard_types (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_hazard_types OWNER TO taf;

--
-- Name: ohs_hazard_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_hazard_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_hazard_types_id_seq OWNER TO taf;

--
-- Name: ohs_hazard_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_hazard_types_id_seq OWNED BY public.ohs_hazard_types.id;


--
-- Name: ohs_hazards; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_hazards (
    id integer NOT NULL,
    description text,
    location character varying(255) DEFAULT NULL::character varying,
    hazard_type_id integer,
    severity integer,
    probability integer,
    risk_level integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_hazards OWNER TO taf;

--
-- Name: ohs_hazards_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_hazards_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_hazards_id_seq OWNER TO taf;

--
-- Name: ohs_hazards_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_hazards_id_seq OWNED BY public.ohs_hazards.id;


--
-- Name: ohs_health_checks; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_health_checks (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    check_type character varying(100) NOT NULL,
    result text,
    check_date date NOT NULL,
    notes text,
    tenant_id integer,
    branch_id integer,
    pendingsync boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_health_checks OWNER TO taf;

--
-- Name: ohs_health_checks_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_health_checks_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_health_checks_id_seq OWNER TO taf;

--
-- Name: ohs_health_checks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_health_checks_id_seq OWNED BY public.ohs_health_checks.id;


--
-- Name: ohs_incident_custom_fields; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incident_custom_fields (
    id integer NOT NULL,
    tenant_id integer NOT NULL,
    branch_id integer,
    field_name character varying(100) NOT NULL,
    field_type character varying(50) NOT NULL,
    is_required boolean DEFAULT false NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_incident_custom_fields OWNER TO taf;

--
-- Name: ohs_incident_custom_fields_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incident_custom_fields_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incident_custom_fields_id_seq OWNER TO taf;

--
-- Name: ohs_incident_custom_fields_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incident_custom_fields_id_seq OWNED BY public.ohs_incident_custom_fields.id;


--
-- Name: ohs_incident_files; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incident_files (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    file_path character varying(255) DEFAULT NULL::character varying,
    uploaded_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_incident_files OWNER TO taf;

--
-- Name: ohs_incident_files_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incident_files_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incident_files_id_seq OWNER TO taf;

--
-- Name: ohs_incident_files_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incident_files_id_seq OWNED BY public.ohs_incident_files.id;


--
-- Name: ohs_incident_logs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incident_logs (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    action character varying(50) NOT NULL,
    details text,
    user_id integer,
    logged_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_incident_logs OWNER TO taf;

--
-- Name: ohs_incident_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incident_logs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incident_logs_id_seq OWNER TO taf;

--
-- Name: ohs_incident_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incident_logs_id_seq OWNED BY public.ohs_incident_logs.id;


--
-- Name: ohs_incident_signoffs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incident_signoffs (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    user_id integer NOT NULL,
    signature text,
    document_id integer,
    signed_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_incident_signoffs OWNER TO taf;

--
-- Name: ohs_incident_signoffs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incident_signoffs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incident_signoffs_id_seq OWNER TO taf;

--
-- Name: ohs_incident_signoffs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incident_signoffs_id_seq OWNED BY public.ohs_incident_signoffs.id;


--
-- Name: ohs_incident_statuses; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incident_statuses (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    purpose text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_incident_statuses OWNER TO taf;

--
-- Name: ohs_incident_statuses_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incident_statuses_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incident_statuses_id_seq OWNER TO taf;

--
-- Name: ohs_incident_statuses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incident_statuses_id_seq OWNED BY public.ohs_incident_statuses.id;


--
-- Name: ohs_incident_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incident_types (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    form_id integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_incident_types OWNER TO taf;

--
-- Name: ohs_incident_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incident_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incident_types_id_seq OWNER TO taf;

--
-- Name: ohs_incident_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incident_types_id_seq OWNED BY public.ohs_incident_types.id;


--
-- Name: ohs_incidents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_incidents (
    id integer NOT NULL,
    date date,
    "time" character varying(255) DEFAULT NULL::character varying,
    location character varying(255) DEFAULT NULL::character varying,
    nature character varying(255) DEFAULT NULL::character varying,
    short_description character varying(255) DEFAULT NULL::character varying,
    classification character varying(100) DEFAULT 'injury'::character varying NOT NULL,
    severity character varying(100) DEFAULT NULL::character varying,
    investigator_id integer,
    reviewer_id integer,
    status character varying(50) DEFAULT 'reported'::character varying,
    submitted_by integer,
    form_data jsonb,
    tenant_id integer,
    branch_id integer,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.ohs_incidents OWNER TO taf;

--
-- Name: ohs_incidents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_incidents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_incidents_id_seq OWNER TO taf;

--
-- Name: ohs_incidents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_incidents_id_seq OWNED BY public.ohs_incidents.id;


--
-- Name: ohs_inspection_audits; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_inspection_audits (
    id integer NOT NULL,
    inspection_id integer NOT NULL,
    action character varying(20) NOT NULL,
    changed_fields text,
    user_id integer NOT NULL,
    performed_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_inspection_audits OWNER TO taf;

--
-- Name: ohs_inspection_audits_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_inspection_audits_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_inspection_audits_id_seq OWNER TO taf;

--
-- Name: ohs_inspection_audits_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_inspection_audits_id_seq OWNED BY public.ohs_inspection_audits.id;


--
-- Name: ohs_inspection_items; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_inspection_items (
    id integer NOT NULL,
    inspection_id integer NOT NULL,
    question character varying(255) NOT NULL,
    response character varying(100) DEFAULT NULL::character varying,
    notes text,
    corrective_action text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_inspection_items OWNER TO taf;

--
-- Name: ohs_inspection_items_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_inspection_items_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_inspection_items_id_seq OWNER TO taf;

--
-- Name: ohs_inspection_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_inspection_items_id_seq OWNED BY public.ohs_inspection_items.id;


--
-- Name: ohs_inspection_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_inspection_templates (
    id integer NOT NULL,
    template_name character varying(255) DEFAULT NULL::character varying,
    name character varying(100) DEFAULT NULL::character varying,
    form_id integer,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_inspection_templates OWNER TO taf;

--
-- Name: ohs_inspection_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_inspection_templates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_inspection_templates_id_seq OWNER TO taf;

--
-- Name: ohs_inspection_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_inspection_templates_id_seq OWNED BY public.ohs_inspection_templates.id;


--
-- Name: ohs_inspection_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_inspection_types (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    form_id integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_inspection_types OWNER TO taf;

--
-- Name: ohs_inspection_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_inspection_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_inspection_types_id_seq OWNER TO taf;

--
-- Name: ohs_inspection_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_inspection_types_id_seq OWNED BY public.ohs_inspection_types.id;


--
-- Name: ohs_inspections; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_inspections (
    id integer NOT NULL,
    date date NOT NULL,
    location character varying(255) DEFAULT NULL::character varying,
    short_description character varying(255) DEFAULT NULL::character varying,
    inspector_id integer,
    inspection_type_id integer,
    form_data jsonb,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_inspections OWNER TO taf;

--
-- Name: ohs_inspections_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_inspections_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_inspections_id_seq OWNER TO taf;

--
-- Name: ohs_inspections_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_inspections_id_seq OWNED BY public.ohs_inspections.id;


--
-- Name: ohs_issues; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_issues (
    id integer NOT NULL,
    description text,
    type character varying(100) DEFAULT NULL::character varying,
    category character varying(100) DEFAULT NULL::character varying,
    impact character varying(255) DEFAULT NULL::character varying,
    risk_or_opportunity character varying(255) DEFAULT NULL::character varying,
    action_taken text,
    owner character varying(100) DEFAULT NULL::character varying,
    review_date date,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_issues OWNER TO taf;

--
-- Name: ohs_issues_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_issues_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_issues_id_seq OWNER TO taf;

--
-- Name: ohs_issues_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_issues_id_seq OWNED BY public.ohs_issues.id;


--
-- Name: ohs_jsa_reviewers; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsa_reviewers (
    id integer NOT NULL,
    jsa_id integer NOT NULL,
    user_id integer NOT NULL,
    reviewed_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsa_reviewers OWNER TO taf;

--
-- Name: ohs_jsa_reviewers_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsa_reviewers_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsa_reviewers_id_seq OWNER TO taf;

--
-- Name: ohs_jsa_reviewers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsa_reviewers_id_seq OWNED BY public.ohs_jsa_reviewers.id;


--
-- Name: ohs_jsa_signoffs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsa_signoffs (
    id integer NOT NULL,
    jsa_id integer NOT NULL,
    user_id integer NOT NULL,
    signed_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsa_signoffs OWNER TO taf;

--
-- Name: ohs_jsa_signoffs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsa_signoffs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsa_signoffs_id_seq OWNER TO taf;

--
-- Name: ohs_jsa_signoffs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsa_signoffs_id_seq OWNED BY public.ohs_jsa_signoffs.id;


--
-- Name: ohs_jsa_step_files; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsa_step_files (
    id integer NOT NULL,
    jsa_step_id integer NOT NULL,
    document_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsa_step_files OWNER TO taf;

--
-- Name: ohs_jsa_step_files_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsa_step_files_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsa_step_files_id_seq OWNER TO taf;

--
-- Name: ohs_jsa_step_files_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsa_step_files_id_seq OWNED BY public.ohs_jsa_step_files.id;


--
-- Name: ohs_jsa_steps; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsa_steps (
    id integer NOT NULL,
    jsa_id integer NOT NULL,
    step_order integer,
    step text,
    hazard_id integer,
    responsible_user_id integer,
    likelihood integer,
    severity integer,
    risk_before integer,
    risk_after integer,
    controls text,
    control_type character varying(20) DEFAULT NULL::character varying,
    ppe_required json,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsa_steps OWNER TO taf;

--
-- Name: ohs_jsa_steps_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsa_steps_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsa_steps_id_seq OWNER TO taf;

--
-- Name: ohs_jsa_steps_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsa_steps_id_seq OWNED BY public.ohs_jsa_steps.id;


--
-- Name: ohs_jsa_training; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsa_training (
    id integer NOT NULL,
    jsa_id integer NOT NULL,
    employee_id integer NOT NULL,
    trained_at timestamp without time zone,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsa_training OWNER TO taf;

--
-- Name: ohs_jsa_training_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsa_training_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsa_training_id_seq OWNER TO taf;

--
-- Name: ohs_jsa_training_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsa_training_id_seq OWNED BY public.ohs_jsa_training.id;


--
-- Name: ohs_jsa_versions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsa_versions (
    id integer NOT NULL,
    jsa_id integer NOT NULL,
    version_no integer NOT NULL,
    data_json json NOT NULL,
    updated_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsa_versions OWNER TO taf;

--
-- Name: ohs_jsa_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsa_versions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsa_versions_id_seq OWNER TO taf;

--
-- Name: ohs_jsa_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsa_versions_id_seq OWNED BY public.ohs_jsa_versions.id;


--
-- Name: ohs_jsas; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_jsas (
    id integer NOT NULL,
    title character varying(255) NOT NULL,
    description text,
    doc_path character varying(255) DEFAULT NULL::character varying,
    location character varying(255) DEFAULT NULL::character varying,
    department_id integer,
    analysis_date date,
    review_date timestamp without time zone,
    prepared_by integer,
    team_member_ids json,
    permit_requirements json,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_jsas OWNER TO taf;

--
-- Name: ohs_jsas_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_jsas_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_jsas_id_seq OWNER TO taf;

--
-- Name: ohs_jsas_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_jsas_id_seq OWNED BY public.ohs_jsas.id;


--
-- Name: ohs_medicals; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_medicals (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    health_check_id integer,
    surname character varying(100) DEFAULT NULL::character varying,
    first_name character varying(100) DEFAULT NULL::character varying,
    other_initials character varying(100) DEFAULT NULL::character varying,
    sex character varying(10) DEFAULT NULL::character varying,
    address character varying(255) DEFAULT NULL::character varying,
    dob date,
    job_title character varying(100) DEFAULT NULL::character varying,
    occ_years integer,
    occ_months integer,
    occ_days integer,
    employment_status character varying(100) DEFAULT NULL::character varying,
    incident_date date,
    incident_time time without time zone,
    incident_type character varying(255) DEFAULT NULL::character varying,
    agency character varying(255) DEFAULT NULL::character varying,
    incident_description text,
    damage_location text,
    corrective_action character varying(255) DEFAULT NULL::character varying,
    action_date date,
    medical_treatment character varying(255) DEFAULT NULL::character varying,
    medical_practitioner character varying(255) DEFAULT NULL::character varying,
    date_notified date,
    incapacity_years integer,
    incapacity_months integer,
    incapacity_days integer,
    employer_signature character varying(255) DEFAULT NULL::character varying,
    employer_date date,
    employee_signature character varying(255) DEFAULT NULL::character varying,
    employee_date date,
    tenant_id integer,
    branch_id integer,
    pendingsync boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_medicals OWNER TO taf;

--
-- Name: ohs_medicals_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_medicals_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_medicals_id_seq OWNER TO taf;

--
-- Name: ohs_medicals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_medicals_id_seq OWNED BY public.ohs_medicals.id;


--
-- Name: ohs_needs_expectations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_needs_expectations (
    id integer NOT NULL,
    interested_party character varying(255) NOT NULL,
    needs text,
    expectations text,
    compliance_required boolean DEFAULT false,
    source character varying(255) DEFAULT NULL::character varying,
    status character varying(50) DEFAULT NULL::character varying,
    notes text,
    review_date date,
    review_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_needs_expectations OWNER TO taf;

--
-- Name: ohs_needs_expectations_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_needs_expectations_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_needs_expectations_id_seq OWNER TO taf;

--
-- Name: ohs_needs_expectations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_needs_expectations_id_seq OWNED BY public.ohs_needs_expectations.id;


--
-- Name: ohs_regulations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_regulations (
    id integer NOT NULL,
    title character varying(255) NOT NULL,
    description text,
    effective_date date,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_regulations OWNER TO taf;

--
-- Name: ohs_regulations_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_regulations_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_regulations_id_seq OWNER TO taf;

--
-- Name: ohs_regulations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_regulations_id_seq OWNED BY public.ohs_regulations.id;


--
-- Name: ohs_risk_matrices; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_risk_matrices (
    id integer NOT NULL,
    tenant_id integer NOT NULL,
    severity integer NOT NULL,
    probability integer NOT NULL,
    risk_value integer NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_risk_matrices OWNER TO taf;

--
-- Name: ohs_risk_matrices_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_risk_matrices_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_risk_matrices_id_seq OWNER TO taf;

--
-- Name: ohs_risk_matrices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_risk_matrices_id_seq OWNED BY public.ohs_risk_matrices.id;


--
-- Name: ohs_risk_reviews; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_risk_reviews (
    id integer NOT NULL,
    hazard_id integer NOT NULL,
    reviewer_id integer,
    review_date date,
    residual_risk integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_risk_reviews OWNER TO taf;

--
-- Name: ohs_risk_reviews_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_risk_reviews_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_risk_reviews_id_seq OWNER TO taf;

--
-- Name: ohs_risk_reviews_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_risk_reviews_id_seq OWNED BY public.ohs_risk_reviews.id;


--
-- Name: ohs_root_causes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_root_causes (
    id integer NOT NULL,
    incident_id integer NOT NULL,
    method character varying(100) DEFAULT NULL::character varying,
    analysis_notes text,
    checklist text,
    five_whys_id integer,
    fishbone_file_id integer,
    fault_tree_id integer,
    created_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_root_causes OWNER TO taf;

--
-- Name: ohs_root_causes_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_root_causes_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_root_causes_id_seq OWNER TO taf;

--
-- Name: ohs_root_causes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_root_causes_id_seq OWNED BY public.ohs_root_causes.id;


--
-- Name: ohs_severities; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_severities (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_severities OWNER TO taf;

--
-- Name: ohs_severities_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_severities_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_severities_id_seq OWNER TO taf;

--
-- Name: ohs_severities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_severities_id_seq OWNED BY public.ohs_severities.id;


--
-- Name: ohs_stakeholders; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_stakeholders (
    id integer NOT NULL,
    stakeholder_name character varying(255) NOT NULL,
    category character varying(100) DEFAULT NULL::character varying,
    role_influence text,
    needs_expectations text,
    impact text,
    communication_method character varying(100) DEFAULT NULL::character varying,
    review_date date,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_stakeholders OWNER TO taf;

--
-- Name: ohs_stakeholders_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_stakeholders_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_stakeholders_id_seq OWNER TO taf;

--
-- Name: ohs_stakeholders_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_stakeholders_id_seq OWNED BY public.ohs_stakeholders.id;


--
-- Name: ohs_training_requirements; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ohs_training_requirements (
    id integer NOT NULL,
    role_id integer,
    location_id integer,
    project_id integer,
    course_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.ohs_training_requirements OWNER TO taf;

--
-- Name: ohs_training_requirements_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ohs_training_requirements_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ohs_training_requirements_id_seq OWNER TO taf;

--
-- Name: ohs_training_requirements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ohs_training_requirements_id_seq OWNED BY public.ohs_training_requirements.id;


--
-- Name: one_time_service_costs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.one_time_service_costs (
    one_time_service_cost_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    reference_table text,
    reference_id uuid,
    date date,
    vendor_id uuid,
    invoice_number text,
    amount numeric(10,2) DEFAULT 0,
    vat_rate numeric(5,4) DEFAULT 0.125 NOT NULL,
    description text,
    status text DEFAULT 'Pending'::text,
    comments text,
    approved boolean DEFAULT false,
    billed_to_client boolean DEFAULT false,
    added_to_cost_schedule boolean DEFAULT false,
    billable boolean DEFAULT false NOT NULL,
    user_id uuid NOT NULL,
    document_ids text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.one_time_service_costs OWNER TO taf;

--
-- Name: one_time_tokens; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.one_time_tokens (
    token_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    user_id uuid,
    email public.citext,
    purpose public.token_purpose NOT NULL,
    token_hash text NOT NULL,
    expires_at timestamp with time zone NOT NULL,
    used_at timestamp with time zone
);


ALTER TABLE public.one_time_tokens OWNER TO taf;

--
-- Name: open_positions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.open_positions (
    open_position_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    title character varying(255) DEFAULT NULL::character varying,
    description character varying(255) DEFAULT NULL::character varying,
    branch_id uuid,
    "position" character varying(255) DEFAULT NULL::character varying,
    applicant_type character varying(100) DEFAULT 'All'::character varying,
    open_date date,
    close_date date,
    department text,
    qualifications text,
    salary numeric(10,2) DEFAULT NULL::numeric,
    status character varying(100) DEFAULT NULL::character varying,
    createdby integer,
    custom_open_positions jsonb,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.open_positions OWNER TO taf;

--
-- Name: orgs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.orgs (
    org_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    parent_org_id uuid,
    root_org_id uuid,
    name text NOT NULL,
    kind text DEFAULT 'company'::text,
    path public.ltree,
    custom_domain text,
    dashboard_name text,
    product_name text,
    logo text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT orgs_kind_check CHECK ((kind = ANY (ARRAY['tenant'::text, 'ministry'::text, 'holding'::text, 'company'::text, 'unit'::text, 'counsel'::text, 'branch'::text])))
);


ALTER TABLE public.orgs OWNER TO taf;

--
-- Name: overtime_rules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.overtime_rules (
    id integer NOT NULL,
    scope character varying(100) DEFAULT 'company'::character varying,
    country_id integer,
    tenant_id integer,
    branch_id integer,
    shift_hours integer NOT NULL,
    first4_rate numeric(5,2) DEFAULT 0.50,
    after4_rate numeric(5,2) DEFAULT 2.00,
    holiday_rate numeric(5,2) DEFAULT 2.00,
    sixth_day_rate numeric(5,2) DEFAULT 2.00,
    seventh_day_rate numeric(5,2) DEFAULT 2.00,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.overtime_rules OWNER TO taf;

--
-- Name: overtime_rules_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.overtime_rules_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.overtime_rules_id_seq OWNER TO taf;

--
-- Name: overtime_rules_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.overtime_rules_id_seq OWNED BY public.overtime_rules.id;


--
-- Name: page_configs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.page_configs (
    id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    tenant_id uuid,
    branch_id uuid,
    page text NOT NULL,
    header_title text,
    cards jsonb,
    layout_type text DEFAULT 'grid'::text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.page_configs OWNER TO taf;

--
-- Name: payment_items; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payment_items (
    payment_item_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    payment_id uuid NOT NULL,
    method text NOT NULL,
    amount numeric(10,2) NOT NULL,
    customer_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.payment_items OWNER TO taf;

--
-- Name: payment_request; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payment_request (
    id integer NOT NULL,
    invoice_id integer,
    request_id integer,
    cashier_id integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.payment_request OWNER TO taf;

--
-- Name: payment_request_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.payment_request_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.payment_request_id_seq OWNER TO taf;

--
-- Name: payment_request_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.payment_request_id_seq OWNED BY public.payment_request.id;


--
-- Name: payment_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payment_types (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    description text,
    tenant_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.payment_types OWNER TO taf;

--
-- Name: payment_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.payment_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.payment_types_id_seq OWNER TO taf;

--
-- Name: payment_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.payment_types_id_seq OWNED BY public.payment_types.id;


--
-- Name: payments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payments (
    payment_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    client_id uuid,
    org_id uuid,
    invoice_id uuid,
    reference_id uuid,
    reference_table text,
    payment_date date,
    total_amount numeric(10,2) DEFAULT NULL::numeric,
    payment_method text,
    payments jsonb,
    document_ids text,
    screenshot_ids text,
    notes text,
    status text DEFAULT 'completed'::text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.payments OWNER TO taf;

--
-- Name: payroll_anomalies; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payroll_anomalies (
    id integer NOT NULL,
    payroll_run_id integer NOT NULL,
    employee_id integer NOT NULL,
    message character varying(255) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.payroll_anomalies OWNER TO taf;

--
-- Name: payroll_anomalies_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.payroll_anomalies_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.payroll_anomalies_id_seq OWNER TO taf;

--
-- Name: payroll_anomalies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.payroll_anomalies_id_seq OWNED BY public.payroll_anomalies.id;


--
-- Name: payslip_deductions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payslip_deductions (
    payslip_deduction_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    payslip_id uuid NOT NULL,
    deduction_type_id uuid NOT NULL,
    amount numeric(10,2) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.payslip_deductions OWNER TO taf;

--
-- Name: payslips; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.payslips (
    payslip_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    user_id uuid NOT NULL,
    time_clock_aggregate_id uuid NOT NULL,
    gross_pay numeric(8,2) DEFAULT NULL::numeric,
    net_pay numeric(8,2) DEFAULT NULL::numeric,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    org_id uuid
);


ALTER TABLE public.payslips OWNER TO taf;

--
-- Name: performance_goals; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.performance_goals (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    description text NOT NULL,
    kpi_id integer,
    due_date date,
    status character varying(50) DEFAULT 'pending'::character varying,
    progress_pct numeric(5,2) DEFAULT 0.00,
    score_type character varying(20) DEFAULT 'numeric'::character varying,
    milestone character varying(255) DEFAULT NULL::character varying,
    completed_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.performance_goals OWNER TO taf;

--
-- Name: performance_goals_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.performance_goals_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.performance_goals_id_seq OWNER TO taf;

--
-- Name: performance_goals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.performance_goals_id_seq OWNED BY public.performance_goals.id;


--
-- Name: performance_reviews; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.performance_reviews (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    cycle_id integer NOT NULL,
    self_rating numeric(3,2) DEFAULT NULL::numeric,
    manager_rating numeric(3,2) DEFAULT NULL::numeric,
    comments text,
    status character varying(50) DEFAULT 'draft'::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.performance_reviews OWNER TO taf;

--
-- Name: performance_reviews_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.performance_reviews_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.performance_reviews_id_seq OWNER TO taf;

--
-- Name: performance_reviews_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.performance_reviews_id_seq OWNED BY public.performance_reviews.id;


--
-- Name: permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.permissions (
    id integer NOT NULL,
    resource_id integer,
    resource_type_id integer,
    resource_name character varying(50) DEFAULT NULL::character varying,
    subject_type character varying(50) DEFAULT NULL::character varying,
    subject_id integer,
    tenant_id integer,
    branch_id integer,
    department_id integer,
    district_id integer,
    can_view boolean,
    can_edit boolean,
    can_create boolean,
    can_delete boolean,
    can_delegate boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.permissions OWNER TO taf;

--
-- Name: permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.permissions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.permissions_id_seq OWNER TO taf;

--
-- Name: permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.permissions_id_seq OWNED BY public.permissions.id;


--
-- Name: permit_applications; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.permit_applications (
    id integer NOT NULL,
    permit_type_id integer NOT NULL,
    applicant_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    status character varying(50) DEFAULT 'Initiated'::character varying,
    start_date date,
    end_date date,
    fee_amount numeric(10,2) DEFAULT 0.00,
    description text,
    work_location character varying(255) DEFAULT NULL::character varying,
    equipment character varying(255) DEFAULT NULL::character varying,
    hazard_assessment text,
    control_measures text,
    ppe_required text,
    control_items json,
    ppe_items json,
    loto_instructions text,
    emergency_response text,
    issuer_id integer,
    supervisor_id integer,
    issuer_signed_at timestamp without time zone,
    supervisor_signed_at timestamp without time zone,
    holder_signed_at timestamp without time zone,
    signed_off_at timestamp without time zone,
    expires_at date,
    archived_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.permit_applications OWNER TO taf;

--
-- Name: permit_applications_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.permit_applications_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.permit_applications_id_seq OWNER TO taf;

--
-- Name: permit_applications_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.permit_applications_id_seq OWNED BY public.permit_applications.id;


--
-- Name: permit_documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.permit_documents (
    id integer NOT NULL,
    permit_application_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    file_name character varying(255) NOT NULL,
    file_type character varying(50) NOT NULL,
    file_path text NOT NULL,
    uploaded_by integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.permit_documents OWNER TO taf;

--
-- Name: permit_documents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.permit_documents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.permit_documents_id_seq OWNER TO taf;

--
-- Name: permit_documents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.permit_documents_id_seq OWNED BY public.permit_documents.id;


--
-- Name: permit_inspections; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.permit_inspections (
    id integer NOT NULL,
    permit_application_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    inspector_id integer NOT NULL,
    scheduled_for timestamp without time zone,
    result character varying(255) DEFAULT NULL::character varying,
    notes text,
    hours_logged numeric(5,2) DEFAULT NULL::numeric,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.permit_inspections OWNER TO taf;

--
-- Name: permit_inspections_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.permit_inspections_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.permit_inspections_id_seq OWNER TO taf;

--
-- Name: permit_inspections_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.permit_inspections_id_seq OWNED BY public.permit_inspections.id;


--
-- Name: permit_signatures; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.permit_signatures (
    id integer NOT NULL,
    permit_application_id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    role character varying(20) NOT NULL,
    user_id integer,
    file_path text NOT NULL,
    signed_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.permit_signatures OWNER TO taf;

--
-- Name: permit_signatures_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.permit_signatures_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.permit_signatures_id_seq OWNER TO taf;

--
-- Name: permit_signatures_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.permit_signatures_id_seq OWNED BY public.permit_signatures.id;


--
-- Name: permit_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.permit_types (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    control_options json,
    ppe_options json,
    required_training_ids json,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.permit_types OWNER TO taf;

--
-- Name: permit_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.permit_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.permit_types_id_seq OWNER TO taf;

--
-- Name: permit_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.permit_types_id_seq OWNED BY public.permit_types.id;


--
-- Name: policies; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.policies (
    policy_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    title character varying(255) NOT NULL,
    content text,
    content_type character varying(100) DEFAULT 'html'::character varying NOT NULL,
    policy_type character varying(50) DEFAULT NULL::character varying,
    pdf_url text,
    language_code character varying(10) DEFAULT 'en'::character varying,
    expiry_date date,
    renewal_status character varying(50) DEFAULT NULL::character varying,
    visible_to_roles character varying(255) DEFAULT NULL::character varying,
    visible_to_group character varying(255) DEFAULT NULL::character varying,
    visible_to_all boolean DEFAULT false,
    created_by integer,
    updated_by integer,
    version integer DEFAULT 1 NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.policies OWNER TO taf;

--
-- Name: policy_acknowledgments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.policy_acknowledgments (
    id integer NOT NULL,
    policy_id integer NOT NULL,
    user_id integer NOT NULL,
    policy_version integer DEFAULT 1,
    acknowledged_at timestamp without time zone NOT NULL,
    ip_address character varying(45) DEFAULT NULL::character varying,
    browser character varying(100) DEFAULT NULL::character varying,
    user_agent text,
    duration_seconds integer,
    scrolled_to_bottom boolean DEFAULT false,
    checkbox_confirmed boolean DEFAULT false,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.policy_acknowledgments OWNER TO taf;

--
-- Name: policy_acknowledgments_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.policy_acknowledgments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.policy_acknowledgments_id_seq OWNER TO taf;

--
-- Name: policy_acknowledgments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.policy_acknowledgments_id_seq OWNED BY public.policy_acknowledgments.id;


--
-- Name: policy_approvals; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.policy_approvals (
    id integer NOT NULL,
    document_id uuid NOT NULL,
    step_order integer NOT NULL,
    approver_role character varying(100) NOT NULL,
    status character varying(50) DEFAULT 'pending'::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.policy_approvals OWNER TO taf;

--
-- Name: policy_approvals_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.policy_approvals_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.policy_approvals_id_seq OWNER TO taf;

--
-- Name: policy_approvals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.policy_approvals_id_seq OWNED BY public.policy_approvals.id;


--
-- Name: policy_targets; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.policy_targets (
    id integer NOT NULL,
    policy_id integer NOT NULL,
    group_id integer,
    location_id integer,
    job_id integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.policy_targets OWNER TO taf;

--
-- Name: policy_targets_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.policy_targets_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.policy_targets_id_seq OWNER TO taf;

--
-- Name: policy_targets_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.policy_targets_id_seq OWNED BY public.policy_targets.id;


--
-- Name: policy_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.policy_templates (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    content text,
    content_type character varying(20) DEFAULT 'html'::character varying,
    pdf_url text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.policy_templates OWNER TO taf;

--
-- Name: policy_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.policy_templates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.policy_templates_id_seq OWNER TO taf;

--
-- Name: policy_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.policy_templates_id_seq OWNED BY public.policy_templates.id;


--
-- Name: pos_settings; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.pos_settings (
    pos_settings_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    branch_id uuid,
    password text NOT NULL,
    pin text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    createdat timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    sdc_endpoint text,
    sdc_pin_url text
);


ALTER TABLE public.pos_settings OWNER TO taf;

--
-- Name: procurement_requests; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.procurement_requests (
    procurement_request_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    description text NOT NULL,
    justification text,
    estimated_cost numeric(12,2),
    quantity integer,
    preferred_vendor character varying(100),
    needed_by date,
    project_id integer,
    inventory_item_id integer,
    location_id integer,
    status character varying(50) DEFAULT 'Pending'::character varying,
    requester_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.procurement_requests OWNER TO taf;

--
-- Name: procurements; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.procurements (
    procurement_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    vendor_id uuid,
    quotation_number text,
    invoice_number text,
    requested_by_date timestamp with time zone,
    product_barcode text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.procurements OWNER TO taf;

--
-- Name: product_batch_number; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.product_batch_number (
    product_batch_number_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid,
    expiry_date date,
    batch_number text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.product_batch_number OWNER TO taf;

--
-- Name: product_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.product_categories (
    category_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.product_categories OWNER TO taf;

--
-- Name: product_daily_rec; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.product_daily_rec (
    product_daily_rec_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    date timestamp with time zone,
    change integer NOT NULL,
    branch_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.product_daily_rec OWNER TO taf;

--
-- Name: product_discounts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.product_discounts (
    discount_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid,
    discount_amount numeric(10,2) DEFAULT NULL::numeric,
    start_date date,
    end_date date,
    org_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.product_discounts OWNER TO taf;

--
-- Name: products; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.products (
    product_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name text,
    description text,
    price numeric DEFAULT NULL::numeric,
    quantity integer,
    org_id uuid,
    barcode text,
    category_id uuid,
    brand text,
    product_number text,
    tax_rates jsonb DEFAULT '{"stt": "", "vat": "G"}'::jsonb,
    size text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.products OWNER TO taf;

--
-- Name: products_2_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.products_2_categories (
    product_category_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid NOT NULL,
    category_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.products_2_categories OWNER TO taf;

--
-- Name: products_2_taxcodes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.products_2_taxcodes (
    product_tax_code_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid,
    taxcode_id uuid,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.products_2_taxcodes OWNER TO taf;

--
-- Name: products_to_vendors; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.products_to_vendors (
    products_to_vendor_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    product_id uuid,
    vendor_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.products_to_vendors OWNER TO taf;

--
-- Name: program_default_group_permissions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.program_default_group_permissions (
    program_default_permission_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    program_default_group_id uuid NOT NULL,
    module_id uuid,
    permission_type character varying(50) DEFAULT 'module'::character varying NOT NULL,
    action text DEFAULT 'allow'::text NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.program_default_group_permissions OWNER TO taf;

--
-- Name: program_default_groups; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.program_default_groups (
    program_default_group_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    program_id uuid NOT NULL,
    group_name character varying(255) NOT NULL,
    group_description text,
    is_auto_create boolean DEFAULT true NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.program_default_groups OWNER TO taf;

--
-- Name: program_enrollments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.program_enrollments (
    program_enrollment_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    program_id uuid NOT NULL,
    org_id uuid NOT NULL,
    status text DEFAULT 'active'::text NOT NULL,
    enrolled_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.program_enrollments OWNER TO taf;

--
-- Name: program_modules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.program_modules (
    program_module_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    program_id uuid NOT NULL,
    module_id uuid,
    config_json jsonb,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.program_modules OWNER TO taf;

--
-- Name: programs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.programs (
    program_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    name text NOT NULL,
    owner_root_org_id uuid,
    is_private boolean DEFAULT true NOT NULL,
    owner_access public.owner_access_mode DEFAULT 'none'::public.owner_access_mode NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.programs OWNER TO taf;

--
-- Name: projects; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.projects (
    id integer NOT NULL,
    tenant_id integer,
    branch_id integer,
    name character varying(255) NOT NULL,
    description text,
    start_date date,
    end_date date,
    status character varying(50) DEFAULT 'active'::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.projects OWNER TO taf;

--
-- Name: projects_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.projects_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.projects_id_seq OWNER TO taf;

--
-- Name: projects_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.projects_id_seq OWNED BY public.projects.id;


--
-- Name: properties; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.properties (
    id integer NOT NULL,
    counselid integer,
    propertyid integer NOT NULL,
    assessmentnumber integer NOT NULL,
    ratepayerid integer,
    zone character varying(100) DEFAULT NULL::character varying,
    address text,
    street character varying(255) DEFAULT NULL::character varying,
    ward character varying(100) DEFAULT NULL::character varying,
    legaldescription text,
    noofflats integer,
    isactive boolean DEFAULT true,
    createdby integer,
    propertyholdersname character varying(255) DEFAULT NULL::character varying,
    ucv numeric(10,2) NOT NULL,
    ratesstrick numeric(3,2) NOT NULL,
    arrears numeric(10,2) NOT NULL,
    advancepayment numeric(10,2) NOT NULL,
    garbagefee numeric(10,2) NOT NULL,
    garbagearrears numeric(10,2) NOT NULL,
    advancepay numeric(10,2) NOT NULL,
    legalfee numeric(10,2) NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.properties OWNER TO taf;

--
-- Name: properties_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.properties_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.properties_id_seq OWNER TO taf;

--
-- Name: properties_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.properties_id_seq OWNED BY public.properties.id;


--
-- Name: property_rates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.property_rates (
    id integer NOT NULL,
    zone character varying(100) DEFAULT NULL::character varying,
    subzone character varying(100) DEFAULT NULL::character varying,
    category character varying(100) DEFAULT NULL::character varying,
    baserate numeric(10,2) DEFAULT NULL::numeric,
    rateper100 numeric(10,2) DEFAULT NULL::numeric,
    ratetype character varying(50) DEFAULT NULL::character varying,
    ratestrick2024 numeric(10,2) DEFAULT NULL::numeric,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.property_rates OWNER TO taf;

--
-- Name: property_rates_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.property_rates_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.property_rates_id_seq OWNER TO taf;

--
-- Name: property_rates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.property_rates_id_seq OWNED BY public.property_rates.id;


--
-- Name: purchase_orders; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.purchase_orders (
    purchase_order_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    vendor_id uuid NOT NULL,
    org_id uuid,
    order_date date NOT NULL,
    order_number text NOT NULL,
    reference_id uuid,
    reference_table text,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    total_amount numeric(14,2),
    rfq_id uuid
);


ALTER TABLE public.purchase_orders OWNER TO taf;

--
-- Name: push_subscriptions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.push_subscriptions (
    id integer NOT NULL,
    user_id integer,
    endpoint text NOT NULL,
    p256dh character varying(255) NOT NULL,
    auth character varying(255) NOT NULL,
    browser character varying(100) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.push_subscriptions OWNER TO taf;

--
-- Name: push_subscriptions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.push_subscriptions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.push_subscriptions_id_seq OWNER TO taf;

--
-- Name: push_subscriptions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.push_subscriptions_id_seq OWNED BY public.push_subscriptions.id;


--
-- Name: quotations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.quotations (
    quotation_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    quotation_number text,
    date date NOT NULL,
    customer_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.quotations OWNER TO taf;

--
-- Name: rate_invoices; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rate_invoices (
    id integer NOT NULL,
    counselid integer,
    rateid integer NOT NULL,
    propertyid integer,
    period date,
    arrears numeric(10,2) DEFAULT NULL::numeric,
    currentcharges numeric(10,2) DEFAULT NULL::numeric,
    penalty numeric(10,2) DEFAULT NULL::numeric,
    totaldue numeric(10,2) DEFAULT NULL::numeric,
    receiptstotal numeric(10,2) DEFAULT NULL::numeric,
    balance numeric(10,2) DEFAULT NULL::numeric,
    createdby integer,
    customerid integer,
    gl_transaction_id integer,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.rate_invoices OWNER TO taf;

--
-- Name: rate_invoices_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.rate_invoices_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.rate_invoices_id_seq OWNER TO taf;

--
-- Name: rate_invoices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.rate_invoices_id_seq OWNED BY public.rate_invoices.id;


--
-- Name: rate_limits; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rate_limits (
    key text NOT NULL,
    window_start timestamp with time zone NOT NULL,
    count integer NOT NULL
);


ALTER TABLE public.rate_limits OWNER TO taf;

--
-- Name: rate_payments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rate_payments (
    id integer NOT NULL,
    counselid integer,
    receiptid integer NOT NULL,
    propertyid integer,
    rateid integer,
    referenceno character varying(100) DEFAULT NULL::character varying,
    amount numeric(10,2) DEFAULT NULL::numeric,
    receiptdate date,
    method character varying(50) DEFAULT NULL::character varying,
    uploadedby character varying(100) DEFAULT NULL::character varying,
    screenshotpath text,
    createdby integer,
    gl_transaction_id integer,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.rate_payments OWNER TO taf;

--
-- Name: rate_payments_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.rate_payments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.rate_payments_id_seq OWNER TO taf;

--
-- Name: rate_payments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.rate_payments_id_seq OWNED BY public.rate_payments.id;


--
-- Name: ratepayers; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.ratepayers (
    id integer NOT NULL,
    counselid integer,
    ratepayerid integer NOT NULL,
    fullname character varying(255) DEFAULT NULL::character varying,
    previousowner character varying(255) DEFAULT NULL::character varying,
    tinnumber character varying(100) DEFAULT NULL::character varying,
    notes text,
    isdeceased boolean DEFAULT false,
    isoverseasowner boolean DEFAULT false,
    workplace character varying(255) DEFAULT NULL::character varying,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.ratepayers OWNER TO taf;

--
-- Name: ratepayers_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.ratepayers_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.ratepayers_id_seq OWNER TO taf;

--
-- Name: ratepayers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.ratepayers_id_seq OWNED BY public.ratepayers.id;


--
-- Name: receipts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.receipts (
    id integer NOT NULL,
    invoice_id integer,
    receipt_number character varying(100) NOT NULL,
    amount numeric(10,2) NOT NULL,
    payment_method character varying(50) DEFAULT NULL::character varying,
    cashier_id integer,
    session_id integer,
    payer_name character varying(255) DEFAULT NULL::character varying,
    receipt_date timestamp without time zone,
    reference character varying(255) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.receipts OWNER TO taf;

--
-- Name: receipts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.receipts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.receipts_id_seq OWNER TO taf;

--
-- Name: receipts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.receipts_id_seq OWNED BY public.receipts.id;


--
-- Name: refresh_tokens; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.refresh_tokens (
    token_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    session_id uuid NOT NULL,
    token_hash text NOT NULL,
    issued_at timestamp with time zone DEFAULT now() NOT NULL,
    expires_at timestamp with time zone NOT NULL,
    rotated_from uuid,
    revoked_at timestamp with time zone,
    revoke_reason text
);


ALTER TABLE public.refresh_tokens OWNER TO taf;

--
-- Name: reimbursement_claims; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.reimbursement_claims (
    id integer NOT NULL,
    employee_id integer NOT NULL,
    claim_date date NOT NULL,
    description text,
    amount numeric(10,2) NOT NULL,
    status character varying(100) DEFAULT 'Pending'::character varying,
    approved_at timestamp without time zone,
    approved_by integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.reimbursement_claims OWNER TO taf;

--
-- Name: reimbursement_claims_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.reimbursement_claims_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.reimbursement_claims_id_seq OWNER TO taf;

--
-- Name: reimbursement_claims_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.reimbursement_claims_id_seq OWNED BY public.reimbursement_claims.id;


--
-- Name: resource_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.resource_types (
    id integer NOT NULL,
    code character varying(50) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    description character varying(100) DEFAULT NULL::character varying,
    name character varying(100) NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.resource_types OWNER TO taf;

--
-- Name: resource_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.resource_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.resource_types_id_seq OWNER TO taf;

--
-- Name: resource_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.resource_types_id_seq OWNED BY public.resource_types.id;


--
-- Name: resources; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.resources (
    id integer NOT NULL,
    resource_type_id integer NOT NULL,
    resource_id integer,
    tenant_id integer,
    branch_id integer,
    name character varying(255) DEFAULT NULL::character varying,
    description character varying(100) DEFAULT NULL::character varying,
    reference_table character varying(100) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.resources OWNER TO taf;

--
-- Name: resources_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.resources_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.resources_id_seq OWNER TO taf;

--
-- Name: resources_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.resources_id_seq OWNED BY public.resources.id;


--
-- Name: review_calibrations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.review_calibrations (
    id integer NOT NULL,
    review_id integer NOT NULL,
    department character varying(255) NOT NULL,
    country_code character varying(5) DEFAULT NULL::character varying,
    original_rating numeric(3,2) DEFAULT NULL::numeric,
    adjusted_rating numeric(3,2) DEFAULT NULL::numeric,
    status character varying(20) DEFAULT 'pending'::character varying,
    moderator_id integer,
    approved_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.review_calibrations OWNER TO taf;

--
-- Name: review_calibrations_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.review_calibrations_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.review_calibrations_id_seq OWNER TO taf;

--
-- Name: review_calibrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.review_calibrations_id_seq OWNED BY public.review_calibrations.id;


--
-- Name: review_cycles; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.review_cycles (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    start_date date NOT NULL,
    end_date date NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.review_cycles OWNER TO taf;

--
-- Name: review_cycles_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.review_cycles_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.review_cycles_id_seq OWNER TO taf;

--
-- Name: review_cycles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.review_cycles_id_seq OWNED BY public.review_cycles.id;


--
-- Name: review_documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.review_documents (
    id integer NOT NULL,
    review_id integer NOT NULL,
    document_id uuid NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.review_documents OWNER TO taf;

--
-- Name: review_documents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.review_documents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.review_documents_id_seq OWNER TO taf;

--
-- Name: review_documents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.review_documents_id_seq OWNED BY public.review_documents.id;


--
-- Name: review_schedules; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.review_schedules (
    id integer NOT NULL,
    tenant_id integer,
    country_code character varying(5) DEFAULT NULL::character varying,
    role_id integer,
    review_type character varying(50) NOT NULL,
    interval_days integer NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.review_schedules OWNER TO taf;

--
-- Name: review_schedules_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.review_schedules_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.review_schedules_id_seq OWNER TO taf;

--
-- Name: review_schedules_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.review_schedules_id_seq OWNED BY public.review_schedules.id;


--
-- Name: rfq_approval_instances; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_approval_instances (
    approval_instance_id uuid DEFAULT gen_random_uuid() NOT NULL,
    rfq_id uuid NOT NULL,
    stage_no integer DEFAULT 1 NOT NULL,
    approver_user_id uuid,
    approver_group_id uuid,
    status text DEFAULT 'pending'::text NOT NULL,
    decided_at timestamp with time zone,
    comments text,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_approval_instances OWNER TO taf;

--
-- Name: rfq_approval_levels; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_approval_levels (
    rfq_approval_levels_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    branch_id uuid,
    department_id uuid,
    approver_user_id uuid NOT NULL,
    level_name text,
    min_amount numeric(12,2) DEFAULT 0.00,
    max_amount numeric(12,2) NOT NULL,
    currency text,
    notes text,
    is_active text DEFAULT 1 NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_approval_levels OWNER TO taf;

--
-- Name: rfq_attachments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_attachments (
    rfq_attachment_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    label text,
    filetype text,
    file_url text,
    include_when text DEFAULT 'always'::text NOT NULL,
    sort_order integer DEFAULT 0 NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_attachments OWNER TO taf;

--
-- Name: rfq_awards; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_awards (
    award_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    scope text NOT NULL,
    rfq_item_id bigint,
    vendor_id uuid NOT NULL,
    notes text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT rfq_awards_scope_check CHECK ((scope = ANY (ARRAY['header'::text, 'item'::text])))
);


ALTER TABLE public.rfq_awards OWNER TO taf;

--
-- Name: rfq_contracts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_contracts (
    contract_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    vendor_id uuid NOT NULL,
    vendor_name text NOT NULL,
    contract_number text NOT NULL,
    title text NOT NULL,
    status text DEFAULT 'draft'::text NOT NULL,
    currency text,
    total_value numeric(18,2) DEFAULT 0,
    effective_date date,
    expiry_date date,
    contract_payload jsonb NOT NULL,
    created_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_contracts OWNER TO taf;

--
-- Name: rfq_conversations; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_conversations (
    conversation_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    audience text NOT NULL,
    vendor_id uuid,
    subject text,
    locked_at timestamp with time zone,
    created_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT rfq_conversations_audience_check CHECK ((audience = ANY (ARRAY['internal'::text, 'vendor'::text, 'all_vendors'::text])))
);


ALTER TABLE public.rfq_conversations OWNER TO taf;

--
-- Name: rfq_events; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_events (
    event_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    actor_id uuid,
    actor_type text DEFAULT 'internal'::text NOT NULL,
    type text NOT NULL,
    payload jsonb DEFAULT '{}'::jsonb NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_events OWNER TO taf;

--
-- Name: rfq_headers; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_headers (
    rfq_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    department_id uuid,
    type text NOT NULL,
    rfq_number text,
    numbering_format text,
    title text NOT NULL,
    category text,
    currency text,
    incoterms text,
    summary_markdown text,
    summary_html text,
    publish_at timestamp with time zone,
    due_at timestamp with time zone NOT NULL,
    qa_cutoff_at timestamp with time zone,
    status text DEFAULT 'draft'::text NOT NULL,
    created_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    tender_box_opened_at timestamp with time zone,
    tender_box_opened_by uuid,
    scoring_config jsonb,
    requested_by uuid,
    approval_status text DEFAULT 'draft'::text NOT NULL,
    approval_started_at timestamp with time zone,
    approval_completed_at timestamp with time zone,
    CONSTRAINT rfq_headers_status_check CHECK ((status = ANY (ARRAY['draft'::text, 'open'::text, 'paused'::text, 'closed'::text, 'awarded'::text, 'archived'::text]))),
    CONSTRAINT rfq_headers_type_check CHECK ((type = ANY (ARRAY['RFQ'::text, 'EOI'::text])))
);


ALTER TABLE public.rfq_headers OWNER TO taf;

--
-- Name: rfq_invites; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_invites (
    invite_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    vendor_id uuid NOT NULL,
    contact_id uuid,
    vendor_user_id uuid,
    channel text,
    status text DEFAULT 'invited'::text NOT NULL,
    sent_at timestamp with time zone,
    delivered_at timestamp with time zone,
    opened_at timestamp with time zone,
    responded_at timestamp with time zone,
    declined_reason text,
    reminder_count integer DEFAULT 0 NOT NULL,
    last_reminder_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT rfq_invites_status_check CHECK ((status = ANY (ARRAY['invited'::text, 'delivered'::text, 'opened'::text, 'responded'::text, 'declined'::text])))
);


ALTER TABLE public.rfq_invites OWNER TO taf;

--
-- Name: rfq_items; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_items (
    id bigint NOT NULL,
    rfq_id uuid NOT NULL,
    description text NOT NULL,
    quantity numeric(14,4),
    uom text,
    required_specs jsonb,
    delivery_terms text,
    delivery_location text,
    is_optional boolean DEFAULT false NOT NULL,
    item_attachments jsonb,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_items OWNER TO taf;

--
-- Name: rfq_items_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.rfq_items_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.rfq_items_id_seq OWNER TO taf;

--
-- Name: rfq_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.rfq_items_id_seq OWNED BY public.rfq_items.id;


--
-- Name: rfq_message_attachments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_message_attachments (
    message_attachment_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    message_id uuid NOT NULL,
    filetype text,
    file_url text,
    label text,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_message_attachments OWNER TO taf;

--
-- Name: rfq_messages; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_messages (
    message_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    conversation_id uuid NOT NULL,
    rfq_id uuid NOT NULL,
    parent_message_id uuid,
    origin_message_id uuid,
    author_type text NOT NULL,
    author_user_id uuid,
    vendor_id uuid,
    category text DEFAULT 'note'::text NOT NULL,
    status text DEFAULT 'approved'::text NOT NULL,
    is_anonymous boolean DEFAULT false NOT NULL,
    body_markdown text NOT NULL,
    body_html text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    CONSTRAINT rfq_messages_author_type_check CHECK ((author_type = ANY (ARRAY['internal'::text, 'vendor'::text]))),
    CONSTRAINT rfq_messages_category_check CHECK ((category = ANY (ARRAY['note'::text, 'question'::text, 'answer'::text, 'announcement'::text, 'addendum'::text, 'clarification'::text, 'reply'::text]))),
    CONSTRAINT rfq_messages_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'approved'::text, 'rejected'::text])))
);


ALTER TABLE public.rfq_messages OWNER TO taf;

--
-- Name: rfq_scoring_notes; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_scoring_notes (
    note_id uuid DEFAULT gen_random_uuid() NOT NULL,
    rfq_id uuid NOT NULL,
    vendor_id uuid NOT NULL,
    org_id uuid,
    criterion_key text NOT NULL,
    note_text text,
    created_by uuid,
    updated_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_scoring_notes OWNER TO taf;

--
-- Name: rfq_sections; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_sections (
    rfq_section_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    section_key text,
    heading text,
    body_markdown text,
    body_html text,
    sort_order integer DEFAULT 0 NOT NULL,
    include_in_print boolean DEFAULT true NOT NULL,
    include_in_email boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    content_type text DEFAULT 'text'::text,
    form_id integer,
    elements jsonb
);


ALTER TABLE public.rfq_sections OWNER TO taf;

--
-- Name: rfq_shortlists; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_shortlists (
    shortlist_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_id uuid NOT NULL,
    vendor_id uuid NOT NULL,
    org_id uuid,
    notes text,
    created_by uuid,
    updated_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_shortlists OWNER TO taf;

--
-- Name: rfq_template_attachments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_template_attachments (
    rfq_template_attachment_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_template_id uuid NOT NULL,
    filetype character varying(50) NOT NULL,
    file_url text NOT NULL,
    label character varying(150) DEFAULT NULL::character varying,
    include_when character varying(50) DEFAULT 'always'::character varying,
    sort_order integer DEFAULT 0 NOT NULL,
    is_deleted boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_template_attachments OWNER TO taf;

--
-- Name: rfq_template_sections; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_template_sections (
    rfq_template_section_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    rfq_template_id uuid NOT NULL,
    section_key character varying(50) NOT NULL,
    heading character varying(150) NOT NULL,
    body_markdown text,
    body_html text,
    sort_order integer DEFAULT 0 NOT NULL,
    is_required boolean DEFAULT false NOT NULL,
    include_in_print boolean DEFAULT true NOT NULL,
    include_in_email boolean DEFAULT true NOT NULL,
    is_deleted boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    content_type text DEFAULT 'text'::text,
    form_id integer,
    elements jsonb
);


ALTER TABLE public.rfq_template_sections OWNER TO taf;

--
-- Name: rfq_templates; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfq_templates (
    rfq_template_id uuid DEFAULT public.uuid_generate_v7() NOT NULL,
    org_id uuid,
    name character varying(150) NOT NULL,
    code character varying(50),
    description text,
    category character varying(100) DEFAULT NULL::character varying,
    is_default boolean DEFAULT false NOT NULL,
    valid_from date,
    valid_until date,
    distribution_channels text[] DEFAULT '{}'::text[],
    created_by uuid,
    is_deleted boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.rfq_templates OWNER TO taf;

--
-- Name: rfqs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.rfqs (
    id uuid NOT NULL,
    procurement_request_id uuid,
    vendor_id uuid,
    sent_at timestamp with time zone
);


ALTER TABLE public.rfqs OWNER TO taf;

--
-- Name: risk_assessment_files; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_assessment_files (
    id integer NOT NULL,
    risk_assessment_id integer NOT NULL,
    file_path character varying(255) DEFAULT NULL::character varying,
    uploaded_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_assessment_files OWNER TO taf;

--
-- Name: risk_assessment_files_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_assessment_files_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_assessment_files_id_seq OWNER TO taf;

--
-- Name: risk_assessment_files_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_assessment_files_id_seq OWNED BY public.risk_assessment_files.id;


--
-- Name: risk_assessment_hazards; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_assessment_hazards (
    id integer NOT NULL,
    risk_assessment_id integer NOT NULL,
    hazard_description text,
    who_might_be_harmed text,
    existing_control_measures text,
    risk_rating_before integer,
    additional_controls text,
    residual_risk_rating integer,
    responsible_person character varying(255) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_assessment_hazards OWNER TO taf;

--
-- Name: risk_assessment_hazards_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_assessment_hazards_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_assessment_hazards_id_seq OWNER TO taf;

--
-- Name: risk_assessment_hazards_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_assessment_hazards_id_seq OWNED BY public.risk_assessment_hazards.id;


--
-- Name: risk_assessment_ppe; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_assessment_ppe (
    id integer NOT NULL,
    risk_assessment_id integer NOT NULL,
    checklist_item character varying(255) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_assessment_ppe OWNER TO taf;

--
-- Name: risk_assessment_ppe_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_assessment_ppe_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_assessment_ppe_id_seq OWNER TO taf;

--
-- Name: risk_assessment_ppe_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_assessment_ppe_id_seq OWNED BY public.risk_assessment_ppe.id;


--
-- Name: risk_assessment_signoffs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_assessment_signoffs (
    id integer NOT NULL,
    risk_assessment_id integer NOT NULL,
    name character varying(255) DEFAULT NULL::character varying,
    "position" character varying(255) DEFAULT NULL::character varying,
    signature character varying(255) DEFAULT NULL::character varying,
    signed_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_assessment_signoffs OWNER TO taf;

--
-- Name: risk_assessment_signoffs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_assessment_signoffs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_assessment_signoffs_id_seq OWNER TO taf;

--
-- Name: risk_assessment_signoffs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_assessment_signoffs_id_seq OWNED BY public.risk_assessment_signoffs.id;


--
-- Name: risk_assessment_types; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_assessment_types (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    description text,
    form_id integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_assessment_types OWNER TO taf;

--
-- Name: risk_assessment_types_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_assessment_types_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_assessment_types_id_seq OWNER TO taf;

--
-- Name: risk_assessment_types_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_assessment_types_id_seq OWNED BY public.risk_assessment_types.id;


--
-- Name: risk_assessments; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_assessments (
    id integer NOT NULL,
    risk_assessment_type_id integer,
    incident_id integer,
    title character varying(255) NOT NULL,
    department_id integer,
    location character varying(255) DEFAULT NULL::character varying,
    assessment_date date,
    review_date date,
    form_data jsonb,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_assessments OWNER TO taf;

--
-- Name: risk_assessments_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_assessments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_assessments_id_seq OWNER TO taf;

--
-- Name: risk_assessments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_assessments_id_seq OWNED BY public.risk_assessments.id;


--
-- Name: risk_categories; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_categories (
    id integer NOT NULL,
    name character varying(255) NOT NULL,
    description text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_categories OWNER TO taf;

--
-- Name: risk_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_categories_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_categories_id_seq OWNER TO taf;

--
-- Name: risk_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_categories_id_seq OWNED BY public.risk_categories.id;


--
-- Name: risk_identifications; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.risk_identifications (
    id integer NOT NULL,
    risk_description text,
    risk_category_id integer,
    root_cause text,
    likelihood integer,
    impact integer,
    risk_rating character varying(255) DEFAULT NULL::character varying,
    current_controls text,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.risk_identifications OWNER TO taf;

--
-- Name: risk_identifications_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.risk_identifications_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.risk_identifications_id_seq OWNER TO taf;

--
-- Name: risk_identifications_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.risk_identifications_id_seq OWNED BY public.risk_identifications.id;


--
-- Name: role_competencies; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.role_competencies (
    id integer NOT NULL,
    role_id integer NOT NULL,
    competency_id integer NOT NULL,
    required_level integer NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.role_competencies OWNER TO taf;

--
-- Name: role_competencies_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.role_competencies_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.role_competencies_id_seq OWNER TO taf;

--
-- Name: role_competencies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.role_competencies_id_seq OWNED BY public.role_competencies.id;


--
-- Name: safety_alert_files; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.safety_alert_files (
    id integer NOT NULL,
    alert_id integer NOT NULL,
    file_path character varying(255) DEFAULT NULL::character varying,
    uploaded_by integer,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.safety_alert_files OWNER TO taf;

--
-- Name: safety_alert_files_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.safety_alert_files_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.safety_alert_files_id_seq OWNER TO taf;

--
-- Name: safety_alert_files_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.safety_alert_files_id_seq OWNED BY public.safety_alert_files.id;


--
-- Name: safety_alert_logs; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.safety_alert_logs (
    id integer NOT NULL,
    alert_id integer NOT NULL,
    action character varying(50) NOT NULL,
    details text,
    user_id integer,
    logged_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.safety_alert_logs OWNER TO taf;

--
-- Name: safety_alert_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.safety_alert_logs_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.safety_alert_logs_id_seq OWNER TO taf;

--
-- Name: safety_alert_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.safety_alert_logs_id_seq OWNED BY public.safety_alert_logs.id;


--
-- Name: safety_alerts; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.safety_alerts (
    id integer NOT NULL,
    date date,
    "time" character varying(255) DEFAULT NULL::character varying,
    location character varying(255) DEFAULT NULL::character varying,
    classification character varying(100) DEFAULT 'general'::character varying NOT NULL,
    description text,
    status character varying(50) DEFAULT 'open'::character varying,
    investigator_id integer,
    submitted_by integer,
    form_data jsonb,
    tenant_id integer,
    branch_id integer,
    updatedat timestamp with time zone DEFAULT now() NOT NULL,
    isdeleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.safety_alerts OWNER TO taf;

--
-- Name: safety_alerts_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.safety_alerts_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.safety_alerts_id_seq OWNER TO taf;

--
-- Name: safety_alerts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.safety_alerts_id_seq OWNED BY public.safety_alerts.id;


--
-- Name: safety_document_versions; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.safety_document_versions (
    id integer NOT NULL,
    document_id uuid NOT NULL,
    storage_key character varying(255) NOT NULL,
    version_number integer NOT NULL,
    version_hash character varying(64) DEFAULT NULL::character varying,
    created_at timestamp without time zone,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.safety_document_versions OWNER TO taf;

--
-- Name: safety_document_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.safety_document_versions_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.safety_document_versions_id_seq OWNER TO taf;

--
-- Name: safety_document_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.safety_document_versions_id_seq OWNED BY public.safety_document_versions.id;


--
-- Name: safety_documents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.safety_documents (
    id integer NOT NULL,
    folder_id integer,
    title character varying(255) NOT NULL,
    description text,
    owner_id integer NOT NULL,
    connector_id integer,
    created_at timestamp without time zone,
    visible_to_roles character varying(255) DEFAULT NULL::character varying,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.safety_documents OWNER TO taf;

--
-- Name: safety_documents_id_seq; Type: SEQUENCE; Schema: public; Owner: taf
--

CREATE SEQUENCE public.safety_documents_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.safety_documents_id_seq OWNER TO taf;

--
-- Name: safety_documents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: taf
--

ALTER SEQUENCE public.safety_documents_id_seq OWNED BY public.safety_documents.id;


--
-- Name: safety_field_incidents; Type: TABLE; Schema: public; Owner: taf
--

CREATE TABLE public.safety_field_incidents (
    id integer NOT NULL,
    incident_type character varying(100) DEFAULT NULL::character varying,
    location character varying(255) DEFAULT NULL::character varying,
    description text,
    document_ids character varying(255) DEFAULT NULL::character varying,
    gps character varying(255) DEFAULT NULL::character varying,
    tenant_id integer,
    branch_id integer,
    isdeleted boolean DEFAULT false NOT NULL,
    updatedat timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.safety_field_incidents OWNER TO taf;

--
