--
-- PostgreSQL database dump
--

\restrict mUKTWCYeXvRf2SKhMr352J1jYiouAP5fsYPxvQjxn9xhEgk8BrOSEtYCYQoFicQ

-- Dumped from database version 16.11
-- Dumped by pg_dump version 18.1

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;

--
-- 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: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;


--
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';


SET default_tablespace = '';

SET default_table_access_method = heap;

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

CREATE TABLE public.companies (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid NOT NULL,
    cnpj character varying(18) NOT NULL,
    razao_social character varying(255) NOT NULL,
    nome_fantasia character varying(255),
    email character varying(255),
    telefone character varying(20),
    status character varying(50) DEFAULT 'active'::character varying,
    created_by_user_id uuid,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.companies OWNER TO aggios;

--
-- Name: refresh_tokens; Type: TABLE; Schema: public; Owner: aggios
--

CREATE TABLE public.refresh_tokens (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    user_id uuid NOT NULL,
    token_hash character varying(255) NOT NULL,
    expires_at timestamp with time zone NOT NULL,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.refresh_tokens OWNER TO aggios;

--
-- Name: tenants; Type: TABLE; Schema: public; Owner: aggios
--

CREATE TABLE public.tenants (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    name character varying(255) NOT NULL,
    domain character varying(255) NOT NULL,
    subdomain character varying(63) NOT NULL,
    cnpj character varying(18),
    razao_social character varying(255),
    email character varying(255),
    phone character varying(20),
    website character varying(255),
    address text,
    city character varying(100),
    state character varying(2),
    zip character varying(10),
    description text,
    industry character varying(100),
    is_active boolean DEFAULT true,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    neighborhood character varying(100),
    street character varying(100),
    number character varying(20),
    complement character varying(100),
    team_size character varying(20),
    primary_color character varying(7),
    secondary_color character varying(7),
    logo_url text,
    logo_horizontal_url text
);


ALTER TABLE public.tenants OWNER TO aggios;

--
-- Name: users; Type: TABLE; Schema: public; Owner: aggios
--

CREATE TABLE public.users (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid,
    email character varying(255) NOT NULL,
    password_hash character varying(255) NOT NULL,
    first_name character varying(128),
    last_name character varying(128),
    role character varying(50) DEFAULT 'CLIENTE'::character varying,
    is_active boolean DEFAULT true,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT users_role_check CHECK (((role)::text = ANY ((ARRAY['SUPERADMIN'::character varying, 'ADMIN_AGENCIA'::character varying, 'CLIENTE'::character varying])::text[])))
);


ALTER TABLE public.users OWNER TO aggios;

--
-- Data for Name: companies; Type: TABLE DATA; Schema: public; Owner: aggios
--

COPY public.companies (id, tenant_id, cnpj, razao_social, nome_fantasia, email, telefone, status, created_by_user_id, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: refresh_tokens; Type: TABLE DATA; Schema: public; Owner: aggios
--

COPY public.refresh_tokens (id, user_id, token_hash, expires_at, created_at) FROM stdin;
\.


--
-- Data for Name: tenants; Type: TABLE DATA; Schema: public; Owner: aggios
--

COPY public.tenants (id, name, domain, subdomain, cnpj, razao_social, email, phone, website, address, city, state, zip, description, industry, is_active, created_at, updated_at, neighborhood, street, number, complement, team_size, primary_color, secondary_color, logo_url, logo_horizontal_url) FROM stdin;
d351e725-1428-45f3-b2e3-ca767e9b952c	Agência Teste	agencia-teste.aggios.app	agencia-teste	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	\N	t	2025-12-13 22:31:35.818953+00	2025-12-13 22:31:35.818953+00	\N	\N	\N	\N	\N	\N	\N	\N	\N
13d32cc3-0490-4557-96a3-7a38da194185	Empresa Teste	teste-empresa.localhost	teste-empresa	12.345.678/0001-90	EMPRESA TESTE LTDA	teste@teste.com	(11) 99999-9999	teste.com.br	Avenida Paulista, 1000 - Andar 10	S�o Paulo	SP	01310-100	Empresa de teste	tecnologia	t	2025-12-13 23:22:58.406376+00	2025-12-13 23:22:58.406376+00	Bela Vista	\N	1000	Andar 10	1-10	#8B5CF6	#A78BFA		
ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc	IdealPages	idealpages.localhost	idealpages	31.091.190/0001-23	ERIK DA SILVA SANTOS 36615318830	erik@idealpages.com.br	(13) 92000-4392	idealpages.com.br	Rua Quatorze, 150 - Casa	Guarujá	SP	11436-575	Empresa de contrucao de marca e desenvolvimento de software	agencia-digital	t	2025-12-13 23:23:35.508285+00	2025-12-13 23:26:40.947714+00	Vila Zilda	\N	150	Casa	1-10	#8B5CF6	#A78BFA	http://api.localhost/api/files/aggios-logos/tenants/ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc/logo-1765668400.png	
\.


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

COPY public.users (id, tenant_id, email, password_hash, first_name, last_name, role, is_active, created_at, updated_at) FROM stdin;
7b51ae6e-6fb0-42c4-8473-a98cbfcda6a4	\N	admin@aggios.app	$2a$10$yhCREFqXL7FA4zveCFcl4eYODNTSyt/swuYjS0nXkEq8pzqJo.BwO	Super	Admin	SUPERADMIN	t	2025-12-13 23:02:33.124444+00	2025-12-13 23:02:33.124444+00
488351e7-4ddc-41a4-9cd3-5c3dec833c44	13d32cc3-0490-4557-96a3-7a38da194185	teste@teste.com	$2a$10$fx3bQqL01A9UqJwSwKpdLuVCq8M/1L9CvcQhx5tTkdinsvCpPsh4a	Teste Silva	\N	ADMIN_AGENCIA	t	2025-12-13 23:22:58.446011+00	2025-12-13 23:22:58.446011+00
8742c1a1-5f1a-4df3-aa53-dcf94a2a2591	ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc	erik@idealpages.com.br	$2a$10$tD8Kq/ZW0fbmW3Ga5JsKbOUy0nzsIZwkXJKaf43gFDVnRxjaf63Em	Erik da Silva Santos	\N	ADMIN_AGENCIA	t	2025-12-13 23:23:35.551192+00	2025-12-13 23:23:35.551192+00
\.


--
-- Name: companies companies_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.companies
    ADD CONSTRAINT companies_pkey PRIMARY KEY (id);


--
-- Name: companies companies_tenant_id_cnpj_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.companies
    ADD CONSTRAINT companies_tenant_id_cnpj_key UNIQUE (tenant_id, cnpj);


--
-- Name: refresh_tokens refresh_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.refresh_tokens
    ADD CONSTRAINT refresh_tokens_pkey PRIMARY KEY (id);


--
-- Name: tenants tenants_domain_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.tenants
    ADD CONSTRAINT tenants_domain_key UNIQUE (domain);


--
-- Name: tenants tenants_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.tenants
    ADD CONSTRAINT tenants_pkey PRIMARY KEY (id);


--
-- Name: tenants tenants_subdomain_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.tenants
    ADD CONSTRAINT tenants_subdomain_key UNIQUE (subdomain);


--
-- Name: users users_email_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_email_key UNIQUE (email);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

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


--
-- Name: idx_companies_cnpj; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_companies_cnpj ON public.companies USING btree (cnpj);


--
-- Name: idx_companies_tenant_id; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_companies_tenant_id ON public.companies USING btree (tenant_id);


--
-- Name: idx_refresh_tokens_expires_at; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_refresh_tokens_expires_at ON public.refresh_tokens USING btree (expires_at);


--
-- Name: idx_refresh_tokens_user_id; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_refresh_tokens_user_id ON public.refresh_tokens USING btree (user_id);


--
-- Name: idx_tenants_domain; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_tenants_domain ON public.tenants USING btree (domain);


--
-- Name: idx_tenants_subdomain; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_tenants_subdomain ON public.tenants USING btree (subdomain);


--
-- Name: idx_users_email; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_users_email ON public.users USING btree (email);


--
-- Name: idx_users_tenant_id; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_users_tenant_id ON public.users USING btree (tenant_id);


--
-- Name: companies companies_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.companies
    ADD CONSTRAINT companies_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES public.users(id);


--
-- Name: companies companies_tenant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.companies
    ADD CONSTRAINT companies_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;


--
-- Name: refresh_tokens refresh_tokens_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.refresh_tokens
    ADD CONSTRAINT refresh_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: users users_tenant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

\unrestrict mUKTWCYeXvRf2SKhMr352J1jYiouAP5fsYPxvQjxn9xhEgk8BrOSEtYCYQoFicQ

