338 lines
19 KiB
SQL
338 lines
19 KiB
SQL
--
|
||
-- PostgreSQL database dump
|
||
--
|
||
|
||
\restrict pHwwy5UuEtHtdS7REgnLp6pofdGXGLcagOaN1otJnxOM9VfG3TAbWnxM7IC8XHJ
|
||
|
||
-- Dumped from database version 16.11
|
||
-- Dumped by pg_dump version 16.11
|
||
|
||
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: 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
|
||
);
|
||
|
||
|
||
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) 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
|
||
\.
|
||
|
||
|
||
--
|
||
-- 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
|
||
\.
|
||
|
||
|
||
--
|
||
-- 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 pHwwy5UuEtHtdS7REgnLp6pofdGXGLcagOaN1otJnxOM9VfG3TAbWnxM7IC8XHJ
|
||
|