CREATE TABLE `ticket_status_tracking` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `ticket_id` int(11) NOT NULL,
  `status_id` int(11) NOT NULL,
  `started_at` timestamp NULL DEFAULT current_timestamp(),
  `ended_at` timestamp NULL DEFAULT NULL,
  `duration_minutes` int(11) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Estructura de tabla para la tabla `urgencies`
--

CREATE TABLE `urgencies` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(50) NOT NULL,
  `description` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Volcado de datos para la tabla `urgencies`
--

INSERT INTO `urgencies` (`id`, `name`, `description`, `created_at`) VALUES
(1, 'urgente', '', '2025-04-22 16:38:57'),
(2, 'no urgente', '', '2025-04-22 16:39:03');

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

--
-- Estructura de tabla para la tabla `user_history`
--

CREATE TABLE `user_history` (
  `id` int(11) NOT NULL,
  `action` varchar(50) NOT NULL,
  `target_user` varchar(100) NOT NULL,
  `target_user_id` int(11) DEFAULT NULL,
  `nombre_usuario` varchar(100) NOT NULL,
  `id_usuario` int(11) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `old_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`old_values`)),
  `new_values` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`new_values`)),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Volcado de datos para la tabla `user_history`
--

INSERT INTO `user_history` (`id`, `action`, `target_user`, `target_user_id`, `nombre_usuario`, `id_usuario`, `description`, `old_values`, `new_values`, `created_at`) VALUES
(1, 'updated', 'oscar', 48, 'Sistema', NULL, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 18:36:19'),
(2, 'updated', 'oscar', 48, 'Sistema', NULL, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 18:36:53'),
(3, 'updated', 'oscar', 48, 'prueba', 55, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 18:46:36'),
(4, 'updated', 'oscar', 48, 'prueba', 55, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 18:46:42'),
(5, 'updated', 'oscar', 48, 'prueba', 55, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '2025-09-25 19:13:41'),
(6, 'updated', 'oscar', 48, 'prueba', 55, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 19:13:45'),
(7, 'updated', 'oscar', 48, 'prueba', 55, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 19:13:50'),
(8, 'updated', 'oscar', 48, 'admin', 1, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"administrador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-25 19:53:30'),
(9, 'updated', 'oscar', 48, 'admin', 1, 'Usuario actualizado sin cambiar contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"administrador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-26 19:59:08'),
(10, 'updated', 'oscar', 48, 'admin', 1, 'Usuario actualizado con nueva contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-09-30 22:31:32'),
(11, 'updated', 'prueba', 55, 'admin', 1, 'Usuario actualizado con nueva contraseña', '{\"email\":\"prueba@prueba.com\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '{\"email\":\"prueba@prueba.com\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '2025-09-30 22:31:42'),
(12, 'updated', 'prueba', 55, 'admin', 1, 'Usuario actualizado con nueva contraseña', '{\"email\":\"prueba@prueba.com\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '{\"email\":\"prueba@prueba.com\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '2025-10-02 18:51:57'),
(13, 'deleted', 'prueba', 55, 'admin', 1, 'Usuario eliminado del sistema', NULL, NULL, '2025-10-03 18:23:21'),
(14, 'created', 'prueba', 57, 'admin', 1, 'Nuevo usuario creado', NULL, '{\"nombre_usuario\":\"prueba\",\"email\":\"prueba@prueba.com\",\"rol\":\"administrador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-10-03 18:23:38'),
(15, 'updated', 'oscar', 48, 'admin', 1, 'Usuario actualizado con nueva contraseña', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"oantonio@securiti.com.mx\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '2025-10-06 22:42:47'),
(16, 'created', 'test', 58, 'admin', 1, 'Nuevo usuario creado', NULL, '{\"nombre_usuario\":\"test\",\"email\":\"test@gmail.com\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '2025-10-13 15:29:31'),
(17, 'deleted', 'test', 58, 'admin', 1, 'Usuario eliminado del sistema', NULL, NULL, '2025-10-13 18:08:54'),
(18, 'created', 'test-supervisor', 59, 'admin', 1, 'Nuevo usuario creado', NULL, '{\"nombre_usuario\":\"test-supervisor\",\"email\":\"test-supervisor@gmail.com\",\"rol\":\"supervisor\",\"can_view_inventory_history\":1,\"can_view_ticket_history\":1,\"can_manage_users\":1}', '2025-10-13 18:09:32'),
(19, 'created', 'test-administrador', 60, 'admin', 1, 'Nuevo usuario creado', NULL, '{\"nombre_usuario\":\"test-administrador\",\"email\":\"test-administrador@gmail.com\",\"rol\":\"administrador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-10-13 18:09:58'),
(20, 'created', 'test-visualizador', 61, 'admin', 1, 'Nuevo usuario creado', NULL, '{\"nombre_usuario\":\"test-visualizador\",\"email\":\"test-visualizador@gmail.com\",\"rol\":\"visualizador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-10-13 18:10:50'),
(21, 'deleted', 'test-administrador', 60, 'admin', 1, 'Usuario eliminado del sistema', NULL, NULL, '2025-10-14 21:51:10'),
(22, 'deleted', 'test-supervisor', 59, 'admin', 1, 'Usuario eliminado del sistema', NULL, NULL, '2025-10-14 21:51:13'),
(23, 'deleted', 'test-visualizador', 61, 'admin', 1, 'Usuario eliminado del sistema', NULL, NULL, '2025-10-14 21:51:15'),
(24, 'updated', 'prueba', 57, 'admin', 1, 'Usuario actualizado con nueva contraseña', '{\"email\":\"prueba@prueba.com\",\"rol\":\"administrador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '{\"email\":\"prueba@prueba.com\",\"rol\":\"administrador\",\"can_view_inventory_history\":0,\"can_view_ticket_history\":0,\"can_manage_users\":0}', '2025-10-16 19:26:39');

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

--
-- Estructura de tabla para la tabla `whatsapp_conversations`
--

CREATE TABLE `whatsapp_conversations` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `wa_message_id` varchar(255) NOT NULL,
  `phone` varchar(20) NOT NULL,
  `message` text DEFAULT NULL,
  `file_name` varchar(255) DEFAULT NULL,
  `file_data` longblob DEFAULT NULL,
  `file_mime` varchar(100) DEFAULT NULL,
  `timestamp` timestamp NULL DEFAULT current_timestamp(),
  `direction` enum('in','out') NOT NULL DEFAULT 'in',
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Volcado de datos para la tabla `whatsapp_conversations`
--

INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(10, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDlCRDRBMTFGMTM5MjBDMjBGQUNDMTQwMjg3N0RCREI3AA==', '5215650299150', 'Prueba de envio', NULL, NULL, NULL, '2025-07-17 22:49:06', 'in', '2025-07-17 18:49:07');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(11, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDZENzYyNkE2ODQ2Q0UyRDgxRTFBRTIyQTJCNDIwOTAxAA==', '5215650299150', '[Imagen]', '715058024699154.jpg', 0x[BLOB], 'image/jpeg', '2025-07-17 22:49:12', 'in', '2025-07-17 18:49:15');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(12, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEjcxNEYwOTYxRDYxNkJBQzM4NgA=', '525650299150', 'hola', NULL, NULL, NULL, '2025-07-17 22:49:35', 'out', '2025-07-17 18:49:35'),
(13, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkY0NUREQUE4MTlFMUVFREYwRQA=', '525650299150', 'hello', 'sangfor-1-r86j958121qd2055qxjdf9je4uh42u5qf299zh58fc.jpg', 0x[BLOB], 'image/jpeg', '2025-07-17 22:49:56', 'out', '2025-07-17 18:49:56');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(14, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDhBN0I2QUVCNUEyMUZDMDU5OUIxODU3M0U4NTMzMjVDAA==', '5215650299150', '[Imagen]', '1306295417546931.jpg', 0x[BLOB], 'image/jpeg', '2025-07-17 22:42:41', 'in', '2025-07-17 18:50:04');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(15, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEUyQTZBREFERkE5MTU2NTQwMUQ2MzUzNTlGRDA5QjMzAA==', '5215650299150', 'Hola', NULL, NULL, NULL, '2025-07-17 22:43:52', 'in', '2025-07-17 18:50:34');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(16, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEVDMTk4NjZFNEI4MTIxRTI1MTgwOUIwMTAxNjBCRjQ5AA==', '5215650299150', '[Imagen]', '739528318668338.jpg', 0x[BLOB], 'image/jpeg', '2025-07-17 22:44:29', 'in', '2025-07-17 18:51:19');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(17, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDRBRDNGNDM0MEEwRkU5ODc5MUM1Q0FCMjA2NDM3RTdDAA==', '5215650299150', 'Hola cómo estás?', NULL, NULL, NULL, '2025-07-17 23:13:40', 'in', '2025-07-17 19:13:41'),
(18, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkUwQkRBNkYwNUZENjEyM0NBQQA=', '525650299150', 'hola', NULL, NULL, NULL, '2025-07-18 00:10:49', 'out', '2025-07-17 20:10:49'),
(19, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDgwODA4QTBEQjE5RjY5MDk5NzZDM0RGMDg2MjA1REE5AA==', '5215650299150', 'Hola prueba', NULL, NULL, NULL, '2025-07-18 00:11:10', 'in', '2025-07-17 20:11:11'),
(20, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDgwODA4QTBEQjE5RjY5MDk5NzZDM0RGMDg2MjA1REE5AA==', '5215650299150', 'Hola prueba', NULL, NULL, NULL, '2025-07-18 00:11:10', 'in', '2025-07-17 20:11:11'),
(21, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEYyNEUxMjAzOTVFRjA1QzhGMEFCQTMxRkZDRkEzOTczAA==', '5215650299150', 'Prueba 2', NULL, NULL, NULL, '2025-07-18 00:27:31', 'in', '2025-07-17 20:27:32'),
(22, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEYyNEUxMjAzOTVFRjA1QzhGMEFCQTMxRkZDRkEzOTczAA==', '5215650299150', 'Prueba 2', NULL, NULL, NULL, '2025-07-18 00:27:31', 'in', '2025-07-17 20:27:32'),
(23, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEjU0MEVGMjEyNzA0MzM2NTI3MQA=', '525650299150', 'prueba', NULL, NULL, NULL, '2025-07-21 22:25:26', 'out', '2025-07-21 18:25:26'),
(24, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDFDQzhCRDM0MkY2NDMxQjQ4QURBMzI3MkQ1MUQyOEM0AA==', '5215650299150', 'Prueba de mensajes', NULL, NULL, NULL, '2025-07-21 23:47:44', 'in', '2025-07-21 19:47:45'),
(25, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEjAxN0VGM0YyN0EwQzBDNDVGMQA=', '525650299150', 'hola ', NULL, NULL, NULL, '2025-07-22 00:22:25', 'out', '2025-07-21 20:22:25'),
(26, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEZFNjNGNEU0OEJBQTJDQTY2RkRGOEEyNTM0ODBDQjJFAA==', '5215650299150', 'Cómo estás?', NULL, NULL, NULL, '2025-07-22 00:22:42', 'in', '2025-07-21 20:22:42'),
(27, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEZFNjNGNEU0OEJBQTJDQTY2RkRGOEEyNTM0ODBDQjJFAA==', '5215650299150', 'Cómo estás?', NULL, NULL, NULL, '2025-07-22 00:22:42', 'in', '2025-07-21 20:22:43'),
(28, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkRGQkJDMDEwRTIyRkY3M0ZGOQA=', '525650299150', 'hello word!', NULL, NULL, NULL, '2025-07-22 00:23:21', 'out', '2025-07-21 20:23:21'),
(29, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDYxMzJCRjZFMDIwMzlENEYxRjg0MUZGMEU2MUUwRjI4AA==', '5215650299150', 'Kiuvo', NULL, NULL, NULL, '2025-07-22 00:23:31', 'in', '2025-07-21 20:23:31'),
(30, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDU2N0UzNUIzRDFGMUQ1MDM0QjNBMkZGM0M0QUY4NDU4AA==', '5215650299150', 'Mejor nadota', NULL, NULL, NULL, '2025-07-22 00:23:43', 'in', '2025-07-21 20:23:44'),
(32, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDlGQzJGMzhBQTYwMzZENEQ4RkEyMDFENTM4NEMzNTYwAA==', '5215650299150', '[Medio no soportado]', NULL, NULL, NULL, '2025-07-22 00:24:02', 'in', '2025-07-21 20:24:04'),
(33, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIERBNTU4QUQyMTQ5NzA1MzM0NTBDNUMyQkIyNDk2QzA0AA==', '5215650299150', '🫃🏻', NULL, NULL, NULL, '2025-07-22 00:24:53', 'in', '2025-07-21 20:24:54'),
(34, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkE4MDI4MkM0M0Q1MTk1N0VDMgA=', '525650299150', '😂', NULL, NULL, NULL, '2025-07-22 00:24:54', 'out', '2025-07-21 20:24:54'),
(35, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkUyRTMwNjcxODdBOEQyREEyOAA=', '525650299150', 'hello', 'usuario.png', 0x[BLOB], 'image/png', '2025-07-22 00:33:17', 'out', '2025-07-21 20:33:17');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(36, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkNDQ0Y0N0Q0N0IzRkQxNThCRAA=', '525650299150', '', 'regresar.webp', 0x[BLOB], 'image/webp', '2025-07-22 00:33:49', 'out', '2025-07-21 20:33:49'),
(37, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEjIwNUY5QTU0MjE5MThEQUEyQgA=', '525650299150', 'hello', 'qrcode.png', 0x[BLOB], 'image/png', '2025-07-22 00:34:26', 'out', '2025-07-21 20:34:26'),
(38, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIDU3OThCQUI5QjEzNzdGN0YyQUYxM0I0NjVCQTIwMTAwAA==', '5215650299150', '[Medio no soportado]', NULL, NULL, NULL, '2025-07-22 00:34:45', 'in', '2025-07-21 20:34:47');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(39, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkQ2MjA0NUMwQjgxQzU0RTQxQQA=', '525650299150', '', 'Hoja.png', 0x[BLOB], 'image/png', '2025-07-22 00:39:20', 'out', '2025-07-21 20:39:20'),
(40, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkM5MEVDMUI0MTNDMUQwMTZBQQA=', '525650299150', '', 'sangfor-1-r86j958121qd2055qxjdf9je4uh42u5qf299zh58fc.jpg', 0x[BLOB], 'image/jpeg', '2025-07-22 00:43:21', 'out', '2025-07-21 20:43:21'),
(41, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEjc5NjY5QzNFMkY5MDM5QUNCQgA=', '525650299150', 'hola', NULL, NULL, NULL, '2025-07-22 02:29:40', 'out', '2025-07-21 22:29:40'),
(42, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABIYIEE1MTEyRUJBQzRGMzI5QkIwRThFRDJBRTRGNzc3MjU2AA==', '5215650299150', 'Hello', NULL, NULL, NULL, '2025-07-22 02:29:54', 'in', '2025-07-21 22:29:55');
INSERT INTO `whatsapp_conversations` (`id`, `wa_message_id`, `phone`, `message`, `file_name`, `file_data`, `file_mime`, `timestamp`, `direction`, `created_at`) VALUES
(43, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkRGQTNGN0JFRDlGQUQzOUM4QwA=', '525650299150', 'HOLA\r\n', NULL, NULL, NULL, '2025-07-22 02:40:37', 'out', '2025-07-21 22:40:37'),
(44, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEjREMzQzQzgyOURCQjM1M0E5MwA=', '525650299150', 'hi', NULL, NULL, NULL, '2025-07-22 02:59:31', 'out', '2025-07-21 22:59:31'),
(45, 'wamid.HBgNNTIxNTY1MDI5OTE1MBUCABEYEkRGN0VBNTIzNzY0RDVBQTI1NAA=', '525650299150', 'envio', NULL, NULL, NULL, '2025-07-22 03:00:40', 'out', '2025-07-21 23:00:40'),
(46, 'wamid.HBgLMTY0NjU4OTQxNjgVAgASGBJFQkZBRDgyQ0RBMTU0MURCNEMA', '16465894168', '*Hit the ground running with conversations that drive conversions*\n\nStart meaningful conversations and turn interest into sales with click-to-WhatsApp ads. To get started, you\'ll need to connect your Facebook Page to a WhatsApp Business Platform phone number. Follow these steps to dive in: https://business.facebook.com/business/help/4631406400243963 . Then, you\'ll be ready to add a button to your Facebook Page and create ads that lead directly to WhatsApp, helping boost engagement for your business. If you\'ve already connected your Facebook Page to a WhatsApp Business Platform phone number, please get started with the link below.\n\n*Get started now:* https://www.facebook.com/business/m/ctwa', NULL, NULL, NULL, '2025-07-23 19:02:30', 'in', '2025-07-23 15:02:33'),
(47, 'wamid.HBgLMTY0NjU4OTQxNjgVAgASGBJFQkZBRDgyQ0RBMTU0MURCNEMA', '16465894168', '*Hit the ground running with conversations that drive conversions*\n\nStart meaningful conversations and turn interest into sales with click-to-WhatsApp ads. To get started, you\'ll need to connect your Facebook Page to a WhatsApp Business Platform phone number. Follow these steps to dive in: https://business.facebook.com/business/help/4631406400243963 . Then, you\'ll be ready to add a button to your Facebook Page and create ads that lead directly to WhatsApp, helping boost engagement for your business. If you\'ve already connected your Facebook Page to a WhatsApp Business Platform phone number, please get started with the link below.\n\n*Get started now:* https://www.facebook.com/business/m/ctwa', NULL, NULL, NULL, '2025-07-23 19:02:30', 'in', '2025-07-23 15:02:34'),
(48, 'wamid.HBgLMTY0NjU4OTQxNjgVAgASGBIzQTdBOEUwRTBBODdFRjUzMjMA', '16465894168', '*Start the conversation with your next customer using ads that click to WhatsApp*\n\nConnect with highly qualified leads by bringing them directly to your WhatsApp chat thread. Use ads that click to WhatsApp to engage, support, and inform customers — within the app they already know and love.\n\n*Get started:* https://www.facebook.com/business/m/ctwa', NULL, NULL, NULL, '2025-07-25 19:02:29', 'in', '2025-07-25 15:02:32'),
(49, 'wamid.HBgLMTY0NjU4OTQxNjgVAgASGBJCNTFDOTRDREY3NUVDRjJCQzcA', '16465894168', '*Start the conversation with your next customer using ads that click to WhatsApp*\n\nConnect with highly qualified leads by bringing them directly to your WhatsApp chat thread. Use ads that click to WhatsApp to engage, support, and inform customers — within the app they already know and love.\n\n*Get started:* https://www.facebook.com/business/m/ctwa', NULL, NULL, NULL, '2025-07-25 19:02:31', 'in', '2025-07-25 15:02:33'),
(50, 'wamid.HBgLMTY0NjU4OTQxNjgVAgASGBJCODQ1Q0UwNDQ3NjQ5OTIzNkUA', '16465894168', '*Lean into convenience to build loyalty that lasts*\n\nDiscover a new way of captivating leads and existing customers with ads that click to WhatsApp. Watch this video for instructions on how to create your ads, so you can encourage repeat business and foster long-term loyalty through personalized conversations: https://www.youtube.com/watch?v=t753Fr5w4UE\n\n*Get started:* https://www.facebook.com/business/m/ctwa', NULL, NULL, NULL, '2025-07-27 19:02:29', 'in', '2025-07-27 15:02:32'),
(51, 'wamid.HBgLMTY0NjU4OTQxNjgVAgASGBIwMUVDMTdFOTU4MUJBNDREMDIA', '16465894168', '*Reach new and existing customers at scale using WhatsApp*\n\nUsing ads that click to WhatsApp, customers can start meaningful conversations with your business in just one click. This innovative ad format gives you more opportunities to reach customers directly — initiating informative conversations while driving purchases.\n\n*Get started*: https://www.facebook.com/business/m/ctwa', NULL, NULL, NULL, '2025-07-29 19:02:30', 'in', '2025-07-29 15:02:32');

--
-- Índices para tablas volcadas
--

--
-- Indices de la tabla `almacenes`
--
ALTER TABLE `almacenes`
  ADD PRIMARY KEY (`id_almacen`),
  ADD UNIQUE KEY `codigo` (`codigo`),
  ADD KEY `idx_bodega` (`id_bodega`),
  ADD KEY `idx_codigo` (`codigo`),
  ADD KEY `idx_estado` (`estado_almacen`);

--
-- Indices de la tabla `blacklisted_domains`
--
ALTER TABLE `blacklisted_domains`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `domain` (`domain`);

--
-- Indices de la tabla `bodegas`
--
ALTER TABLE `bodegas`
  ADD PRIMARY KEY (`id_bodega`),
  ADD KEY `idx_nombre` (`nombre`),
  ADD KEY `idx_estado` (`estado_bodega`);

--
-- Indices de la tabla `cartas_entrega`
--
ALTER TABLE `cartas_entrega`
  ADD PRIMARY KEY (`id_carta`),
  ADD UNIQUE KEY `numero_carta` (`numero_carta`),
  ADD KEY `idx_numero` (`numero_carta`),
  ADD KEY `idx_producto` (`id_producto`),
  ADD KEY `idx_estado` (`estado_entrega`),
  ADD KEY `idx_fecha_entrega` (`fecha_entrega`);

--
-- Indices de la tabla `catalogos`
--
ALTER TABLE `catalogos`
  ADD PRIMARY KEY (`id_catalogo`),
  ADD UNIQUE KEY `unique_catalogo` (`modulo`,`campo`,`valor`);

--
-- Indices de la tabla `categories`
--
ALTER TABLE `categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `classifications`
--
ALTER TABLE `classifications`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `contactos_empresa`
--
ALTER TABLE `contactos_empresa`
  ADD PRIMARY KEY (`id_contacto`),
  ADD KEY `id_empresa` (`id_empresa`);

--
-- Indices de la tabla `contact_modes`
--
ALTER TABLE `contact_modes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `email_references`
--
ALTER TABLE `email_references`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`),
  ADD UNIQUE KEY `message_id` (`message_id`),
  ADD KEY `message_id_2` (`message_id`),
  ADD KEY `thread_id` (`thread_id`),
  ADD KEY `in_reply_to` (`in_reply_to`),
  ADD KEY `ticket_message_id` (`ticket_message_id`);

--
-- Indices de la tabla `email_threads`
--
ALTER TABLE `email_threads`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`),
  ADD UNIQUE KEY `thread_id` (`thread_id`),
  ADD KEY `thread_id_2` (`thread_id`),
  ADD KEY `ticket_id` (`ticket_id`);

--
-- Indices de la tabla `empresas`
--
ALTER TABLE `empresas`
  ADD PRIMARY KEY (`id_empresa`),
  ADD UNIQUE KEY `id_empresa` (`id_empresa`);

--
-- Indices de la tabla `historial_actividades`
--
ALTER TABLE `historial_actividades`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_usuario` (`id_usuario`);

--
-- Indices de la tabla `historial_movimientos`
--
ALTER TABLE `historial_movimientos`
  ADD PRIMARY KEY (`id_movimiento`),
  ADD KEY `almacen_origen` (`almacen_origen`),
  ADD KEY `almacen_destino` (`almacen_destino`),
  ADD KEY `id_carta_entrega` (`id_carta_entrega`),
  ADD KEY `idx_producto` (`id_producto`),
  ADD KEY `idx_tipo` (`tipo_movimiento`),
  ADD KEY `idx_fecha` (`fecha_movimiento`);

--
-- Indices de la tabla `impacts`
--
ALTER TABLE `impacts`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `level`
--
ALTER TABLE `level`
  ADD PRIMARY KEY (`id`);

--
-- Indices de la tabla `levels`
--
ALTER TABLE `levels`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `permisos_rutas`
--
ALTER TABLE `permisos_rutas`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_rol_ruta` (`rol`,`ruta`);

--
-- Indices de la tabla `priorities`
--
ALTER TABLE `priorities`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `processed_emails`
--
ALTER TABLE `processed_emails`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `unique_message_id` (`message_id`),
  ADD KEY `idx_sender_email` (`sender_email`),
  ADD KEY `idx_email_date` (`email_date`),
  ADD KEY `idx_processed_at` (`processed_at`),
  ADD KEY `idx_ticket_id` (`ticket_id`);

--
-- Indices de la tabla `productos_almacen`
--
ALTER TABLE `productos_almacen`
  ADD PRIMARY KEY (`id_producto`),
  ADD UNIQUE KEY `codigo_producto` (`codigo_producto`),
  ADD KEY `idx_almacen` (`id_almacen`),
  ADD KEY `idx_codigo` (`codigo_producto`),
  ADD KEY `idx_estado` (`estado_producto`),
  ADD KEY `idx_categoria` (`categoria`);

--
-- Indices de la tabla `requesters`
--
ALTER TABLE `requesters`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `statuses`
--
ALTER TABLE `statuses`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `technicians`
--
ALTER TABLE `technicians`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `tickets`
--
ALTER TABLE `tickets`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `ticket_attachments`
--
ALTER TABLE `ticket_attachments`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`),
  ADD KEY `ticket_attachments_ibfk_1` (`ticket_id`),
  ADD KEY `ticket_attachments_ibfk_2` (`message_id`);

--
-- Indices de la tabla `ticket_costs`
--
ALTER TABLE `ticket_costs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `ticket_id` (`ticket_id`);

--
-- Indices de la tabla `ticket_cost_attachments`
--
ALTER TABLE `ticket_cost_attachments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `cost_id` (`cost_id`);

--
-- Indices de la tabla `ticket_history`
--
ALTER TABLE `ticket_history`
  ADD PRIMARY KEY (`id`),
  ADD KEY `ticket_id` (`ticket_id`),
  ADD KEY `action` (`action`),
  ADD KEY `created_at` (`created_at`);

--
-- Indices de la tabla `ticket_messages`
--
ALTER TABLE `ticket_messages`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`),
  ADD UNIQUE KEY `idx_imap_uid` (`imap_uid`),
  ADD KEY `idx_message_id` (`message_id`(250)),
  ADD KEY `idx_parent_message_id` (`parent_message_id`);

--
-- Indices de la tabla `ticket_status_tracking`
--
ALTER TABLE `ticket_status_tracking`
  ADD PRIMARY KEY (`id`),
  ADD KEY `ticket_id` (`ticket_id`),
  ADD KEY `status_id` (`status_id`),
  ADD KEY `is_active` (`is_active`),
  ADD KEY `started_at` (`started_at`);

--
-- Indices de la tabla `urgencies`
--
ALTER TABLE `urgencies`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id` (`id`);

--
-- Indices de la tabla `user_history`
--
ALTER TABLE `user_history`
  ADD PRIMARY KEY (`id`),
  ADD KEY `target_user_id` (`target_user_id`);

--
-- Indices de la tabla `whatsapp_conversations`
--
ALTER TABLE `whatsapp_conversations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_phone` (`phone`),
  ADD KEY `idx_timestamp` (`timestamp`),
  ADD KEY `idx_wa_message_id` (`wa_message_id`);

--
-- AUTO_INCREMENT de las tablas volcadas
--

--
-- AUTO_INCREMENT de la tabla `almacenes`
--
ALTER TABLE `almacenes`
  MODIFY `id_almacen` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT de la tabla `blacklisted_domains`
--
ALTER TABLE `blacklisted_domains`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT de la tabla `bodegas`
--
ALTER TABLE `bodegas`
  MODIFY `id_bodega` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT de la tabla `cartas_entrega`
--
ALTER TABLE `cartas_entrega`
  MODIFY `id_carta` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT de la tabla `catalogos`
--
ALTER TABLE `catalogos`
  MODIFY `id_catalogo` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=22;

--
-- AUTO_INCREMENT de la tabla `categories`
--
ALTER TABLE `categories`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT de la tabla `classifications`
--
ALTER TABLE `classifications`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT de la tabla `contactos_empresa`
--
ALTER TABLE `contactos_empresa`
  MODIFY `id_contacto` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=47;

--
-- AUTO_INCREMENT de la tabla `contact_modes`
--
ALTER TABLE `contact_modes`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT de la tabla `email_references`
--
ALTER TABLE `email_references`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `email_threads`
--
ALTER TABLE `email_threads`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de la tabla `empresas`
--
ALTER TABLE `empresas`
  MODIFY `id_empresa` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=45;

--
-- AUTO_INCREMENT de la tabla `historial_actividades`
--
ALTER TABLE `historial_actividades`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=650;

--
-- AUTO_INCREMENT de la tabla `historial_movimientos`
--
ALTER TABLE `historial_movimientos`
  MODIFY `id_movimiento` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

--
-- AUTO_INCREMENT de la tabla `impacts`
--
ALTER TABLE `impacts`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT de la tabla `level`
--
ALTER TABLE `level`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT de la tabla `levels`
--
ALTER TABLE `levels`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT de la tabla `permisos_rutas`
--
ALTER TABLE `permisos_rutas`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=32;

--
-- AUTO_INCREMENT de la tabla `priorities`
--
ALTER TABLE `priorities`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT de la tabla `processed_emails`
--
ALTER TABLE `processed_emails`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT de la tabla `productos_almacen`
--
ALTER TABLE `productos_almacen`
  MODIFY `id_producto` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;

--
-- AUTO_INCREMENT de la tabla `requesters`
--
ALTER TABLE `requesters`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;

--
-- AUTO_INCREMENT de la tabla `statuses`
--
ALTER TABLE `statuses`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;

--
-- AUTO_INCREMENT de la tabla `technicians`
--
ALTER TABLE `technicians`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT de la tabla `tickets`
--
ALTER TABLE `tickets`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1358;

--
-- AUTO_INCREMENT de la tabla `ticket_attachments`
--
ALTER TABLE `ticket_attachments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=777;

--
-- AUTO_INCREMENT de la tabla `ticket_costs`
--
ALTER TABLE `ticket_costs`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=27;

--
-- AUTO_INCREMENT de la tabla `ticket_cost_attachments`
--
ALTER TABLE `ticket_cost_attachments`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;

--
-- AUTO_INCREMENT de la tabla `ticket_history`
--
ALTER TABLE `ticket_history`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=186;

--
-- AUTO_INCREMENT de la tabla `ticket_messages`
--
ALTER TABLE `ticket_messages`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=833;

--
-- AUTO_INCREMENT de la tabla `ticket_status_tracking`
--
ALTER TABLE `ticket_status_tracking`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28;

--
-- AUTO_INCREMENT de la tabla `urgencies`
--
ALTER TABLE `urgencies`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de la tabla `user_history`
--
ALTER TABLE `user_history`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;

--
-- AUTO_INCREMENT de la tabla `whatsapp_conversations`
--
ALTER TABLE `whatsapp_conversations`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=52;

--
-- Restricciones para tablas volcadas
--

--
-- Filtros para la tabla `almacenes`
--
ALTER TABLE `almacenes`
  ADD CONSTRAINT `almacenes_ibfk_1` FOREIGN KEY (`id_bodega`) REFERENCES `bodegas` (`id_bodega`) ON DELETE CASCADE;

--
-- Filtros para la tabla `cartas_entrega`
--
ALTER TABLE `cartas_entrega`
  ADD CONSTRAINT `cartas_entrega_ibfk_1` FOREIGN KEY (`id_producto`) REFERENCES `productos_almacen` (`id_producto`) ON DELETE SET NULL;

--
-- Filtros para la tabla `historial_movimientos`
--
ALTER TABLE `historial_movimientos`
  ADD CONSTRAINT `historial_movimientos_ibfk_1` FOREIGN KEY (`id_producto`) REFERENCES `productos_almacen` (`id_producto`) ON DELETE SET NULL,
  ADD CONSTRAINT `historial_movimientos_ibfk_2` FOREIGN KEY (`almacen_origen`) REFERENCES `almacenes` (`id_almacen`) ON DELETE SET NULL,
  ADD CONSTRAINT `historial_movimientos_ibfk_3` FOREIGN KEY (`almacen_destino`) REFERENCES `almacenes` (`id_almacen`) ON DELETE SET NULL,
  ADD CONSTRAINT `historial_movimientos_ibfk_4` FOREIGN KEY (`id_carta_entrega`) REFERENCES `cartas_entrega` (`id_carta`) ON DELETE SET NULL;

--
-- Filtros para la tabla `productos_almacen`
--
ALTER TABLE `productos_almacen`
  ADD CONSTRAINT `productos_almacen_ibfk_1` FOREIGN KEY (`id_almacen`) REFERENCES `almacenes` (`id_almacen`) ON DELETE CASCADE;
COMMIT;

