-- https://www.phpmyadmin.net/
--
-- Tempo de geração: 24/12/2025 às 22:39
-- Versão do servidor: 10.4.32-MariaDB
-- Versão do PHP: 8.2.12

START TRANSACTION;



--
-- Banco de dados: `ordem_de_servico`
--

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

--
-- Estrutura para tabela `companies`
--

CREATE TABLE `companies` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `phone` varchar(255) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `companies`
--

INSERT INTO `companies` (`id`, `name`, `email`, `phone`, `address`, `created_at`, `updated_at`) VALUES
(1, 'Empresa', 'empresa@email.com', '000000', 'endereco', '2025-12-24 20:45:17', NULL),
(2, 'Nova', 'nova@email.com', NULL, NULL, '2025-12-25 00:35:40', '2025-12-25 00:35:40');

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

--
-- Estrutura para tabela `failed_jobs`
--

CREATE TABLE `failed_jobs` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `uuid` varchar(255) NOT NULL,
  `connection` text NOT NULL,
  `queue` text NOT NULL,
  `payload` longtext NOT NULL,
  `exception` longtext NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--

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

--
-- Estrutura para tabela `manager_companies`
--

CREATE TABLE `manager_companies` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `company_id` bigint(20) UNSIGNED NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Estrutura para tabela `migrations`
--

CREATE TABLE `migrations` (
  `id` int(10) UNSIGNED NOT NULL,
  `migration` varchar(255) NOT NULL,
  `batch` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `migrations`
--

INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
(1, '2014_10_12_000000_create_users_table', 1),
(2, '2014_10_12_100000_create_password_reset_tokens_table', 1),
(3, '2019_08_19_000000_create_failed_jobs_table', 1),
(4, '2019_12_14_000001_create_personal_access_tokens_table', 1),
(5, '2025_12_24_184500_create_companies_table', 1),
(6, '2025_12_24_184505_add_company_to_users_table', 1),
(7, '2025_12_24_184510_create_service_orders_table', 1),
(8, '2025_12_24_184520_create_order_photos_table', 1),
(9, '2025_12_24_201326_create_sectors_table', 1),
(10, '2025_12_24_201343_add_fields_to_service_orders_table', 1),
(11, '2026_01_03_000000_create_manager_companies_table', 2);

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

--
-- Estrutura para tabela `order_photos`
--

CREATE TABLE `order_photos` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `service_order_id` bigint(20) UNSIGNED NOT NULL,
  `photo_url` varchar(255) DEFAULT NULL,
  `photo_key` varchar(255) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `order_photos`
--

INSERT INTO `order_photos` (`id`, `service_order_id`, `photo_url`, `photo_key`, `created_at`, `updated_at`) VALUES
(4, 6, 'service-orders/xKdYfTvrCWSnqCFyQFMIrdlQPHJKSvXzIBU5Xdhg.png', NULL, '2025-12-25 00:33:33', '2025-12-25 00:33:33');

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

--
-- Estrutura para tabela `sectors`
--

CREATE TABLE `sectors` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `company_id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `sectors`
--

INSERT INTO `sectors` (`id`, `company_id`, `name`, `description`, `created_at`, `updated_at`) VALUES
(1, 1, 'Setor1', NULL, '2025-12-24 23:48:41', '2025-12-24 23:48:41'),
(2, 1, 'Setor2', NULL, '2025-12-24 23:48:50', '2025-12-24 23:48:50'),
(3, 1, 'Setor novo', NULL, '2025-12-25 00:36:00', '2025-12-25 00:36:13');

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

--
-- Estrutura para tabela `service_orders`
--

CREATE TABLE `service_orders` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `company_id` bigint(20) UNSIGNED NOT NULL,
  `sector_id` bigint(20) UNSIGNED DEFAULT NULL,
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `sector` varchar(255) DEFAULT NULL,
  `priority` enum('low','normal','urgent') NOT NULL DEFAULT 'normal',
  `description` text DEFAULT NULL,
  `requester_name` varchar(255) DEFAULT NULL,
  `maintenance_type` enum('geral','refrigeracao','eletrica','hidraulica','mecanica') NOT NULL DEFAULT 'geral',
  `service_type` enum('corretiva','planejada','preventiva') NOT NULL DEFAULT 'corretiva',
  `status` enum('pending','in_progress','completed','rescheduled') NOT NULL DEFAULT 'pending',
  `scheduled_date` date DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `service_orders`
--

INSERT INTO `service_orders` (`id`, `company_id`, `sector_id`, `user_id`, `sector`, `priority`, `description`, `requester_name`, `maintenance_type`, `service_type`, `status`, `scheduled_date`, `completed_at`, `created_at`, `updated_at`) VALUES
(1, 1, 1, 3, NULL, 'low', 'Descrição 12345', 'Fulano', 'geral', 'corretiva', 'pending', NULL, NULL, '2025-12-24 23:59:08', '2025-12-24 23:59:08'),
(2, 1, 1, 2, NULL, 'low', 'Descrição 132456', 'Fulano', 'eletrica', 'corretiva', 'pending', NULL, NULL, '2025-12-25 00:01:32', '2025-12-25 00:01:32'),
(3, 1, 1, 2, NULL, 'low', '12121 321321321321321', 'Fulano', 'geral', 'corretiva', 'pending', NULL, NULL, '2025-12-25 00:09:12', '2025-12-25 00:09:12'),
(4, 1, 1, 2, NULL, 'low', 'Descriação 12345', 'Fulano', 'geral', 'planejada', 'pending', NULL, NULL, '2025-12-25 00:13:32', '2025-12-25 00:13:32'),
(5, 1, 1, 2, NULL, 'low', 'Descrição 123455564', 'Fulano', 'geral', 'corretiva', 'in_progress', NULL, NULL, '2025-12-25 00:19:40', '2025-12-25 00:20:27'),
(6, 1, 2, 2, NULL, 'low', 'Descrição 234564', 'Fulano', 'refrigeracao', 'corretiva', 'in_progress', NULL, NULL, '2025-12-25 00:32:43', '2025-12-25 00:33:19');

--
-- Índices para tabelas despejadas
--

--
-- Índices de tabela `companies`
--
ALTER TABLE `companies`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `companies_name_unique` (`name`);

--
-- Índices de tabela `failed_jobs`
--
ALTER TABLE `failed_jobs`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`);

--

--
-- Índices de tabela `manager_companies`
--
ALTER TABLE `manager_companies`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `manager_companies_user_id_company_id_unique` (`user_id`,`company_id`),
  ADD KEY `manager_companies_company_id_foreign` (`company_id`);

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

--
-- Índices de tabela `order_photos`
--
ALTER TABLE `order_photos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_photos_service_order_id_foreign` (`service_order_id`);

--
-- Índices de tabela `sectors`
--
ALTER TABLE `sectors`
  ADD PRIMARY KEY (`id`),
  ADD KEY `sectors_company_id_foreign` (`company_id`);

--
-- Índices de tabela `service_orders`
--
ALTER TABLE `service_orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `service_orders_company_id_foreign` (`company_id`),
  ADD KEY `service_orders_user_id_foreign` (`user_id`),
  ADD KEY `service_orders_sector_id_foreign` (`sector_id`);

--
-- AUTO_INCREMENT para tabelas despejadas
--

--
-- AUTO_INCREMENT de tabela `companies`
--
ALTER TABLE `companies`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `failed_jobs`
--
ALTER TABLE `failed_jobs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--

--
-- AUTO_INCREMENT de tabela `manager_companies`
--
ALTER TABLE `manager_companies`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

-- AUTO_INCREMENT de tabela `migrations`
--
ALTER TABLE `migrations`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;

--
-- AUTO_INCREMENT de tabela `order_photos`
--
ALTER TABLE `order_photos`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT de tabela `sectors`
--
ALTER TABLE `sectors`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT de tabela `service_orders`
--
ALTER TABLE `service_orders`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

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

--

--
-- Restrições para tabelas `manager_companies`
--
ALTER TABLE `manager_companies`
  ADD CONSTRAINT `manager_companies_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `manager_companies_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

-- Restrições para tabelas `order_photos`
--
ALTER TABLE `order_photos`
  ADD CONSTRAINT `order_photos_service_order_id_foreign` FOREIGN KEY (`service_order_id`) REFERENCES `service_orders` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `sectors`
--
ALTER TABLE `sectors`
  ADD CONSTRAINT `sectors_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `service_orders`
--
ALTER TABLE `service_orders`
  ADD CONSTRAINT `service_orders_company_id_foreign` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `service_orders_sector_id_foreign` FOREIGN KEY (`sector_id`) REFERENCES `sectors` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `service_orders_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
COMMIT;

