chore(release): snapshot 1.4.2
This commit is contained in:
12
postgres/fix_admin_password.sql
Normal file
12
postgres/fix_admin_password.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
DELETE FROM users WHERE email = 'admin@aggios.app';
|
||||
INSERT INTO users (id, email, password_hash, first_name, role, is_active, created_at, updated_at)
|
||||
VALUES (
|
||||
gen_random_uuid(),
|
||||
'admin@aggios.app',
|
||||
'$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
|
||||
'Admin Master',
|
||||
'SUPERADMIN',
|
||||
true,
|
||||
NOW(),
|
||||
NOW()
|
||||
);
|
||||
15
postgres/migrations/012_add_tenant_address_fields.sql
Normal file
15
postgres/migrations/012_add_tenant_address_fields.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- Migration para adicionar colunas de endereco completas e personalizacao
|
||||
-- Criada em 2025-12-13 para corrigir problema de colunas faltantes
|
||||
|
||||
ALTER TABLE tenants
|
||||
ADD COLUMN IF NOT EXISTS neighborhood VARCHAR(100),
|
||||
ADD COLUMN IF NOT EXISTS street VARCHAR(100),
|
||||
ADD COLUMN IF NOT EXISTS number VARCHAR(20),
|
||||
ADD COLUMN IF NOT EXISTS complement VARCHAR(100),
|
||||
ADD COLUMN IF NOT EXISTS team_size VARCHAR(20),
|
||||
ADD COLUMN IF NOT EXISTS primary_color VARCHAR(7),
|
||||
ADD COLUMN IF NOT EXISTS secondary_color VARCHAR(7),
|
||||
ADD COLUMN IF NOT EXISTS logo_url TEXT,
|
||||
ADD COLUMN IF NOT EXISTS logo_horizontal_url TEXT;
|
||||
|
||||
-- Comentario: Estas colunas sao necessarias para o cadastro completo de agencias e personalizacao
|
||||
30
postgres/migrations/013_create_solutions_table.sql
Normal file
30
postgres/migrations/013_create_solutions_table.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
-- Tabela de soluções disponíveis (CRM, ERP, etc.)
|
||||
CREATE TABLE IF NOT EXISTS solutions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
slug VARCHAR(50) NOT NULL UNIQUE,
|
||||
icon VARCHAR(50),
|
||||
description TEXT,
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Relacionamento N:N entre planos e soluções
|
||||
CREATE TABLE IF NOT EXISTS plan_solutions (
|
||||
plan_id UUID REFERENCES plans(id) ON DELETE CASCADE,
|
||||
solution_id UUID REFERENCES solutions(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (plan_id, solution_id)
|
||||
);
|
||||
|
||||
-- Índices
|
||||
CREATE INDEX idx_solutions_slug ON solutions(slug);
|
||||
CREATE INDEX idx_solutions_is_active ON solutions(is_active);
|
||||
CREATE INDEX idx_plan_solutions_plan_id ON plan_solutions(plan_id);
|
||||
CREATE INDEX idx_plan_solutions_solution_id ON plan_solutions(solution_id);
|
||||
|
||||
-- Seed inicial: CRM
|
||||
INSERT INTO solutions (id, name, slug, icon, description, is_active) VALUES
|
||||
('00000000-0000-0000-0000-000000000001', 'CRM', 'crm', 'users', 'Gestão de clientes e relacionamento', true)
|
||||
ON CONFLICT (slug) DO NOTHING;
|
||||
86
postgres/migrations/014_create_crm_tables.sql
Normal file
86
postgres/migrations/014_create_crm_tables.sql
Normal file
@@ -0,0 +1,86 @@
|
||||
-- Tabela de clientes do CRM (multi-tenant)
|
||||
CREATE TABLE IF NOT EXISTS crm_customers (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
|
||||
-- Dados básicos
|
||||
name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255),
|
||||
phone VARCHAR(50),
|
||||
company VARCHAR(255),
|
||||
position VARCHAR(100),
|
||||
|
||||
-- Endereço
|
||||
address VARCHAR(255),
|
||||
city VARCHAR(100),
|
||||
state VARCHAR(50),
|
||||
zip_code VARCHAR(20),
|
||||
country VARCHAR(100) DEFAULT 'Brasil',
|
||||
|
||||
-- Informações adicionais
|
||||
notes TEXT,
|
||||
tags TEXT[], -- Array de tags para filtros rápidos
|
||||
|
||||
-- Controle
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_by UUID REFERENCES users(id),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
-- Constraint: email deve ser único por agência (pode repetir entre agências)
|
||||
CONSTRAINT unique_email_per_tenant UNIQUE (tenant_id, email)
|
||||
);
|
||||
|
||||
-- Tabela de listas para organizar clientes
|
||||
CREATE TABLE IF NOT EXISTS crm_lists (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
|
||||
name VARCHAR(100) NOT NULL,
|
||||
description TEXT,
|
||||
color VARCHAR(7) DEFAULT '#3b82f6', -- Hex color
|
||||
|
||||
created_by UUID REFERENCES users(id),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
-- Lista deve ter nome único por agência
|
||||
CONSTRAINT unique_list_per_tenant UNIQUE (tenant_id, name)
|
||||
);
|
||||
|
||||
-- Relacionamento N:N entre clientes e listas
|
||||
CREATE TABLE IF NOT EXISTS crm_customer_lists (
|
||||
customer_id UUID REFERENCES crm_customers(id) ON DELETE CASCADE,
|
||||
list_id UUID REFERENCES crm_lists(id) ON DELETE CASCADE,
|
||||
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
added_by UUID REFERENCES users(id),
|
||||
PRIMARY KEY (customer_id, list_id)
|
||||
);
|
||||
|
||||
-- Índices para performance
|
||||
CREATE INDEX idx_crm_customers_tenant_id ON crm_customers(tenant_id);
|
||||
CREATE INDEX idx_crm_customers_email ON crm_customers(email);
|
||||
CREATE INDEX idx_crm_customers_name ON crm_customers(name);
|
||||
CREATE INDEX idx_crm_customers_is_active ON crm_customers(is_active);
|
||||
CREATE INDEX idx_crm_customers_tags ON crm_customers USING GIN(tags);
|
||||
|
||||
CREATE INDEX idx_crm_lists_tenant_id ON crm_lists(tenant_id);
|
||||
CREATE INDEX idx_crm_lists_name ON crm_lists(name);
|
||||
|
||||
CREATE INDEX idx_crm_customer_lists_customer_id ON crm_customer_lists(customer_id);
|
||||
CREATE INDEX idx_crm_customer_lists_list_id ON crm_customer_lists(list_id);
|
||||
|
||||
-- Trigger para atualizar updated_at
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
|
||||
CREATE TRIGGER update_crm_customers_updated_at BEFORE UPDATE ON crm_customers
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
CREATE TRIGGER update_crm_lists_updated_at BEFORE UPDATE ON crm_lists
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
16
postgres/migrations/015_create_template_solutions.sql
Normal file
16
postgres/migrations/015_create_template_solutions.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- Migration: Vincular Signup Templates com Solutions
|
||||
-- Permite que ao criar um link de cadastro personalizado, o superadmin
|
||||
-- selecione quais soluções estarão disponíveis para as agências que se cadastrarem
|
||||
|
||||
CREATE TABLE IF NOT EXISTS template_solutions (
|
||||
template_id UUID NOT NULL REFERENCES agency_signup_templates(id) ON DELETE CASCADE,
|
||||
solution_id UUID NOT NULL REFERENCES solutions(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (template_id, solution_id)
|
||||
);
|
||||
|
||||
-- Index para queries rápidas
|
||||
CREATE INDEX idx_template_solutions_template ON template_solutions(template_id);
|
||||
CREATE INDEX idx_template_solutions_solution ON template_solutions(solution_id);
|
||||
|
||||
COMMENT ON TABLE template_solutions IS 'Relacionamento N:N entre signup templates e solutions - define quais soluções estarão disponíveis ao cadastrar via template';
|
||||
28
postgres/migrations/016_seed_all_solutions.sql
Normal file
28
postgres/migrations/016_seed_all_solutions.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
-- Migration: Seed todas as soluções do sistema
|
||||
-- Cria todas as solutions disponíveis para que o superadmin possa gerenciar
|
||||
-- quais aparecem nos planos das agências
|
||||
|
||||
-- Inserir todas as soluções (CRM já existe, apenas atualizar se necessário)
|
||||
INSERT INTO solutions (id, name, slug, icon, description, is_active) VALUES
|
||||
-- CRM já existe, mas vamos garantir que está correto
|
||||
('00000000-0000-0000-0000-000000000001', 'CRM', 'crm', '🚀', 'Gestão de Relacionamento com Clientes', true)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
slug = EXCLUDED.slug,
|
||||
icon = EXCLUDED.icon,
|
||||
description = EXCLUDED.description;
|
||||
|
||||
-- Inserir novas soluções
|
||||
INSERT INTO solutions (id, name, slug, icon, description, is_active) VALUES
|
||||
('00000000-0000-0000-0000-000000000002', 'ERP', 'erp', '📊', 'Gestão Empresarial e Financeira', true),
|
||||
('00000000-0000-0000-0000-000000000003', 'Projetos', 'projetos', '💼', 'Gestão de Projetos e Tarefas', true),
|
||||
('00000000-0000-0000-0000-000000000004', 'Helpdesk', 'helpdesk', '🆘', 'Central de Atendimento e Suporte', true),
|
||||
('00000000-0000-0000-0000-000000000005', 'Pagamentos', 'pagamentos', '💳', 'Gestão de Cobranças e Pagamentos', true),
|
||||
('00000000-0000-0000-0000-000000000006', 'Contratos', 'contratos', '📄', 'Gestão de Contratos e Documentos Legais', true),
|
||||
('00000000-0000-0000-0000-000000000007', 'Documentos', 'documentos', '📁', 'Armazenamento e Gestão de Arquivos', true),
|
||||
('00000000-0000-0000-0000-000000000008', 'Redes Sociais', 'social', '🔗', 'Gestão de Redes Sociais', true)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
-- Comentários explicativos
|
||||
COMMENT ON COLUMN solutions.slug IS 'Slug usado para identificar a solução no menu (deve corresponder ao ID do menu no frontend)';
|
||||
COMMENT ON COLUMN solutions.icon IS 'Emoji ou código do ícone para exibição visual';
|
||||
11
postgres/migrations/017_fix_solutions_utf8.sql
Normal file
11
postgres/migrations/017_fix_solutions_utf8.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Migration: Corrigir encoding UTF-8 das descrições das soluções
|
||||
-- Atualiza as descrições que estão com caracteres bugados
|
||||
|
||||
UPDATE solutions SET description = 'Gestão de Relacionamento com Clientes' WHERE slug = 'crm';
|
||||
UPDATE solutions SET description = 'Gestão Empresarial e Financeira' WHERE slug = 'erp';
|
||||
UPDATE solutions SET description = 'Gestão de Projetos e Tarefas' WHERE slug = 'projetos';
|
||||
UPDATE solutions SET description = 'Central de Atendimento e Suporte' WHERE slug = 'helpdesk';
|
||||
UPDATE solutions SET description = 'Gestão de Cobranças e Pagamentos' WHERE slug = 'pagamentos';
|
||||
UPDATE solutions SET description = 'Gestão de Contratos e Documentos Legais' WHERE slug = 'contratos';
|
||||
UPDATE solutions SET description = 'Armazenamento e Gestão de Arquivos' WHERE slug = 'documentos';
|
||||
UPDATE solutions SET description = 'Gestão de Redes Sociais' WHERE slug = 'social';
|
||||
Reference in New Issue
Block a user