--
-- PostgreSQL database dump
--

-- Dumped from database version 17.5
-- Dumped by pg_dump version 17.5

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET transaction_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;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: agendamentos; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.agendamentos (
    id integer NOT NULL,
    nome character varying(100),
    descricao text,
    rotina character varying(30),
    periodicidade character varying(20),
    dias_semana text[],
    horario time without time zone,
    data_inicio date,
    data_fim date,
    ativo boolean DEFAULT true,
    execucoes_ilimitadas boolean DEFAULT true,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    alerta boolean DEFAULT false,
    tipo_servico character varying(20),
    endpoint text,
    token text,
    json_payload text,
    metodo_http character varying(10) DEFAULT 'POST'::character varying,
    sql_retorno text,
    modo_execucao character varying(30),
    servidor_origem character varying(100),
    id_servico integer,
    intervalo_segundos integer,
    retorna_dados boolean DEFAULT false,
    api_origem text,
    token_origem text,
    api_destino text,
    token_destino text
);


ALTER TABLE public.agendamentos OWNER TO postgres;

--
-- Name: agendamentos_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.agendamentos_id_seq OWNER TO postgres;

--
-- Name: agendamentos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.agendamentos_id_seq OWNED BY public.agendamentos.id;


--
-- Name: execucoes_agendadas; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.execucoes_agendadas (
    id integer NOT NULL,
    agendamento_id integer,
    status character varying(20) DEFAULT 'pendente'::character varying,
    parametros text,
    payload_enviado text,
    resposta_recebida text,
    erro text,
    servidor character varying(100),
    data_agendada timestamp without time zone,
    data_execucao timestamp without time zone,
    atualizado_em timestamp without time zone
);


ALTER TABLE public.execucoes_agendadas OWNER TO postgres;

--
-- Name: execucoes_agendadas_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.execucoes_agendadas_id_seq OWNER TO postgres;

--
-- Name: execucoes_agendadas_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.execucoes_agendadas_id_seq OWNED BY public.execucoes_agendadas.id;


--
-- Name: logs; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.logs (
    id integer NOT NULL,
    usuario_id integer,
    endpoint text,
    metodo text,
    dados text,
    ip text,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.logs OWNER TO postgres;

--
-- Name: logs_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.logs_id_seq OWNER TO postgres;

--
-- Name: logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.logs_id_seq OWNED BY public.logs.id;


--
-- Name: permissoes_tokens; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.permissoes_tokens (
    id integer NOT NULL,
    token_id integer,
    servico_id integer,
    metodo_http character varying(10),
    data_expiracao timestamp without time zone
);


ALTER TABLE public.permissoes_tokens OWNER TO postgres;

--
-- Name: permissoes_tokens_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.permissoes_tokens_id_seq OWNER TO postgres;

--
-- Name: permissoes_tokens_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.permissoes_tokens_id_seq OWNED BY public.permissoes_tokens.id;


--
-- Name: servicos_dinamicos; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.servicos_dinamicos (
    id integer NOT NULL,
    nome_servico character varying(100),
    ativo boolean DEFAULT true,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    endpoint text,
    tipo character varying(10) DEFAULT 'GET'::character varying,
    atualizado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    sql_comando text NOT NULL,
    parametros text NOT NULL
);


ALTER TABLE public.servicos_dinamicos OWNER TO postgres;

--
-- Name: servicos_dinamicos_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.servicos_dinamicos_id_seq OWNER TO postgres;

--
-- Name: servicos_dinamicos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.servicos_dinamicos_id_seq OWNED BY public.servicos_dinamicos.id;


--
-- Name: tokens_fixos; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.tokens_fixos (
    id integer NOT NULL,
    token text NOT NULL,
    descricao text,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.tokens_fixos OWNER TO postgres;

--
-- Name: tokens_fixos_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.tokens_fixos_id_seq OWNER TO postgres;

--
-- Name: tokens_fixos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.tokens_fixos_id_seq OWNED BY public.tokens_fixos.id;


--
-- Name: tokens_temp; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.tokens_temp (
    id integer NOT NULL,
    token text NOT NULL,
    descricao text,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    expira_em timestamp without time zone,
    permissoes jsonb,
    tempo_indefinido boolean DEFAULT false
);


ALTER TABLE public.tokens_temp OWNER TO postgres;

--
-- Name: tokens_temp_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.tokens_temp_id_seq OWNER TO postgres;

--
-- Name: tokens_temp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.tokens_temp_id_seq OWNED BY public.tokens_temp.id;


--
-- Name: tokens_terceiros; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.tokens_terceiros (
    id integer NOT NULL,
    nome_identificador character varying(100),
    token text NOT NULL,
    ativo boolean DEFAULT true,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    escopo text
);


ALTER TABLE public.tokens_terceiros OWNER TO postgres;

--
-- Name: tokens_terceiros_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.tokens_terceiros_id_seq OWNER TO postgres;

--
-- Name: tokens_terceiros_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.tokens_terceiros_id_seq OWNED BY public.tokens_terceiros.id;


--
-- Name: usuarios; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.usuarios (
    id integer NOT NULL,
    nome character varying(100),
    email character varying(150),
    senha character varying(255),
    admin boolean DEFAULT false,
    ativo boolean DEFAULT true,
    criado_em timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    data_ultima_atividade timestamp without time zone
);


ALTER TABLE public.usuarios OWNER TO postgres;

--
-- Name: usuarios_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER SEQUENCE public.usuarios_id_seq OWNER TO postgres;

--
-- Name: usuarios_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.usuarios_id_seq OWNED BY public.usuarios.id;


--
-- Name: agendamentos id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.agendamentos ALTER COLUMN id SET DEFAULT nextval('public.agendamentos_id_seq'::regclass);


--
-- Name: execucoes_agendadas id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.execucoes_agendadas ALTER COLUMN id SET DEFAULT nextval('public.execucoes_agendadas_id_seq'::regclass);


--
-- Name: logs id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.logs ALTER COLUMN id SET DEFAULT nextval('public.logs_id_seq'::regclass);


--
-- Name: permissoes_tokens id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.permissoes_tokens ALTER COLUMN id SET DEFAULT nextval('public.permissoes_tokens_id_seq'::regclass);


--
-- Name: servicos_dinamicos id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servicos_dinamicos ALTER COLUMN id SET DEFAULT nextval('public.servicos_dinamicos_id_seq'::regclass);


--
-- Name: tokens_fixos id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_fixos ALTER COLUMN id SET DEFAULT nextval('public.tokens_fixos_id_seq'::regclass);


--
-- Name: tokens_temp id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_temp ALTER COLUMN id SET DEFAULT nextval('public.tokens_temp_id_seq'::regclass);


--
-- Name: tokens_terceiros id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_terceiros ALTER COLUMN id SET DEFAULT nextval('public.tokens_terceiros_id_seq'::regclass);


--
-- Name: usuarios id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.usuarios ALTER COLUMN id SET DEFAULT nextval('public.usuarios_id_seq'::regclass);


--
-- Name: agendamentos agendamentos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.agendamentos
    ADD CONSTRAINT agendamentos_pkey PRIMARY KEY (id);


--
-- Name: execucoes_agendadas execucoes_agendadas_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.execucoes_agendadas
    ADD CONSTRAINT execucoes_agendadas_pkey PRIMARY KEY (id);


--
-- Name: logs logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.logs
    ADD CONSTRAINT logs_pkey PRIMARY KEY (id);


--
-- Name: permissoes_tokens permissoes_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.permissoes_tokens
    ADD CONSTRAINT permissoes_tokens_pkey PRIMARY KEY (id);


--
-- Name: servicos_dinamicos servicos_dinamicos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servicos_dinamicos
    ADD CONSTRAINT servicos_dinamicos_pkey PRIMARY KEY (id);


--
-- Name: tokens_fixos tokens_fixos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_fixos
    ADD CONSTRAINT tokens_fixos_pkey PRIMARY KEY (id);


--
-- Name: tokens_fixos tokens_fixos_token_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_fixos
    ADD CONSTRAINT tokens_fixos_token_key UNIQUE (token);


--
-- Name: tokens_temp tokens_temp_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_temp
    ADD CONSTRAINT tokens_temp_pkey PRIMARY KEY (id);


--
-- Name: tokens_terceiros tokens_terceiros_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_terceiros
    ADD CONSTRAINT tokens_terceiros_pkey PRIMARY KEY (id);


--
-- Name: tokens_terceiros tokens_terceiros_token_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.tokens_terceiros
    ADD CONSTRAINT tokens_terceiros_token_key UNIQUE (token);


--
-- Name: usuarios usuarios_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.usuarios
    ADD CONSTRAINT usuarios_email_key UNIQUE (email);


--
-- Name: usuarios usuarios_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.usuarios
    ADD CONSTRAINT usuarios_pkey PRIMARY KEY (id);


--
-- Name: execucoes_agendadas execucoes_agendadas_agendamento_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.execucoes_agendadas
    ADD CONSTRAINT execucoes_agendadas_agendamento_id_fkey FOREIGN KEY (agendamento_id) REFERENCES public.agendamentos(id) ON DELETE CASCADE;


--
-- Name: permissoes_tokens permissoes_tokens_servico_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.permissoes_tokens
    ADD CONSTRAINT permissoes_tokens_servico_id_fkey FOREIGN KEY (servico_id) REFERENCES public.servicos_dinamicos(id) ON DELETE CASCADE;


--
-- Name: permissoes_tokens permissoes_tokens_token_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.permissoes_tokens
    ADD CONSTRAINT permissoes_tokens_token_id_fkey FOREIGN KEY (token_id) REFERENCES public.tokens_terceiros(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

