-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Tempo de geração: 09/03/2026 às 12:44
-- Versão do servidor: 10.4.32-MariaDB
-- Versão do PHP: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Banco de dados: `recepcao`
--

-- --------------------------------------------------------

--
-- Estrutura para tabela `access_cards`
--

CREATE TABLE `access_cards` (
  `id` int(11) NOT NULL,
  `card_number` varchar(50) NOT NULL,
  `status` enum('livre','em_uso','perdido','danificado') DEFAULT 'livre',
  `type` enum('visitante','provisorio_funcionario') DEFAULT 'visitante',
  `current_visitor_id` int(11) DEFAULT NULL,
  `current_visita_id` int(11) DEFAULT NULL,
  `current_pessoa_id` int(11) DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `departamentos`
--

CREATE TABLE `departamentos` (
  `id` int(11) NOT NULL,
  `nome` varchar(100) NOT NULL,
  `empresa_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `departamentos`
--

INSERT INTO `departamentos` (`id`, `nome`, `empresa_id`) VALUES
(1, 'Gabinete 1', NULL),
(2, 'Gabinete da Presidencia', NULL),
(3, 'Juridico', NULL),
(4, 'Comunicação', NULL);

-- --------------------------------------------------------

--
-- Estrutura para tabela `devices`
--

CREATE TABLE `devices` (
  `id` int(11) NOT NULL,
  `nome` varchar(100) NOT NULL,
  `tipo` enum('catraca','porta','cancela') NOT NULL,
  `ip_address` varchar(50) DEFAULT NULL,
  `status` enum('online','offline','manutencao') DEFAULT 'online',
  `localizacao` varchar(100) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `devices`
--

INSERT INTO `devices` (`id`, `nome`, `tipo`, `ip_address`, `status`, `localizacao`, `created_at`) VALUES
(1, 'Catraca Recepção', 'catraca', '192.168.1.50', 'online', 'Portaria Principal', '2026-02-24 18:34:00');

-- --------------------------------------------------------

--
-- Estrutura para tabela `empresas`
--

CREATE TABLE `empresas` (
  `id` int(11) NOT NULL,
  `nome` varchar(100) NOT NULL,
  `cnpj` varchar(20) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `eventos`
--

CREATE TABLE `eventos` (
  `id` int(11) NOT NULL,
  `nome` varchar(100) NOT NULL,
  `local` varchar(100) NOT NULL,
  `data_hora` datetime NOT NULL,
  `descricao` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `evento_participantes`
--

CREATE TABLE `evento_participantes` (
  `id` int(11) NOT NULL,
  `evento_id` int(11) NOT NULL,
  `nome` varchar(100) NOT NULL,
  `documento` varchar(50) DEFAULT NULL,
  `telefone` varchar(50) DEFAULT NULL,
  `status_presenca` enum('pendente','presente','cancelado') DEFAULT 'pendente',
  `check_in_time` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `gabinetes`
--

CREATE TABLE `gabinetes` (
  `id` int(11) NOT NULL,
  `nome` varchar(100) NOT NULL,
  `andar` varchar(50) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `gabinetes`
--

INSERT INTO `gabinetes` (`id`, `nome`, `andar`, `created_at`) VALUES
(1, 'Gabinete da Presidência', '2º Andar', '2025-11-28 13:00:36'),
(2, 'Gabinete Ver. João da Silva', '1º Andar', '2025-11-28 13:00:36'),
(3, 'Secretaria Administrativa', 'Térreo', '2025-11-28 13:00:36');

-- --------------------------------------------------------

--
-- Estrutura para tabela `perfis_acesso`
--

CREATE TABLE `perfis_acesso` (
  `id` int(11) NOT NULL,
  `nome` varchar(50) NOT NULL,
  `horarios_permitidos` text DEFAULT NULL,
  `descricao` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `perfis_acesso`
--

INSERT INTO `perfis_acesso` (`id`, `nome`, `horarios_permitidos`, `descricao`) VALUES
(1, 'Assessores', NULL, 'Assessores de Gabinete');

-- --------------------------------------------------------

--
-- Estrutura para tabela `pessoas`
--

CREATE TABLE `pessoas` (
  `id` int(11) NOT NULL,
  `tipo` enum('VISITANTE','MUNICIPE') NOT NULL DEFAULT 'VISITANTE',
  `nome` varchar(255) NOT NULL,
  `documento_numero` varchar(50) DEFAULT NULL,
  `documento_orgao` varchar(50) DEFAULT NULL,
  `telefone` varchar(30) DEFAULT NULL,
  `email` varchar(120) DEFAULT NULL,
  `data_nascimento` date DEFAULT NULL,
  `endereco` varchar(255) DEFAULT NULL,
  `endereco_comercial` varchar(255) DEFAULT NULL,
  `grau_escolaridade` varchar(80) DEFAULT NULL,
  `atividade_profissional` varchar(120) DEFAULT NULL,
  `dependentes_qtd` int(11) DEFAULT NULL,
  `foto_url` varchar(255) DEFAULT NULL,
  `doc_url` varchar(255) DEFAULT NULL,
  `biometria_template` longtext DEFAULT NULL,
  `biometria_dedo` int(11) DEFAULT 0,
  `observacoes` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `pessoas`
--

INSERT INTO `pessoas` (`id`, `tipo`, `nome`, `documento_numero`, `documento_orgao`, `telefone`, `email`, `data_nascimento`, `endereco`, `endereco_comercial`, `grau_escolaridade`, `atividade_profissional`, `dependentes_qtd`, `foto_url`, `doc_url`, `biometria_template`, `biometria_dedo`, `observacoes`, `created_at`, `updated_at`) VALUES
(1, 'VISITANTE', 'Miguel Fernando', '41189645890', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, '2025-11-28 13:18:55', NULL),
(2, 'VISITANTE', 'Felipe Fernando Gonçalves', '486504311', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, '2025-11-28 12:48:37', NULL);

-- --------------------------------------------------------

--
-- Estrutura para tabela `profile_device_permissions`
--

CREATE TABLE `profile_device_permissions` (
  `perfil_acesso_id` int(11) NOT NULL,
  `device_id` int(11) NOT NULL,
  `horario_inicio` time NOT NULL DEFAULT '00:00:00',
  `horario_fim` time NOT NULL DEFAULT '23:59:59'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `profile_device_permissions`
--

INSERT INTO `profile_device_permissions` (`perfil_acesso_id`, `device_id`, `horario_inicio`, `horario_fim`) VALUES
(1, 1, '08:00:00', '19:00:00');

-- --------------------------------------------------------

--
-- Estrutura para tabela `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `matricula` varchar(50) DEFAULT NULL,
  `password` varchar(255) NOT NULL,
  `role` enum('admin','receptionist') NOT NULL,
  `empresa_id` int(11) DEFAULT NULL,
  `departamento_id` int(11) DEFAULT NULL,
  `perfil_acesso_id` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `foto_url` varchar(255) DEFAULT NULL,
  `doc_frente_url` varchar(255) DEFAULT NULL,
  `doc_verso_url` varchar(255) DEFAULT NULL,
  `data_ativacao` datetime DEFAULT NULL,
  `data_expiracao` datetime DEFAULT NULL,
  `campo_personalizado_1` varchar(100) DEFAULT NULL,
  `campo_personalizado_2` varchar(100) DEFAULT NULL,
  `campo_personalizado_3` varchar(100) DEFAULT NULL,
  `obs_extra` text DEFAULT NULL,
  `biometria_template` longtext DEFAULT NULL,
  `biometria_dedo` int(11) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `users`
--

INSERT INTO `users` (`id`, `username`, `matricula`, `password`, `role`, `empresa_id`, `departamento_id`, `perfil_acesso_id`, `created_at`, `foto_url`, `doc_frente_url`, `doc_verso_url`, `data_ativacao`, `data_expiracao`, `campo_personalizado_1`, `campo_personalizado_2`, `campo_personalizado_3`, `obs_extra`, `biometria_template`, `biometria_dedo`) VALUES
(1, 'admin', NULL, '$2y$10$gotdcKVCsbwSoKrwyIFtxeHjsJPHNv6OFT15XqxBrzZyr3afwn3/a', 'admin', NULL, NULL, NULL, '2025-11-28 11:52:34', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0),
(2, 'recepcionista', NULL, '$2y$10$gotdcKVCsbwSoKrwyIFtxeHjsJPHNv6OFT15XqxBrzZyr3afwn3/a', 'receptionist', NULL, NULL, NULL, '2025-11-28 11:52:34', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);

-- --------------------------------------------------------

--
-- Estrutura para tabela `user_access_logs`
--

CREATE TABLE `user_access_logs` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `access_time` timestamp NOT NULL DEFAULT current_timestamp(),
  `ip_address` varchar(45) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `user_access_logs`
--

INSERT INTO `user_access_logs` (`id`, `user_id`, `access_time`, `ip_address`) VALUES
(1, 2, '2025-12-30 17:17:03', '177.8.174.77'),
(2, 1, '2025-12-30 17:17:28', '177.8.174.77'),
(3, 2, '2025-12-30 17:33:06', '177.135.150.117'),
(4, 2, '2025-12-30 18:02:32', '177.135.150.117'),
(5, 1, '2025-12-30 18:02:57', '177.135.150.117'),
(6, 1, '2025-12-30 18:41:32', '177.135.150.117'),
(7, 2, '2025-12-30 18:50:47', '177.8.174.77'),
(8, 1, '2026-01-05 19:44:00', '::1'),
(9, 2, '2026-01-05 19:45:57', '::1'),
(10, 1, '2026-02-24 17:06:36', '::1'),
(11, 2, '2026-02-24 17:07:12', '::1'),
(12, 1, '2026-02-24 17:20:09', '::1'),
(13, 1, '2026-02-24 17:44:29', '::1'),
(14, 1, '2026-02-24 17:54:24', '::1'),
(15, 1, '2026-02-24 18:00:19', '::1'),
(16, 2, '2026-02-24 18:01:13', '::1'),
(17, 1, '2026-02-24 18:31:47', '::1'),
(18, 2, '2026-02-24 18:47:53', '::1'),
(19, 1, '2026-02-24 18:49:39', '::1'),
(20, 1, '2026-02-24 19:24:30', '::1'),
(21, 2, '2026-02-24 19:28:26', '::1'),
(22, 1, '2026-02-24 19:38:26', '::1'),
(23, 2, '2026-02-24 19:43:19', '::1'),
(24, 1, '2026-02-24 20:02:08', '::1'),
(25, 2, '2026-02-24 20:32:33', '::1'),
(26, 2, '2026-03-09 11:34:54', '::1'),
(27, 1, '2026-03-09 11:40:17', '::1');

-- --------------------------------------------------------

--
-- Estrutura para tabela `visitas`
--

CREATE TABLE `visitas` (
  `id` int(11) NOT NULL,
  `pessoa_id` int(11) NOT NULL,
  `gabinete_id` int(11) DEFAULT NULL,
  `motivo` varchar(255) DEFAULT NULL,
  `check_in` timestamp NOT NULL DEFAULT current_timestamp(),
  `check_out` timestamp NULL DEFAULT NULL,
  `registrado_por` int(11) NOT NULL,
  `veiculo_modelo` varchar(100) DEFAULT NULL,
  `veiculo_placa` varchar(20) DEFAULT NULL,
  `materiais` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `destinos_multiplos` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `visitas`
--

INSERT INTO `visitas` (`id`, `pessoa_id`, `gabinete_id`, `motivo`, `check_in`, `check_out`, `registrado_por`, `veiculo_modelo`, `veiculo_placa`, `materiais`, `created_at`, `destinos_multiplos`) VALUES
(1, 1, 1, NULL, '2025-11-28 13:18:55', '2025-12-30 17:17:14', 2, NULL, NULL, NULL, '2026-01-05 19:39:21', NULL),
(2, 2, NULL, NULL, '2025-11-28 12:48:37', '2025-11-28 13:19:04', 2, NULL, NULL, NULL, '2026-01-05 19:39:21', NULL);

-- --------------------------------------------------------

--
-- Estrutura para tabela `visitors`
--

CREATE TABLE `visitors` (
  `id` int(11) NOT NULL,
  `full_name` varchar(255) NOT NULL,
  `document_id` varchar(50) DEFAULT NULL,
  `check_in` timestamp NOT NULL DEFAULT current_timestamp(),
  `check_out` timestamp NULL DEFAULT NULL,
  `destination` varchar(255) NOT NULL,
  `registered_by` int(11) NOT NULL,
  `veiculo_modelo` varchar(100) DEFAULT NULL,
  `veiculo_placa` varchar(20) DEFAULT NULL,
  `materiais` text DEFAULT NULL,
  `foto_url` varchar(255) DEFAULT NULL,
  `biometria_template` longtext DEFAULT NULL,
  `biometria_dedo` int(11) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Despejando dados para a tabela `visitors`
--

INSERT INTO `visitors` (`id`, `full_name`, `document_id`, `check_in`, `check_out`, `destination`, `registered_by`, `veiculo_modelo`, `veiculo_placa`, `materiais`, `foto_url`, `biometria_template`, `biometria_dedo`) VALUES
(1, 'Felipe Fernando Gonçalves', '486504311', '2025-11-28 12:48:37', '2025-11-28 13:19:04', 'Gabinete 01', 2, NULL, NULL, NULL, NULL, NULL, 0),
(2, 'Miguel Fernando', '41189645890', '2025-11-28 13:18:55', '2025-12-30 17:17:14', 'Gabinete da Presidência', 2, NULL, NULL, NULL, NULL, NULL, 0);

--
-- Índices para tabelas despejadas
--

--
-- Índices de tabela `access_cards`
--
ALTER TABLE `access_cards`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `card_number` (`card_number`),
  ADD KEY `current_visitor_id` (`current_visitor_id`);

--
-- Índices de tabela `departamentos`
--
ALTER TABLE `departamentos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `empresa_id` (`empresa_id`);

--
-- Índices de tabela `devices`
--
ALTER TABLE `devices`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `empresas`
--
ALTER TABLE `empresas`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `eventos`
--
ALTER TABLE `eventos`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `evento_participantes`
--
ALTER TABLE `evento_participantes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `evento_id` (`evento_id`);

--
-- Índices de tabela `gabinetes`
--
ALTER TABLE `gabinetes`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `perfis_acesso`
--
ALTER TABLE `perfis_acesso`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `pessoas`
--
ALTER TABLE `pessoas`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_documento` (`documento_numero`);

--
-- Índices de tabela `profile_device_permissions`
--
ALTER TABLE `profile_device_permissions`
  ADD PRIMARY KEY (`perfil_acesso_id`,`device_id`),
  ADD KEY `device_id` (`device_id`);

--
-- Índices de tabela `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`),
  ADD KEY `fk_user_empresa` (`empresa_id`),
  ADD KEY `fk_user_depto` (`departamento_id`),
  ADD KEY `fk_user_perfil` (`perfil_acesso_id`);

--
-- Índices de tabela `user_access_logs`
--
ALTER TABLE `user_access_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Índices de tabela `visitas`
--
ALTER TABLE `visitas`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_visitas_periodo` (`check_in`),
  ADD KEY `idx_visitas_pessoa` (`pessoa_id`),
  ADD KEY `idx_visitas_gabinete` (`gabinete_id`),
  ADD KEY `fk_visitas_user` (`registrado_por`);

--
-- Índices de tabela `visitors`
--
ALTER TABLE `visitors`
  ADD PRIMARY KEY (`id`),
  ADD KEY `registered_by` (`registered_by`);

--
-- AUTO_INCREMENT para tabelas despejadas
--

--
-- AUTO_INCREMENT de tabela `access_cards`
--
ALTER TABLE `access_cards`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `departamentos`
--
ALTER TABLE `departamentos`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT de tabela `devices`
--
ALTER TABLE `devices`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `empresas`
--
ALTER TABLE `empresas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `eventos`
--
ALTER TABLE `eventos`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `evento_participantes`
--
ALTER TABLE `evento_participantes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `gabinetes`
--
ALTER TABLE `gabinetes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT de tabela `perfis_acesso`
--
ALTER TABLE `perfis_acesso`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `pessoas`
--
ALTER TABLE `pessoas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `user_access_logs`
--
ALTER TABLE `user_access_logs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28;

--
-- AUTO_INCREMENT de tabela `visitas`
--
ALTER TABLE `visitas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `visitors`
--
ALTER TABLE `visitors`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- Restrições para tabelas despejadas
--

--
-- Restrições para tabelas `access_cards`
--
ALTER TABLE `access_cards`
  ADD CONSTRAINT `access_cards_ibfk_1` FOREIGN KEY (`current_visitor_id`) REFERENCES `visitors` (`id`) ON DELETE SET NULL;

--
-- Restrições para tabelas `departamentos`
--
ALTER TABLE `departamentos`
  ADD CONSTRAINT `departamentos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresas` (`id`) ON DELETE SET NULL;

--
-- Restrições para tabelas `evento_participantes`
--
ALTER TABLE `evento_participantes`
  ADD CONSTRAINT `evento_participantes_ibfk_1` FOREIGN KEY (`evento_id`) REFERENCES `eventos` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `profile_device_permissions`
--
ALTER TABLE `profile_device_permissions`
  ADD CONSTRAINT `profile_device_permissions_ibfk_1` FOREIGN KEY (`perfil_acesso_id`) REFERENCES `perfis_acesso` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `profile_device_permissions_ibfk_2` FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `fk_user_depto` FOREIGN KEY (`departamento_id`) REFERENCES `departamentos` (`id`),
  ADD CONSTRAINT `fk_user_empresa` FOREIGN KEY (`empresa_id`) REFERENCES `empresas` (`id`),
  ADD CONSTRAINT `fk_user_perfil` FOREIGN KEY (`perfil_acesso_id`) REFERENCES `perfis_acesso` (`id`);

--
-- Restrições para tabelas `user_access_logs`
--
ALTER TABLE `user_access_logs`
  ADD CONSTRAINT `user_access_logs_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `visitas`
--
ALTER TABLE `visitas`
  ADD CONSTRAINT `fk_visitas_gabinete` FOREIGN KEY (`gabinete_id`) REFERENCES `gabinetes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_visitas_pessoa` FOREIGN KEY (`pessoa_id`) REFERENCES `pessoas` (`id`) ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_visitas_user` FOREIGN KEY (`registrado_por`) REFERENCES `users` (`id`) ON UPDATE CASCADE;

--
-- Restrições para tabelas `visitors`
--
ALTER TABLE `visitors`
  ADD CONSTRAINT `visitors_ibfk_1` FOREIGN KEY (`registered_by`) REFERENCES `users` (`id`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
