Files
6e8e640738 feat: initial commit - Table Expiration Watcher
- Monitor de tabelas de planos de saúde prestes a vencer/vencidas
- Stack: Bun + Hono + SQLite + Zod + date-fns
- Alertas via Telegram e WhatsApp (AstraCalls MCP)
- UI de configuração estilo Apple/Planium em /configs
- Scheduler periódico com intervalo configurável
- Testes unitários e de integração (30 testes passando)

Co-Authored-By: Coder <coder@agent.local>
Co-Authored-By: Review <review@agent.local>
Co-Authored-By: Testing <testing@agent.local>
2026-11-25 09:43:00 -03:00

108 lines
5.1 KiB
SQL

-- Banco de dados: teamiron
CREATE TABLE IF NOT EXISTS `agendamentos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cliente_id` int(11) NOT NULL,
`data_agendamento` date NOT NULL,
`horario` time NOT NULL,
`servico_id` int(11) NOT NULL,
`profissional_id` int(11) NOT NULL,
`status` enum('pendente','confirmado','cancelado','finalizado') NOT NULL DEFAULT 'pendente',
`observacoes` text DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `idx_cliente_id` (`cliente_id`),
KEY `idx_data_agendamento` (`data_agendamento`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `clientes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(255) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`telefone` varchar(20) DEFAULT NULL,
`cpf` varchar(14) DEFAULT NULL,
`data_nascimento` date DEFAULT NULL,
`endereco` text DEFAULT NULL,
`observacoes` text DEFAULT NULL,
`ativo` tinyint(1) NOT NULL DEFAULT 1,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `uk_email` (`email`),
UNIQUE KEY `uk_cpf` (`cpf`),
KEY `idx_nome` (`nome`),
KEY `idx_ativo` (`ativo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `profissionais` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(255) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`telefone` varchar(20) DEFAULT NULL,
`especialidade` varchar(255) DEFAULT NULL,
`ativo` tinyint(1) NOT NULL DEFAULT 1,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `idx_nome` (`nome`),
KEY `idx_ativo` (`ativo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `servicos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(255) NOT NULL,
`descricao` text DEFAULT NULL,
`duracao_minutos` int(11) NOT NULL DEFAULT 30,
`preco` decimal(10,2) NOT NULL DEFAULT 0.00,
`ativo` tinyint(1) NOT NULL DEFAULT 1,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `idx_nome` (`nome`),
KEY `idx_ativo` (`ativo`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `tabelas_expiradas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cliente_id` int(11) NOT NULL,
`data_expiracao` date NOT NULL,
`tabela_referencia` varchar(100) NOT NULL,
`id_referencia` int(11) NOT NULL,
`notificado` tinyint(1) NOT NULL DEFAULT 0,
`data_notificacao` datetime DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
KEY `idx_cliente_id` (`cliente_id`),
KEY `idx_data_expiracao` (`data_expiracao`),
KEY `idx_notificado` (`notificado`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Inserir dados de exemplo para testes
INSERT IGNORE INTO `clientes` (`nome`, `email`, `telefone`, `cpf`, `data_nascimento`, `endereco`, `observacoes`) VALUES
('João Silva', 'joao.silva@email.com', '(11) 99999-1111', '123.456.789-00', '1990-05-15', 'Rua A, 123 - São Paulo/SP', 'Cliente VIP'),
('Maria Santos', 'maria.santos@email.com', '(11) 99999-2222', '987.654.321-00', '1985-08-22', 'Rua B, 456 - São Paulo/SP', ''),
('Pedro Oliveira', 'pedro.oliveira@email.com', '(11) 99999-3333', '456.789.123-00', '1992-11-30', 'Rua C, 789 - São Paulo/SP', 'Alérgico a látex');
INSERT IGNORE INTO `profissionais` (`nome`, `email`, `telefone`, `especialidade`) VALUES
('Dr. Carlos Mendes', 'carlos.mendes@clinic.com', '(11) 98888-1111', 'Ortopedia'),
('Dra. Ana Paula', 'ana.paula@clinic.com', '(11) 98888-2222', 'Fisioterapia'),
('Dr. Roberto Lima', 'roberto.lima@clinic.com', '(11) 98888-3333', 'Cardiologia');
INSERT IGNORE INTO `servicos` (`nome`, `descricao`, `duracao_minutos`, `preco`) VALUES
('Consulta Ortopédica', 'Consulta com especialista em ortopedia', 30, 150.00),
('Sessão de Fisioterapia', 'Sessão de fisioterapia convencional', 60, 120.00),
('Check-up Cardíaco', 'Exames e consulta cardiológica completa', 90, 300.00);
INSERT IGNORE INTO `agendamentos` (`cliente_id`, `data_agendamento`, `horario`, `servico_id`, `profissional_id`, `status`) VALUES
(1, '2025-01-15', '09:00:00', 1, 1, 'confirmado'),
(2, '2025-01-16', '14:00:00', 2, 2, 'pendente'),
(3, '2025-01-17', '10:30:00', 3, 3, 'confirmado');
-- Inserir algumas tabelas expiradas para teste
INSERT IGNORE INTO `tabelas_expiradas` (`cliente_id`, `data_expiracao`, `tabela_referencia`, `id_referencia`, `notificado`) VALUES
(1, '2024-12-01', 'agendamentos', 1, 0),
(2, '2024-11-15', 'agendamentos', 2, 1),
(3, '2025-01-10', 'servicos', 1, 0);