--
-- PostgreSQL database dump
--

\restrict ncvzwECg3gFaKDQN1qiZ5Czm3zMLkxhxcfcv3fVgXaROlVKnomYb3Jc6VjtZXqC

-- 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)';


--
-- Name: update_updated_at_column(); Type: FUNCTION; Schema: public; Owner: aggios
--

CREATE FUNCTION public.update_updated_at_column() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
    NEW.updated_at = CURRENT_TIMESTAMP;
    RETURN NEW;
END;
$$;


ALTER FUNCTION public.update_updated_at_column() OWNER TO aggios;

SET default_tablespace = '';

SET default_table_access_method = heap;

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

CREATE TABLE public.agency_signup_templates (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    name character varying(255) NOT NULL,
    slug character varying(100) NOT NULL,
    description text,
    form_fields jsonb DEFAULT '[]'::jsonb NOT NULL,
    available_modules jsonb DEFAULT '[]'::jsonb NOT NULL,
    custom_primary_color character varying(7),
    custom_logo_url text,
    redirect_url text,
    success_message text,
    is_active boolean DEFAULT true,
    usage_count integer DEFAULT 0,
    max_uses integer,
    expires_at timestamp with time zone,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.agency_signup_templates OWNER TO aggios;

--
-- Name: TABLE agency_signup_templates; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON TABLE public.agency_signup_templates IS 'Templates de cadastro de agÃªncias (SuperAdmin â†’ AgÃªncias)';


--
-- Name: COLUMN agency_signup_templates.form_fields; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.agency_signup_templates.form_fields IS 'Campos do formulÃ¡rio em JSONB: [{name: cnpj, required: true, enabled: true}]';


--
-- Name: COLUMN agency_signup_templates.available_modules; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.agency_signup_templates.available_modules IS 'MÃ³dulos disponÃ­veis: [CRM, Financial, Projects]';


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

CREATE TABLE public.agency_subscriptions (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    agency_id uuid NOT NULL,
    plan_id uuid NOT NULL,
    billing_type character varying(20) DEFAULT 'monthly'::character varying NOT NULL,
    current_users integer DEFAULT 0 NOT NULL,
    status character varying(50) DEFAULT 'active'::character varying NOT NULL,
    start_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    renewal_date timestamp without time zone NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.agency_subscriptions OWNER TO aggios;

--
-- Name: TABLE agency_subscriptions; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON TABLE public.agency_subscriptions IS 'Tracks agency subscription to plans';


--
-- Name: COLUMN agency_subscriptions.billing_type; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.agency_subscriptions.billing_type IS 'Monthly or annual billing';


--
-- Name: COLUMN agency_subscriptions.current_users; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.agency_subscriptions.current_users IS 'Current count of users (collaborators + clients)';


--
-- 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: crm_customer_lists; Type: TABLE; Schema: public; Owner: aggios
--

CREATE TABLE public.crm_customer_lists (
    customer_id uuid NOT NULL,
    list_id uuid NOT NULL,
    added_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    added_by uuid
);


ALTER TABLE public.crm_customer_lists OWNER TO aggios;

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

CREATE TABLE public.crm_customers (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid NOT NULL,
    name character varying(255) NOT NULL,
    email character varying(255),
    phone character varying(50),
    company character varying(255),
    "position" character varying(100),
    address character varying(255),
    city character varying(100),
    state character varying(50),
    zip_code character varying(20),
    country character varying(100) DEFAULT 'Brasil'::character varying,
    notes text,
    tags text[],
    is_active boolean DEFAULT true,
    created_by uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.crm_customers OWNER TO aggios;

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

CREATE TABLE public.crm_lists (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid NOT NULL,
    name character varying(100) NOT NULL,
    description text,
    color character varying(7) DEFAULT '#3b82f6'::character varying,
    created_by uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.crm_lists OWNER TO aggios;

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

CREATE TABLE public.plan_solutions (
    plan_id uuid NOT NULL,
    solution_id uuid NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.plan_solutions OWNER TO aggios;

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

CREATE TABLE public.plans (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    name character varying(255) NOT NULL,
    slug character varying(100) NOT NULL,
    description text,
    min_users integer DEFAULT 1 NOT NULL,
    max_users integer DEFAULT 30 NOT NULL,
    monthly_price numeric(10,2),
    annual_price numeric(10,2),
    features text[] DEFAULT '{}'::text[] NOT NULL,
    differentiators text[] DEFAULT '{}'::text[] NOT NULL,
    storage_gb integer DEFAULT 1 NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.plans OWNER TO aggios;

--
-- Name: TABLE plans; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON TABLE public.plans IS 'Subscription plans for agencies';


--
-- Name: COLUMN plans.max_users; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.plans.max_users IS '-1 means unlimited users';


--
-- 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: solutions; Type: TABLE; Schema: public; Owner: aggios
--

CREATE TABLE public.solutions (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    name character varying(100) NOT NULL,
    slug character varying(50) NOT NULL,
    icon character varying(50),
    description text,
    is_active boolean DEFAULT true,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.solutions OWNER TO aggios;

--
-- Name: COLUMN solutions.slug; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.solutions.slug IS 'Slug usado para identificar a soluÃ§Ã£o no menu (deve corresponder ao ID do menu no frontend)';


--
-- Name: COLUMN solutions.icon; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON COLUMN public.solutions.icon IS 'Emoji ou cÃ³digo do Ã­cone para exibiÃ§Ã£o visual';


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

CREATE TABLE public.template_solutions (
    template_id uuid NOT NULL,
    solution_id uuid NOT NULL,
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.template_solutions OWNER TO aggios;

--
-- Name: TABLE template_solutions; Type: COMMENT; Schema: public; Owner: aggios
--

COMMENT ON TABLE public.template_solutions IS 'Relacionamento N:N entre signup templates e solutions - define quais soluÃ§Ãµes estarÃ£o disponÃ­veis ao cadastrar via template';


--
-- 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: agency_signup_templates; Type: TABLE DATA; Schema: public; Owner: aggios
--

COPY public.agency_signup_templates (id, name, slug, description, form_fields, available_modules, custom_primary_color, custom_logo_url, redirect_url, success_message, is_active, usage_count, max_uses, expires_at, created_at, updated_at) FROM stdin;
\.


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

COPY public.agency_subscriptions (id, agency_id, plan_id, billing_type, current_users, status, start_date, renewal_date, created_at, updated_at) FROM stdin;
80bc290e-1a78-45b9-8419-a75137a86c7c	ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc	2cf6727a-bb36-48dc-8b7c-a207834f4943	monthly	1	active	2025-12-15 19:26:27.783807	2026-01-14 19:26:27.783807	2025-12-15 19:26:27.783807	2025-12-15 19:26:27.783807
\.


--
-- 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: crm_customer_lists; Type: TABLE DATA; Schema: public; Owner: aggios
--

COPY public.crm_customer_lists (customer_id, list_id, added_at, added_by) FROM stdin;
\.


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

COPY public.crm_customers (id, tenant_id, name, email, phone, company, "position", address, city, state, zip_code, country, notes, tags, is_active, created_by, created_at, updated_at) FROM stdin;
7160a1e0-d8f0-4fce-a62a-9cc706118ecd	ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc	teste	teste@gmail.com	13996465280	asda	asda					Brasil	asd	{dasdas}	t	8742c1a1-5f1a-4df3-aa53-dcf94a2a2591	2025-12-16 03:13:10.576109	2025-12-16 03:13:10.576109
\.


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

COPY public.crm_lists (id, tenant_id, name, description, color, created_by, created_at, updated_at) FROM stdin;
f8366f56-755e-4a5a-b784-dbc6e11564c8	ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc	teste	teste	#EC4899	8742c1a1-5f1a-4df3-aa53-dcf94a2a2591	2025-12-16 18:48:38.051286	2025-12-16 18:48:38.051286
\.


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

COPY public.plan_solutions (plan_id, solution_id, created_at) FROM stdin;
2cf6727a-bb36-48dc-8b7c-a207834f4943	00000000-0000-0000-0000-000000000001	2025-12-16 22:47:41.092009
\.


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

COPY public.plans (id, name, slug, description, min_users, max_users, monthly_price, annual_price, features, differentiators, storage_gb, is_active, created_at, updated_at) FROM stdin;
2cf6727a-bb36-48dc-8b7c-a207834f4943	Ignites	ignite	Plano simples aggios.app	1	30	199.00	1990.00	{}	{}	1	t	2025-12-15 00:04:13.710353	2025-12-16 19:47:41.08154
\.


--
-- 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: solutions; Type: TABLE DATA; Schema: public; Owner: aggios
--

COPY public.solutions (id, name, slug, icon, description, is_active, created_at, updated_at) FROM stdin;
00000000-0000-0000-0000-000000000001	CRM	crm		Gestão de Relacionamento com Clientes	t	2025-12-15 02:58:24.89748	2025-12-15 02:58:24.89748
00000000-0000-0000-0000-000000000002	ERP	erp		Gestão Empresarial e Financeira	t	2025-12-15 19:46:10.537836	2025-12-15 19:46:10.537836
00000000-0000-0000-0000-000000000003	Projetos	projetos		Gestão de Projetos e Tarefas	t	2025-12-15 19:46:10.537836	2025-12-15 19:46:10.537836
00000000-0000-0000-0000-000000000004	Helpdesk	helpdesk		Central de Atendimento e Suporte	t	2025-12-15 19:46:10.537836	2025-12-15 19:46:10.537836
00000000-0000-0000-0000-000000000005	Pagamentos	pagamentos		Gestão de Cobranças e Pagamentos	t	2025-12-15 19:46:10.537836	2025-12-15 19:46:10.537836
00000000-0000-0000-0000-000000000006	Contratos	contratos		Gestão de Contratos e Documentos Legais	t	2025-12-15 19:46:10.537836	2025-12-15 19:46:10.537836
00000000-0000-0000-0000-000000000007	Documentos	documentos		Armazenamento e Gestão de Arquivos	t	2025-12-15 19:46:10.537836	2025-12-15 19:46:10.537836
00000000-0000-0000-0000-000000000008	Redes Sociais	social		Gestão de Redes Sociais	t	2025-12-15 19:46:10.537836	2025-12-15 22:06:15.81116
\.


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

COPY public.template_solutions (template_id, solution_id, 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;
3c4c1d84-8645-49d1-a24e-3bae60525cbc	avon	avon.localhost	avon	56.991.441/0001-57	AVON COSMETICOS LTDA.	adriana@avon.com.br	(13) 9946-5280	eeeeeeeeeeeeeeeeeeeeeee	Rua Quatorze, 14 - Casa	Guarujá	SP	11436-575	eeeeeeeeeeeeeeeeeeeeee	agencia-digital	t	2025-12-17 03:13:38.790798+00	2025-12-17 03:13:38.790798+00	Vila Zilda	\N	14	Casa	1-10	#e5014c	#FF0080	data:image/jpeg;base64,[encoded data, 63800 characters]	
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-16 22:40:21.289552+00	Vila Zilda	\N	150	Casa	1-10	#5a1bee	#A78BFA	http://api.localhost/api/files/aggios-logos/tenants/ae271be0-a63c-407f-9cf6-a4a8c8a0a4dc/logo-1765924821.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
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
d49c08b8-b115-4032-aaf7-ed50e62d511c	3c4c1d84-8645-49d1-a24e-3bae60525cbc	adriana@avon.com.br	$2a$10$MBiRsT1K7pp4lH2JIKg4SeUQrb461rxN0/.x1Ibgae/IFI.aK418a	Adriana Ribeiro	\N	ADMIN_AGENCIA	t	2025-12-17 03:13:38.832374+00	2025-12-17 03:13:38.832374+00
\.


--
-- Name: agency_signup_templates agency_signup_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.agency_signup_templates
    ADD CONSTRAINT agency_signup_templates_pkey PRIMARY KEY (id);


--
-- Name: agency_signup_templates agency_signup_templates_slug_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.agency_signup_templates
    ADD CONSTRAINT agency_signup_templates_slug_key UNIQUE (slug);


--
-- Name: agency_subscriptions agency_subscriptions_agency_id_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.agency_subscriptions
    ADD CONSTRAINT agency_subscriptions_agency_id_key UNIQUE (agency_id);


--
-- Name: agency_subscriptions agency_subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.agency_subscriptions
    ADD CONSTRAINT agency_subscriptions_pkey PRIMARY KEY (id);


--
-- 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: crm_customer_lists crm_customer_lists_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customer_lists
    ADD CONSTRAINT crm_customer_lists_pkey PRIMARY KEY (customer_id, list_id);


--
-- Name: crm_customers crm_customers_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customers
    ADD CONSTRAINT crm_customers_pkey PRIMARY KEY (id);


--
-- Name: crm_lists crm_lists_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_lists
    ADD CONSTRAINT crm_lists_pkey PRIMARY KEY (id);


--
-- Name: plan_solutions plan_solutions_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.plan_solutions
    ADD CONSTRAINT plan_solutions_pkey PRIMARY KEY (plan_id, solution_id);


--
-- Name: plans plans_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.plans
    ADD CONSTRAINT plans_pkey PRIMARY KEY (id);


--
-- Name: plans plans_slug_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.plans
    ADD CONSTRAINT plans_slug_key UNIQUE (slug);


--
-- 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: solutions solutions_name_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.solutions
    ADD CONSTRAINT solutions_name_key UNIQUE (name);


--
-- Name: solutions solutions_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.solutions
    ADD CONSTRAINT solutions_pkey PRIMARY KEY (id);


--
-- Name: solutions solutions_slug_key; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.solutions
    ADD CONSTRAINT solutions_slug_key UNIQUE (slug);


--
-- Name: template_solutions template_solutions_pkey; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.template_solutions
    ADD CONSTRAINT template_solutions_pkey PRIMARY KEY (template_id, solution_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: crm_customers unique_email_per_tenant; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customers
    ADD CONSTRAINT unique_email_per_tenant UNIQUE (tenant_id, email);


--
-- Name: crm_lists unique_list_per_tenant; Type: CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_lists
    ADD CONSTRAINT unique_list_per_tenant UNIQUE (tenant_id, name);


--
-- 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_agency_subscriptions_agency_id; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_agency_subscriptions_agency_id ON public.agency_subscriptions USING btree (agency_id);


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

CREATE INDEX idx_agency_subscriptions_plan_id ON public.agency_subscriptions USING btree (plan_id);


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

CREATE INDEX idx_agency_subscriptions_status ON public.agency_subscriptions USING btree (status);


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

CREATE INDEX idx_agency_templates_active ON public.agency_signup_templates USING btree (is_active);


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

CREATE INDEX idx_agency_templates_slug ON public.agency_signup_templates USING btree (slug);


--
-- 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_crm_customer_lists_customer_id; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_crm_customer_lists_customer_id ON public.crm_customer_lists USING btree (customer_id);


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

CREATE INDEX idx_crm_customer_lists_list_id ON public.crm_customer_lists USING btree (list_id);


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

CREATE INDEX idx_crm_customers_email ON public.crm_customers USING btree (email);


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

CREATE INDEX idx_crm_customers_is_active ON public.crm_customers USING btree (is_active);


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

CREATE INDEX idx_crm_customers_name ON public.crm_customers USING btree (name);


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

CREATE INDEX idx_crm_customers_tags ON public.crm_customers USING gin (tags);


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

CREATE INDEX idx_crm_customers_tenant_id ON public.crm_customers USING btree (tenant_id);


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

CREATE INDEX idx_crm_lists_name ON public.crm_lists USING btree (name);


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

CREATE INDEX idx_crm_lists_tenant_id ON public.crm_lists USING btree (tenant_id);


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

CREATE INDEX idx_plan_solutions_plan_id ON public.plan_solutions USING btree (plan_id);


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

CREATE INDEX idx_plan_solutions_solution_id ON public.plan_solutions USING btree (solution_id);


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

CREATE INDEX idx_plans_is_active ON public.plans USING btree (is_active);


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

CREATE INDEX idx_plans_slug ON public.plans USING btree (slug);


--
-- 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_solutions_is_active; Type: INDEX; Schema: public; Owner: aggios
--

CREATE INDEX idx_solutions_is_active ON public.solutions USING btree (is_active);


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

CREATE INDEX idx_solutions_slug ON public.solutions USING btree (slug);


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

CREATE INDEX idx_template_solutions_solution ON public.template_solutions USING btree (solution_id);


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

CREATE INDEX idx_template_solutions_template ON public.template_solutions USING btree (template_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: crm_customers update_crm_customers_updated_at; Type: TRIGGER; Schema: public; Owner: aggios
--

CREATE TRIGGER update_crm_customers_updated_at BEFORE UPDATE ON public.crm_customers FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: crm_lists update_crm_lists_updated_at; Type: TRIGGER; Schema: public; Owner: aggios
--

CREATE TRIGGER update_crm_lists_updated_at BEFORE UPDATE ON public.crm_lists FOR EACH ROW EXECUTE FUNCTION public.update_updated_at_column();


--
-- Name: agency_subscriptions agency_subscriptions_agency_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.agency_subscriptions
    ADD CONSTRAINT agency_subscriptions_agency_id_fkey FOREIGN KEY (agency_id) REFERENCES public.tenants(id) ON DELETE CASCADE;


--
-- Name: agency_subscriptions agency_subscriptions_plan_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.agency_subscriptions
    ADD CONSTRAINT agency_subscriptions_plan_id_fkey FOREIGN KEY (plan_id) REFERENCES public.plans(id) ON DELETE RESTRICT;


--
-- 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: crm_customer_lists crm_customer_lists_added_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customer_lists
    ADD CONSTRAINT crm_customer_lists_added_by_fkey FOREIGN KEY (added_by) REFERENCES public.users(id);


--
-- Name: crm_customer_lists crm_customer_lists_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customer_lists
    ADD CONSTRAINT crm_customer_lists_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.crm_customers(id) ON DELETE CASCADE;


--
-- Name: crm_customer_lists crm_customer_lists_list_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customer_lists
    ADD CONSTRAINT crm_customer_lists_list_id_fkey FOREIGN KEY (list_id) REFERENCES public.crm_lists(id) ON DELETE CASCADE;


--
-- Name: crm_customers crm_customers_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_customers
    ADD CONSTRAINT crm_customers_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: crm_customers crm_customers_tenant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

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


--
-- Name: crm_lists crm_lists_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.crm_lists
    ADD CONSTRAINT crm_lists_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: crm_lists crm_lists_tenant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

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


--
-- Name: plan_solutions plan_solutions_plan_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.plan_solutions
    ADD CONSTRAINT plan_solutions_plan_id_fkey FOREIGN KEY (plan_id) REFERENCES public.plans(id) ON DELETE CASCADE;


--
-- Name: plan_solutions plan_solutions_solution_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.plan_solutions
    ADD CONSTRAINT plan_solutions_solution_id_fkey FOREIGN KEY (solution_id) REFERENCES public.solutions(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: template_solutions template_solutions_solution_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.template_solutions
    ADD CONSTRAINT template_solutions_solution_id_fkey FOREIGN KEY (solution_id) REFERENCES public.solutions(id) ON DELETE CASCADE;


--
-- Name: template_solutions template_solutions_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: aggios
--

ALTER TABLE ONLY public.template_solutions
    ADD CONSTRAINT template_solutions_template_id_fkey FOREIGN KEY (template_id) REFERENCES public.agency_signup_templates(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 ncvzwECg3gFaKDQN1qiZ5Czm3zMLkxhxcfcv3fVgXaROlVKnomYb3Jc6VjtZXqC

