--
-- PostgreSQL database dump
--


-- Dumped from database version 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1)
-- Dumped by pg_dump version 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: order_status; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE public.order_status AS ENUM (
    'pending',
    'running',
    'finished',
    'failed',
    'dlx'
);


--
-- Name: order_types; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE public.order_types AS ENUM (
    'activate',
    'preactivate',
    'cancel',
    'pause',
    'reactivate',
    'unknown'
);


--
-- Name: status_enum; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE public.status_enum AS ENUM (
    'noRequestID',
    'noMassID',
    'running',
    'finished',
    'error',
    'other'
);


SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: objenious_operation; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.objenious_operation (
    id bigint NOT NULL,
    retry_count integer DEFAULT 0,
    max_retry integer DEFAULT 5,
    max_date_retry timestamp without time zone,
    iccids text,
    request_id text,
    mass_action_id text,
    operation text NOT NULL,
    start_date timestamp with time zone DEFAULT now() NOT NULL,
    last_change_date timestamp with time zone DEFAULT now() NOT NULL,
    end_date timestamp with time zone,
    error text,
    status public.status_enum,
    objenious_status text
);


--
-- Name: objenious_operation_change; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.objenious_operation_change (
    id bigint NOT NULL,
    operation_id bigint,
    creation_date timestamp with time zone DEFAULT now() NOT NULL,
    error text,
    new_status public.status_enum,
    previous_status public.status_enum,
    new_objenious_status text,
    previous_objenious_status text,
    new_request_id text,
    new_mass_action_id text
);


--
-- Name: objenious_operation_change_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.objenious_operation_change ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.objenious_operation_change_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: objenious_operation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.objenious_operation ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.objenious_operation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: order_history; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.order_history (
    id bigint NOT NULL,
    order_id bigint NOT NULL,
    previous_status public.order_status NOT NULL,
    new_status public.order_status NOT NULL,
    change_reason text,
    change_date timestamp with time zone DEFAULT now() NOT NULL
);


--
-- Name: order_history_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.order_history ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.order_history_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: order_tracking; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.order_tracking (
    id bigint NOT NULL,
    correlation_id character varying(255) NOT NULL,
    exchange character varying(100),
    routing_key character varying(100),
    order_type public.order_types DEFAULT 'unknown'::public.order_types NOT NULL,
    payload jsonb,
    status public.order_status DEFAULT 'pending'::public.order_status NOT NULL,
    retry_count integer DEFAULT 0,
    error_message text,
    error_stacktrace text,
    start_date timestamp with time zone DEFAULT now() NOT NULL,
    update_date timestamp with time zone DEFAULT now() NOT NULL,
    finish_date timestamp with time zone
);


--
-- Name: order_tracking_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

ALTER TABLE public.order_tracking ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME public.order_tracking_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- Name: objenious_operation_change objenious_operation_change_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.objenious_operation_change
    ADD CONSTRAINT objenious_operation_change_pkey PRIMARY KEY (id);


--
-- Name: objenious_operation objenious_operation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.objenious_operation
    ADD CONSTRAINT objenious_operation_pkey PRIMARY KEY (id);


--
-- Name: order_history order_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.order_history
    ADD CONSTRAINT order_history_pkey PRIMARY KEY (id);


--
-- Name: order_tracking order_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.order_tracking
    ADD CONSTRAINT order_tracking_pkey PRIMARY KEY (id);


--
-- Name: idx_order_change_date; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_order_change_date ON public.order_history USING btree (change_date);


--
-- Name: idx_order_correlation; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_order_correlation ON public.order_tracking USING btree (correlation_id);


--
-- Name: idx_order_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_order_id ON public.order_history USING btree (order_id);


--
-- Name: operation_change; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX operation_change ON public.objenious_operation_change USING btree (operation_id);


--
-- Name: pending_operations; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX pending_operations ON public.objenious_operation USING btree (start_date) WHERE (end_date IS NULL);


--
-- Name: pending_orders; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX pending_orders ON public.order_tracking USING btree (start_date) WHERE (finish_date IS NULL);


--
-- Name: objenious_operation_change fk_operation_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.objenious_operation_change
    ADD CONSTRAINT fk_operation_id FOREIGN KEY (operation_id) REFERENCES public.objenious_operation(id);


--
-- Name: order_history fk_order_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.order_history
    ADD CONSTRAINT fk_order_id FOREIGN KEY (order_id) REFERENCES public.order_tracking(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--


