One Hat Cyber Team
Your IP :
216.73.216.36
Server IP :
162.240.179.46
Server :
Linux vps-14493116.nutrivittasaude.com.br 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
Server Software :
Apache
PHP Version :
8.2.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
lifeprimeti
/
meta.lifeprimeti.com.br
/
sql
/
Edit File:
schema.sql
-- ============================================================ -- BARBEARIA PRIME - Complete Database Schema -- Run this to install from scratch on a fresh system -- ============================================================ -- Se precisar criar o banco (local), descomente: -- CREATE DATABASE IF NOT EXISTS barbearia_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; -- USE barbearia_db; -- Drop all tables in reverse FK order for clean reinstall SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS password_reset_tokens, suporte_respostas, suporte_tickets, ia_prompts, lembretes_config, disparos, grupos_disparo, campanhas, config_smtp, faturas, comissoes, anexos, caixa_movimentos, caixa, contas_pagar, contas_receber, fornecedores, frequencias, formas_pagamento, whatsapp_config, pagamentos, agendamentos, bloqueio_dias, horarios_profissionais, horarios_sistema, servicos_profissionais, servicos, profissionais, cargos, usuarios, grupos, configuracoes, empresas, planos; SET FOREIGN_KEY_CHECKS = 1; -- PLANOS (SaaS) CREATE TABLE planos ( id INT AUTO_INCREMENT PRIMARY KEY, nome VARCHAR(100) NOT NULL, valor DECIMAL(10,2) NOT NULL DEFAULT 0, recorencia ENUM('mensal','trimestral','semestral','anual') NOT NULL DEFAULT 'mensal', limite_profissionais INT DEFAULT 0, limite_clientes INT DEFAULT 0, recursos JSON, whatsapp_available TINYINT(1) DEFAULT 0, gateway_hubpay TINYINT(1) DEFAULT 1, gateway_mercadopago TINYINT(1) DEFAULT 0, gateway_asaas TINYINT(1) DEFAULT 0, gateway_manual TINYINT(1) DEFAULT 1, ativo TINYINT(1) NOT NULL DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- EMPRESAS (SaaS multi-tenant) CREATE TABLE empresas ( id INT AUTO_INCREMENT PRIMARY KEY, plano_id INT NULL, nome VARCHAR(200) NOT NULL, slug VARCHAR(100) NOT NULL UNIQUE, documento VARCHAR(20), telefone VARCHAR(20), email VARCHAR(100), endereco TEXT, logo VARCHAR(255), cor_primaria VARCHAR(7) DEFAULT '#667eea', cor_secundaria VARCHAR(7) DEFAULT '#764ba2', ativo TINYINT(1) NOT NULL DEFAULT 1, aprovado TINYINT(1) NOT NULL DEFAULT 0, bloqueado TINYINT(1) NOT NULL DEFAULT 0, bloqueado_motivo VARCHAR(255) DEFAULT NULL, bloqueado_em DATETIME DEFAULT NULL, payment_gateway ENUM('hubpay','mercadopago','asaas','manual') DEFAULT NULL, payment_due_date DATE NULL, payment_grace_start DATETIME DEFAULT NULL, ultima_fatura_gerada DATE NULL, plano_valor DECIMAL(10,2) DEFAULT 0, data_expiracao DATE NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (plano_id) REFERENCES planos(id) ON DELETE SET NULL ); -- GRUPOS DE ACESSO (ACL) CREATE TABLE grupos ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, nome VARCHAR(100) NOT NULL, descricao TEXT, permissoes JSON NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- USUARIOS CREATE TABLE usuarios ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, grupo_id INT NULL, nome VARCHAR(100) NOT NULL, email VARCHAR(100) NOT NULL, telefone VARCHAR(20), senha VARCHAR(255) NOT NULL, tipo ENUM('super_admin','admin','profissional','cliente') NOT NULL DEFAULT 'cliente', foto VARCHAR(255), ativo TINYINT(1) NOT NULL DEFAULT 1, aprovado TINYINT(1) NOT NULL DEFAULT 0, hash_link VARCHAR(100) UNIQUE, whatsapp VARCHAR(20), data_nascimento DATE NULL, cep VARCHAR(9), endereco VARCHAR(255), numero VARCHAR(20), complemento VARCHAR(100), bairro VARCHAR(100), cidade VARCHAR(100), estado CHAR(2), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (grupo_id) REFERENCES grupos(id) ON DELETE SET NULL ); -- CARGOS CREATE TABLE cargos ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, nome VARCHAR(100) NOT NULL, ativo TINYINT(1) DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- PROFISSIONAIS CREATE TABLE profissionais ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, usuario_id INT NOT NULL UNIQUE, foto VARCHAR(255), especialidade VARCHAR(255), descricao TEXT, cor_calendario VARCHAR(7) DEFAULT '#667eea', comissao_tipo ENUM('percentual','fixo') NOT NULL DEFAULT 'percentual', comissao_valor DECIMAL(10,2) DEFAULT 0, cargo_id INT NULL, mostrar TINYINT(1) DEFAULT 1, data_nascimento DATE NULL, cpf VARCHAR(14) NULL, chave_pix_tipo ENUM('telefone','cpf','aleatoria','cnpj','email') NULL, chave_pix VARCHAR(255) NULL, cep VARCHAR(10) NULL, endereco VARCHAR(255) NULL, numero VARCHAR(20) NULL, complemento VARCHAR(100) NULL, bairro VARCHAR(100) NULL, cidade VARCHAR(100) NULL, estado CHAR(2) NULL, ativo TINYINT(1) NOT NULL DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE ); -- SERVICOS CREATE TABLE servicos ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, nome VARCHAR(150) NOT NULL, descricao TEXT, preco DECIMAL(10,2) NOT NULL, duracao INT NOT NULL COMMENT 'duracao em minutos', foto VARCHAR(255), comissao_tipo ENUM('percentual','fixo') NOT NULL DEFAULT 'percentual', comissao_valor DECIMAL(10,2) DEFAULT 0, ativo TINYINT(1) NOT NULL DEFAULT 1, mostrar_site TINYINT(1) NOT NULL DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- SERVICOS PROFISSIONAIS CREATE TABLE servicos_profissionais ( id INT AUTO_INCREMENT PRIMARY KEY, profissional_id INT NOT NULL, servico_id INT NOT NULL, preco DECIMAL(10,2) NULL, duracao INT NULL, comissao_tipo ENUM('percentual','fixo') NULL, comissao_valor DECIMAL(10,2) NULL, FOREIGN KEY (profissional_id) REFERENCES profissionais(id) ON DELETE CASCADE, FOREIGN KEY (servico_id) REFERENCES servicos(id) ON DELETE CASCADE, UNIQUE KEY unique_prof_serv (profissional_id, servico_id) ); -- HORARIOS SISTEMA CREATE TABLE horarios_sistema ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, dia_semana TINYINT NOT NULL, hora_inicio TIME NOT NULL, hora_fim TIME NOT NULL, intervalo INT NOT NULL DEFAULT 60, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- HORARIOS PROFISSIONAIS CREATE TABLE horarios_profissionais ( id INT AUTO_INCREMENT PRIMARY KEY, profissional_id INT NOT NULL, dia_semana TINYINT NOT NULL, hora_inicio TIME NOT NULL, hora_fim TIME NOT NULL, intervalo_inicio TIME DEFAULT NULL, intervalo_fim TIME DEFAULT NULL, FOREIGN KEY (profissional_id) REFERENCES profissionais(id) ON DELETE CASCADE ); -- BLOQUEIO DE DIAS CREATE TABLE bloqueio_dias ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, profissional_id INT NULL, data DATE NOT NULL, hora_inicio TIME NULL, hora_fim TIME NULL, motivo VARCHAR(255), tipo ENUM('empresa', 'profissional') NOT NULL DEFAULT 'empresa', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (profissional_id) REFERENCES profissionais(id) ON DELETE CASCADE ); -- AGENDAMENTOS CREATE TABLE agendamentos ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, cliente_id INT NOT NULL, profissional_id INT NOT NULL, servico_id INT NOT NULL, data DATE NOT NULL, hora TIME NOT NULL, hora_fim TIME NOT NULL, status ENUM('pendente','confirmado','em_andamento','concluido','cancelado') NOT NULL DEFAULT 'pendente', confirmado_cliente TINYINT(1) NOT NULL DEFAULT 0, confirmado_admin TINYINT(1) NOT NULL DEFAULT 0, pagamento_tipo ENUM('gratis','manual','mercadopago','asaas') DEFAULT 'gratis', pagamento_status ENUM('pendente','aprovado','recusado','cancelado') DEFAULT 'pendente', observacao TEXT, lembrete_enviado TINYINT(1) NOT NULL DEFAULT 0, hubpay_charge_id VARCHAR(100) DEFAULT NULL, hubpay_pix_copy_paste TEXT DEFAULT NULL, hubpay_pix_qrcode TEXT DEFAULT NULL, hash_link VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (cliente_id) REFERENCES usuarios(id) ON DELETE CASCADE, FOREIGN KEY (profissional_id) REFERENCES profissionais(id) ON DELETE CASCADE, FOREIGN KEY (servico_id) REFERENCES servicos(id) ON DELETE CASCADE, INDEX idx_data (data), INDEX idx_status (status) ); -- PAGAMENTOS CREATE TABLE pagamentos ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, agendamento_id INT NOT NULL, cliente_id INT NOT NULL, valor DECIMAL(10,2) NOT NULL, taxa DECIMAL(10,2) DEFAULT 0, metodo ENUM('dinheiro','pix','cartao','boleto','asaas','mercadopago') NOT NULL DEFAULT 'pix', status ENUM('pendente','aprovado','recusado','cancelado') NOT NULL DEFAULT 'pendente', transacao_id VARCHAR(255), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (agendamento_id) REFERENCES agendamentos(id) ON DELETE CASCADE, FOREIGN KEY (cliente_id) REFERENCES usuarios(id) ON DELETE CASCADE ); -- FORMAS DE PAGAMENTO CREATE TABLE formas_pagamento ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, nome VARCHAR(100) NOT NULL, taxa DECIMAL(5,2) DEFAULT 0, ativo TINYINT(1) DEFAULT 1, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- FREQUENCIAS CREATE TABLE frequencias ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, nome VARCHAR(100) NOT NULL, dias INT NOT NULL, ativo TINYINT(1) DEFAULT 1, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- FORNECEDORES CREATE TABLE fornecedores ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, cpf_cnpj VARCHAR(20) UNIQUE, razao_social VARCHAR(200), nome_fantasia VARCHAR(200), email VARCHAR(100), telefones JSON, chave_pix_tipo ENUM('telefone','cpf','aleatoria','cnpj','email') NULL, chave_pix VARCHAR(255), cep VARCHAR(10), endereco VARCHAR(255), numero VARCHAR(20), complemento VARCHAR(100), bairro VARCHAR(100), cidade VARCHAR(100), estado CHAR(2), ativo TINYINT(1) DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- CONTAS A RECEBER CREATE TABLE contas_receber ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, agendamento_id INT NOT NULL, cliente_id INT NOT NULL, profissional_id INT NOT NULL, servico_id INT NOT NULL, descricao VARCHAR(255), forma_pagamento_id INT NULL, frequencia_id INT NULL, recorrente TINYINT(1) DEFAULT 0, total_vezes INT DEFAULT 0, parcela_atual INT DEFAULT 0, juros DECIMAL(10,2) DEFAULT 0, mora DECIMAL(10,2) DEFAULT 0, observacoes TEXT, valor_total DECIMAL(10,2) NOT NULL, valor_recebido DECIMAL(10,2) DEFAULT 0, comissao_valor DECIMAL(10,2) DEFAULT 0, repasse_profissional DECIMAL(10,2) DEFAULT 0, status ENUM('pendente','parcial','pago','cancelado') NOT NULL DEFAULT 'pendente', data_vencimento DATE, data_pagamento DATE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (agendamento_id) REFERENCES agendamentos(id) ON DELETE CASCADE, FOREIGN KEY (forma_pagamento_id) REFERENCES formas_pagamento(id) ON DELETE SET NULL, FOREIGN KEY (frequencia_id) REFERENCES frequencias(id) ON DELETE SET NULL ); -- CONTAS A PAGAR CREATE TABLE contas_pagar ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, descricao VARCHAR(255) NOT NULL, fornecedor VARCHAR(200), fornecedor_id INT NULL, profissional_id INT NULL, forma_pagamento_id INT NULL, frequencia_id INT NULL, recorrente TINYINT(1) DEFAULT 0, total_vezes INT DEFAULT 0, parcela_atual INT DEFAULT 0, observacoes TEXT, valor DECIMAL(10,2) NOT NULL, repasse_profissional_id INT NULL, tipo ENUM('despesa','repasse','comissao','aluguel','agua','luz','internet','outro') NOT NULL DEFAULT 'despesa', status ENUM('pendente','pago','cancelado') NOT NULL DEFAULT 'pendente', data_vencimento DATE, data_pagamento DATE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (fornecedor_id) REFERENCES fornecedores(id) ON DELETE SET NULL, FOREIGN KEY (forma_pagamento_id) REFERENCES formas_pagamento(id) ON DELETE SET NULL, FOREIGN KEY (frequencia_id) REFERENCES frequencias(id) ON DELETE SET NULL, FOREIGN KEY (repasse_profissional_id) REFERENCES profissionais(id) ON DELETE SET NULL ); -- COMISSOES CREATE TABLE comissoes ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, profissional_id INT NOT NULL, periodo_inicio DATE NOT NULL, periodo_fim DATE NOT NULL, valor DECIMAL(10,2) NOT NULL, status ENUM('pendente','pago','cancelado') NOT NULL DEFAULT 'pendente', forma_pagamento_id INT NULL, data_pagamento DATE NULL, observacao TEXT, contas_pagar_id INT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (profissional_id) REFERENCES profissionais(id) ON DELETE CASCADE, UNIQUE KEY uk_comissao_periodo (empresa_id, profissional_id, periodo_inicio, periodo_fim) ); -- ANEXOS CREATE TABLE anexos ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, modelo VARCHAR(50) NOT NULL, modelo_id INT NOT NULL, nome_original VARCHAR(255), arquivo VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- CAIXA / PDV CREATE TABLE caixa ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, usuario_id INT NOT NULL, data_abertura DATETIME NOT NULL, data_fechamento DATETIME NULL, valor_abertura DECIMAL(10,2) NOT NULL DEFAULT 0, valor_fechamento DECIMAL(10,2) DEFAULT 0, status ENUM('aberto','fechado') NOT NULL DEFAULT 'aberto', observacoes TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE ); CREATE TABLE caixa_movimentos ( id INT AUTO_INCREMENT PRIMARY KEY, caixa_id INT NOT NULL, tipo ENUM('entrada','saida','sangria','suprimento') NOT NULL, descricao VARCHAR(255), valor DECIMAL(10,2) NOT NULL, forma_pagamento_id INT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (caixa_id) REFERENCES caixa(id) ON DELETE CASCADE, FOREIGN KEY (forma_pagamento_id) REFERENCES formas_pagamento(id) ON DELETE SET NULL ); -- CONFIGURACOES (per-company) CREATE TABLE configuracoes ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL UNIQUE, opcao_pagar ENUM('sim','nao') NOT NULL DEFAULT 'nao', gateway_padrao ENUM('mercadopago','asaas','nenhum') NOT NULL DEFAULT 'nenhum', mp_public_key VARCHAR(255), mp_access_token VARCHAR(255), asaas_api_key VARCHAR(255), asaas_token VARCHAR(255), whatsapp_api VARCHAR(255), whatsapp_token VARCHAR(255), whatsapp_instance VARCHAR(100), horario_inicio TIME DEFAULT '08:00', horario_fim TIME DEFAULT '18:00', intervalo_padrao INT DEFAULT 0, confirma_cadastro TINYINT(1) NOT NULL DEFAULT 1, confirma_agendamento TINYINT(1) NOT NULL DEFAULT 1, smtp_host VARCHAR(255) DEFAULT '', smtp_porta INT DEFAULT 587, smtp_usuario VARCHAR(255) DEFAULT '', smtp_senha VARCHAR(255) DEFAULT '', smtp_criptografia ENUM('tls','ssl','nenhuma') NOT NULL DEFAULT 'tls', smtp_email_from VARCHAR(255) DEFAULT '', smtp_nome_from VARCHAR(255) DEFAULT '', smtp_ativo TINYINT(1) NOT NULL DEFAULT 0, openai_api_key VARCHAR(255), gemini_api_key VARCHAR(255), claude_api_key VARCHAR(255), waba_phone_id VARCHAR(100) DEFAULT '', waba_token VARCHAR(512) DEFAULT '', waba_business_id VARCHAR(100) DEFAULT '', waba_webhook_token VARCHAR(100) DEFAULT '', lembrete_ativo TINYINT(1) NOT NULL DEFAULT 0, lembrete_timezone VARCHAR(50) DEFAULT 'America/Sao_Paulo', lembrete_metodo ENUM('email','whatsapp','digigo') NOT NULL DEFAULT 'email', hubpay_api_key VARCHAR(255) DEFAULT '', hubpay_webhook_secret VARCHAR(255) DEFAULT '', hubpay_ambiente ENUM('test','live') NOT NULL DEFAULT 'test', digigo_base_url VARCHAR(255) DEFAULT '', digigo_admin_token VARCHAR(512) DEFAULT '', digigo_user_token VARCHAR(512) DEFAULT '', digigo_user_name VARCHAR(100) DEFAULT '', digigo_connected TINYINT(1) DEFAULT 0, digigo_envio_ativo TINYINT(1) DEFAULT 0, digigo_modo ENUM('proprio','global') NOT NULL DEFAULT 'proprio', app_nome VARCHAR(100) DEFAULT NULL, login_bg_tipo ENUM('imagem','video') DEFAULT NULL, login_bg_arquivo VARCHAR(255) DEFAULT NULL, confirmacao_agendamento_ativo TINYINT(1) NOT NULL DEFAULT 0, confirmacao_agendamento_metodo ENUM('email','whatsapp','digigo') NOT NULL DEFAULT 'email', timezone VARCHAR(50) DEFAULT 'America/Sao_Paulo', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- CONFIG SMTP (super admin global) CREATE TABLE config_smtp ( id INT AUTO_INCREMENT PRIMARY KEY, host VARCHAR(255) NOT NULL DEFAULT '', porta INT NOT NULL DEFAULT 587, usuario VARCHAR(255) NOT NULL DEFAULT '', senha VARCHAR(255) NOT NULL DEFAULT '', criptografia ENUM('tls','ssl','nenhuma') NOT NULL DEFAULT 'tls', email_from VARCHAR(255) NOT NULL DEFAULT '', nome_from VARCHAR(255) NOT NULL DEFAULT '', ativo TINYINT(1) NOT NULL DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); -- FATURAS (planos das empresas) CREATE TABLE faturas ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, plano_id INT NULL, valor DECIMAL(10,2) NOT NULL, status ENUM('pendente','paga','vencida','cancelada') NOT NULL DEFAULT 'pendente', metodo ENUM('hubpay','mercadopago','asaas','manual') NOT NULL DEFAULT 'manual', transacao_id VARCHAR(255) DEFAULT NULL, data_vencimento DATE NOT NULL, data_pagamento DATE DEFAULT NULL, enviado_em DATETIME DEFAULT NULL, enviado_por VARCHAR(50) DEFAULT NULL COMMENT 'email|digigo|meta', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (plano_id) REFERENCES planos(id) ON DELETE SET NULL ); -- CAMPANHAS DE MARKETING CREATE TABLE campanhas ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, titulo VARCHAR(200) NOT NULL, assunto VARCHAR(255) NOT NULL, corpo_html TEXT NOT NULL, metodo_envio ENUM('email','whatsapp','digigo') NOT NULL DEFAULT 'email', destinos TEXT DEFAULT NULL COMMENT 'JSON array of user IDs, NULL = all clients', status ENUM('rascunho','agendada','enviada') NOT NULL DEFAULT 'rascunho', data_agendamento DATETIME NULL, enviadas INT NOT NULL DEFAULT 0, total_destinatarios INT NOT NULL DEFAULT 0, delay_min INT NOT NULL DEFAULT 1 COMMENT 'Delay minimo entre envios (segundos)', delay_max INT NOT NULL DEFAULT 5 COMMENT 'Delay maximo entre envios (segundos)', horario_inicio TIME DEFAULT '08:00' COMMENT 'Horario inicio de envio no dia', horario_fim TIME DEFAULT '18:00' COMMENT 'Horario fim de envio no dia', dia_util_only TINYINT(1) NOT NULL DEFAULT 1 COMMENT 'Enviar apenas em dias uteis (seg-sex)', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- GRUPOS DISPARO (old campaign groups, kept for compatibility) CREATE TABLE grupos_disparo ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, campanha_id INT NOT NULL, nome VARCHAR(100) NOT NULL, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (campanha_id) REFERENCES campanhas(id) ON DELETE CASCADE ); -- DISPAROS (old campaign send log, kept for compatibility) CREATE TABLE disparos ( id INT AUTO_INCREMENT PRIMARY KEY, campanha_id INT NOT NULL, contato_id INT NOT NULL, status ENUM('pendente','enviado','falhou') NOT NULL DEFAULT 'pendente', enviado_em DATETIME NULL, FOREIGN KEY (campanha_id) REFERENCES campanhas(id) ON DELETE CASCADE, FOREIGN KEY (contato_id) REFERENCES usuarios(id) ON DELETE CASCADE ); -- WHATSAPP CONFIG (old, kept for compatibility) CREATE TABLE whatsapp_config ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, dispositivo_nome VARCHAR(100), dispositivo_id VARCHAR(255), qr_code TEXT, status ENUM('desconectado','conectando','conectado') NOT NULL DEFAULT 'desconectado', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- LEMBRETES DE AGENDAMENTO CREATE TABLE lembretes_config ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, tipo ENUM('minutos','horas','dias','meses') NOT NULL DEFAULT 'horas', valor INT NOT NULL DEFAULT 1, metodo ENUM('email','whatsapp','digigo') NOT NULL DEFAULT 'email', ativo TINYINT(1) NOT NULL DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- MODELOS DE MENSAGEM CREATE TABLE modelos_mensagem ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, tipo ENUM('confirmacao','cancelamento','lembrete','confirmado','personalizado') NOT NULL DEFAULT 'personalizado', titulo VARCHAR(200) NOT NULL, mensagem_texto TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, UNIQUE KEY uk_empresa_tipo (empresa_id, tipo) ); -- IA / PROMPTS CREATE TABLE ia_prompts ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, titulo VARCHAR(200) NOT NULL, prompt_texto TEXT NOT NULL, ia_provedor ENUM('openai','gemini','claude') NOT NULL DEFAULT 'openai', modelo VARCHAR(100) NOT NULL DEFAULT 'gpt-4o-mini', temperatura DECIMAL(3,2) DEFAULT 0.7, max_tokens INT DEFAULT 2048, ativo TINYINT(1) DEFAULT 1, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE ); -- SUPORTE TECNICO CREATE TABLE suporte_tickets ( id INT AUTO_INCREMENT PRIMARY KEY, empresa_id INT NOT NULL, usuario_id INT NOT NULL, titulo VARCHAR(200) NOT NULL, mensagem TEXT NOT NULL, status ENUM('aberto','fechado') NOT NULL DEFAULT 'aberto', respondido TINYINT(1) NOT NULL DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (empresa_id) REFERENCES empresas(id) ON DELETE CASCADE, FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE ); CREATE TABLE suporte_respostas ( id INT AUTO_INCREMENT PRIMARY KEY, ticket_id INT NOT NULL, usuario_id INT NOT NULL, mensagem TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (ticket_id) REFERENCES suporte_tickets(id) ON DELETE CASCADE, FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE ); -- TOKENS DE RECUPERACAO DE SENHA CREATE TABLE password_reset_tokens ( id INT AUTO_INCREMENT PRIMARY KEY, usuario_id INT NOT NULL, token VARCHAR(100) NOT NULL UNIQUE, usado TINYINT(1) NOT NULL DEFAULT 0, expires_at DATETIME NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE ); -- ====== SEED DATA ====== INSERT INTO planos (nome, valor, recorencia, limite_profissionais, recursos, whatsapp_available) VALUES ('Gratis', 0, 'mensal', 2, '["dashboard","agendamentos","clientes"]', 0), ('Basico', 49.90, 'mensal', 5, '["dashboard","agendamentos","clientes","profissionais","servicos","relatorios"]', 0), ('Profissional', 99.90, 'mensal', 15, '["dashboard","agendamentos","clientes","profissionais","servicos","relatorios","campanhas","whatsapp","pagamentos"]', 1), ('Enterprise', 199.90, 'mensal', 999, '["dashboard","agendamentos","clientes","profissionais","servicos","relatorios","campanhas","whatsapp","pagamentos","api","multiusuario"]', 1); INSERT INTO empresas (plano_id, nome, slug, documento, telefone, email, aprovado) VALUES (3, 'Barbearia Prime', 'barbearia-prime', '00.000.000/0001-00', '(11) 99999-9999', 'contato@barbeariaprime.com', 1); INSERT INTO configuracoes (empresa_id) VALUES (1); INSERT INTO modelos_mensagem (empresa_id, tipo, titulo, mensagem_texto) VALUES (1, 'confirmacao', 'Confirmacao de Agendamento', 'Ola {{cliente_nome}}!\n\nSeu agendamento foi confirmado com sucesso na {{empresa_nome}}.\n\nConfira os detalhes:\nProfissional: {{profissional_nome}}\nServico: {{servico_nome}}\nData: {{data}}\nHorario: {{hora}}\nValor: {{valor}}\n\nLocal: {{endereco}}\nTelefone: {{telefone}}\n\nAgradecemos a preferencia!\nEquipe {{empresa_nome}}'), (1, 'cancelamento', 'Cancelamento de Agendamento', 'Ola {{cliente_nome}}!\n\nSeu agendamento foi cancelado conforme solicitado:\n\nProfissional: {{profissional_nome}}\nServico: {{servico_nome}}\nData: {{data}}\nHorario: {{hora}}\n\nSe desejar remarcar, entre em contato pelo telefone {{telefone}} ou acesse nosso site.\n\nAtenciosamente,\nEquipe {{empresa_nome}}'), (1, 'lembrete', 'Lembrete de Agendamento', 'Ola {{cliente_nome}}!\n\nPassando para lembrar do seu horario amanha:\n\nProfissional: {{profissional_nome}}\nServico: {{servico_nome}}\nData: {{data}}\nHorario: {{hora}}\n\nSe precisar cancelar ou remarcar, clique no link abaixo:\n{{link_cancelamento}}\n\nOu entre em contato: {{telefone}}\n\nAte logo!\nEquipe {{empresa_nome}}'), (1, 'confirmado', 'Cliente Confirmou o Agendamento', 'Ola {{profissional_nome}}!\n\nO cliente {{cliente_nome}} confirmou o agendamento:\n\nServico: {{servico_nome}}\nData: {{data}}\nHorario: {{hora}}\n\nO horario esta reservado.'), (1, 'personalizado', 'Mensagem Personalizada', 'Ola {{cliente_nome}}!\n\n{{mensagem_personalizada}}\n\nAtenciosamente,\n{{empresa_nome}}'); INSERT INTO grupos (empresa_id, nome, descricao, permissoes) VALUES (1, 'Administrador', 'Acesso total ao sistema', '["admin","dashboard","usuarios","grupos","profissionais","servicos","clientes","agendamentos","calendario","relatorios","configuracoes","campanhas","bloqueio_dias","financeiro"]'), (1, 'Profissional', 'Acesso a propria agenda e perfil', '["dashboard","meus_agendamentos","meu_calendario"]'); INSERT INTO usuarios (empresa_id, grupo_id, nome, email, telefone, senha, tipo, aprovado) VALUES (1, 1, 'Administrador', 'admin@agendamento.com', '(11) 99999-9999', '$2y$10$HNOmGJriHOetMCUvXv8pG.9YX.qOnyaPMc0Ji38He6u3sqd4.a5bW', 'admin', 1), (1, 1, 'Super Admin', 'super@agendamento.com', '(11) 99999-9999', '$2y$10$HNOmGJriHOetMCUvXv8pG.9YX.qOnyaPMc0Ji38He6u3sqd4.a5bW', 'super_admin', 1); INSERT INTO config_smtp (id) VALUES (1); INSERT INTO horarios_sistema (empresa_id, dia_semana, hora_inicio, hora_fim, intervalo) VALUES (1, 1, '08:00', '18:00', 60), (1, 2, '08:00', '18:00', 60), (1, 3, '08:00', '18:00', 60), (1, 4, '08:00', '18:00', 60), (1, 5, '08:00', '18:00', 60), (1, 6, '08:00', '13:00', 60); INSERT INTO servicos (empresa_id, nome, descricao, preco, duracao, comissao_tipo, comissao_valor) VALUES (1, 'Corte Masculino', 'Corte tradicional com tesoura e maquina', 45.00, 40, 'percentual', 50), (1, 'Barba', 'Aparacao e modelagem de barba', 30.00, 20, 'percentual', 50), (1, 'Corte + Barba', 'Combo corte masculino + barba', 65.00, 60, 'percentual', 50), (1, 'Hidratacao', 'Hidratacao capilar profunda', 50.00, 30, 'fixo', 20), (1, 'Sobrancelha', 'Design de sobrancelha', 20.00, 15, 'percentual', 40);
Simpan