-- --------------------------------------------------------
-- Inventario DB - Schema ordenado para import en phpMyAdmin
-- Origen: inventario_db_1.sql (solo estructura, sin data)
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;



-- Base
CREATE TABLE IF NOT EXISTS `tiendas` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `nombre` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `direccion` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `activo` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_verified_at` timestamp NULL DEFAULT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `role` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'VENDEDOR',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `tienda_id` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`),
  KEY `users_tienda_id_foreign` (`tienda_id`),
  CONSTRAINT `users_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `productos` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `barcode` varchar(13) COLLATE utf8mb4_unicode_ci NOT NULL,
  `nombre` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `descripcion` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `categoria` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `costo` decimal(12,2) NOT NULL DEFAULT '0.00',
  `precio` decimal(12,2) NOT NULL DEFAULT '0.00',
  `activo` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `productos_barcode_unique` (`barcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `clientes` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `nombres` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `dni` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `telefono` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `credito_saldo` decimal(10,2) NOT NULL DEFAULT '0.00',
  `activo` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `tienda_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `clientes_dni_unique` (`dni`),
  KEY `clientes_tienda_id_foreign` (`tienda_id`),
  CONSTRAINT `clientes_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Operaciones principales
CREATE TABLE IF NOT EXISTS `cajas` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tienda_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `fecha_apertura` datetime NOT NULL,
  `fecha_cierre` datetime DEFAULT NULL,
  `monto_inicial` decimal(12,2) NOT NULL DEFAULT '0.00',
  `monto_cierre` decimal(12,2) DEFAULT NULL,
  `estado` enum('ABIERTA','CERRADA') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ABIERTA',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `cajas_tienda_id_foreign` (`tienda_id`),
  KEY `cajas_user_id_foreign` (`user_id`),
  CONSTRAINT `cajas_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `cajas_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `ventas` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tienda_id` bigint unsigned NOT NULL,
  `caja_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `cliente_id` bigint unsigned NOT NULL,
  `total` decimal(12,2) NOT NULL,
  `descuento_monto` decimal(12,2) NOT NULL DEFAULT '0.00',
  `credito_aplicado` decimal(12,2) NOT NULL DEFAULT '0.00',
  `estado` enum('PAGADA','ANULADA') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'PAGADA',
  `origen` enum('VENTA','SEPARACION') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'VENTA',
  `metodo` enum('EFECTIVO','YAPE','PLIN','TARJETA','TRANSFERENCIA') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'EFECTIVO',
  `anulado_por` bigint unsigned DEFAULT NULL,
  `anulado_en` timestamp NULL DEFAULT NULL,
  `motivo` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ventas_tienda_id_foreign` (`tienda_id`),
  KEY `ventas_caja_id_foreign` (`caja_id`),
  KEY `ventas_user_id_foreign` (`user_id`),
  KEY `ventas_cliente_id_foreign` (`cliente_id`),
  KEY `ventas_anulado_por_foreign` (`anulado_por`),
  CONSTRAINT `ventas_anulado_por_foreign` FOREIGN KEY (`anulado_por`) REFERENCES `users` (`id`),
  CONSTRAINT `ventas_caja_id_foreign` FOREIGN KEY (`caja_id`) REFERENCES `cajas` (`id`),
  CONSTRAINT `ventas_cliente_id_foreign` FOREIGN KEY (`cliente_id`) REFERENCES `clientes` (`id`),
  CONSTRAINT `ventas_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `ventas_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `venta_items` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `venta_id` bigint unsigned NOT NULL,
  `producto_id` bigint unsigned NOT NULL,
  `barcode_snapshot` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `nombre_snapshot` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `precio_unit_snapshot` decimal(12,2) NOT NULL,
  `cantidad` int NOT NULL,
  `subtotal` decimal(12,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `venta_items_venta_id_foreign` (`venta_id`),
  KEY `venta_items_producto_id_foreign` (`producto_id`),
  CONSTRAINT `venta_items_producto_id_foreign` FOREIGN KEY (`producto_id`) REFERENCES `productos` (`id`),
  CONSTRAINT `venta_items_venta_id_foreign` FOREIGN KEY (`venta_id`) REFERENCES `ventas` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `separaciones` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tienda_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `cliente_id` bigint unsigned NOT NULL,
  `total` decimal(12,2) NOT NULL,
  `saldo` decimal(12,2) NOT NULL,
  `descuento_monto` decimal(12,2) NOT NULL DEFAULT '0.00',
  `credito_aplicado` decimal(12,2) NOT NULL DEFAULT '0.00',
  `estado` enum('PENDIENTE','COMPLETADA','CANCELADA') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'PENDIENTE',
  `nota` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `venta_id` bigint unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `separaciones_tienda_id_foreign` (`tienda_id`),
  KEY `separaciones_user_id_foreign` (`user_id`),
  KEY `separaciones_cliente_id_foreign` (`cliente_id`),
  KEY `separaciones_venta_id_foreign` (`venta_id`),
  CONSTRAINT `separaciones_cliente_id_foreign` FOREIGN KEY (`cliente_id`) REFERENCES `clientes` (`id`),
  CONSTRAINT `separaciones_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `separaciones_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `separaciones_venta_id_foreign` FOREIGN KEY (`venta_id`) REFERENCES `ventas` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `separacion_items` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `separacion_id` bigint unsigned NOT NULL,
  `producto_id` bigint unsigned NOT NULL,
  `barcode_snapshot` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
  `nombre_snapshot` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `precio_unit_snapshot` decimal(12,2) NOT NULL,
  `cantidad` int NOT NULL,
  `subtotal` decimal(12,2) NOT NULL,
  `estado` enum('RESERVADO','CANCELADO','VENDIDO') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'RESERVADO',
  `pagado` decimal(12,2) NOT NULL DEFAULT '0.00',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `separacion_items_separacion_id_foreign` (`separacion_id`),
  KEY `separacion_items_producto_id_foreign` (`producto_id`),
  CONSTRAINT `separacion_items_producto_id_foreign` FOREIGN KEY (`producto_id`) REFERENCES `productos` (`id`),
  CONSTRAINT `separacion_items_separacion_id_foreign` FOREIGN KEY (`separacion_id`) REFERENCES `separaciones` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `separacion_pagos` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `separacion_id` bigint unsigned NOT NULL,
  `separacion_item_id` bigint unsigned DEFAULT NULL,
  `caja_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `monto` decimal(12,2) NOT NULL,
  `metodo` enum('EFECTIVO','YAPE','PLIN','TARJETA','TRANSFERENCIA') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'EFECTIVO',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `separacion_pagos_separacion_id_foreign` (`separacion_id`),
  KEY `separacion_pagos_caja_id_foreign` (`caja_id`),
  KEY `separacion_pagos_user_id_foreign` (`user_id`),
  KEY `separacion_pagos_separacion_item_id_foreign` (`separacion_item_id`),
  CONSTRAINT `separacion_pagos_caja_id_foreign` FOREIGN KEY (`caja_id`) REFERENCES `cajas` (`id`),
  CONSTRAINT `separacion_pagos_separacion_id_foreign` FOREIGN KEY (`separacion_id`) REFERENCES `separaciones` (`id`) ON DELETE CASCADE,
  CONSTRAINT `separacion_pagos_separacion_item_id_foreign` FOREIGN KEY (`separacion_item_id`) REFERENCES `separacion_items` (`id`) ON DELETE CASCADE,
  CONSTRAINT `separacion_pagos_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `separacion_notas` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `separacion_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `nota` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `separacion_notas_separacion_id_foreign` (`separacion_id`),
  KEY `separacion_notas_user_id_foreign` (`user_id`),
  CONSTRAINT `separacion_notas_separacion_id_foreign` FOREIGN KEY (`separacion_id`) REFERENCES `separaciones` (`id`) ON DELETE CASCADE,
  CONSTRAINT `separacion_notas_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `inventarios` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tienda_id` bigint unsigned NOT NULL,
  `producto_id` bigint unsigned NOT NULL,
  `stock` int NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `inventarios_tienda_id_producto_id_unique` (`tienda_id`,`producto_id`),
  KEY `inventarios_producto_id_foreign` (`producto_id`),
  CONSTRAINT `inventarios_producto_id_foreign` FOREIGN KEY (`producto_id`) REFERENCES `productos` (`id`),
  CONSTRAINT `inventarios_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `movimientos_inventario` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tienda_id` bigint unsigned NOT NULL,
  `producto_id` bigint unsigned NOT NULL,
  `tipo` enum('ENTRADA','SALIDA','TRANSFERENCIA_IN','TRANSFERENCIA_OUT','VENTA','AJUSTE') COLLATE utf8mb4_unicode_ci NOT NULL,
  `cantidad` int NOT NULL,
  `stock_antes` int NOT NULL,
  `stock_despues` int NOT NULL,
  `referencia` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `nota` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `tienda_origen_id` bigint unsigned DEFAULT NULL,
  `tienda_destino_id` bigint unsigned DEFAULT NULL,
  `codigo_transferencia` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `movimientos_inventario_tienda_id_foreign` (`tienda_id`),
  KEY `movimientos_inventario_producto_id_foreign` (`producto_id`),
  KEY `movimientos_inventario_tienda_origen_id_foreign` (`tienda_origen_id`),
  KEY `movimientos_inventario_tienda_destino_id_foreign` (`tienda_destino_id`),
  CONSTRAINT `movimientos_inventario_producto_id_foreign` FOREIGN KEY (`producto_id`) REFERENCES `productos` (`id`),
  CONSTRAINT `movimientos_inventario_tienda_destino_id_foreign` FOREIGN KEY (`tienda_destino_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `movimientos_inventario_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `movimientos_inventario_tienda_origen_id_foreign` FOREIGN KEY (`tienda_origen_id`) REFERENCES `tiendas` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `transferencias` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `producto_id` bigint unsigned NOT NULL,
  `tienda_origen_id` bigint unsigned NOT NULL,
  `tienda_destino_id` bigint unsigned NOT NULL,
  `cantidad` int NOT NULL,
  `estado` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ENVIADA',
  `nota` text COLLATE utf8mb4_unicode_ci,
  `enviada_por` bigint unsigned DEFAULT NULL,
  `enviada_at` timestamp NULL DEFAULT NULL,
  `recibida_por` bigint unsigned DEFAULT NULL,
  `recibida_at` timestamp NULL DEFAULT NULL,
  `rechazada_por` bigint unsigned DEFAULT NULL,
  `rechazada_at` timestamp NULL DEFAULT NULL,
  `motivo_rechazo` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `transferencias_tienda_destino_id_estado_index` (`tienda_destino_id`,`estado`),
  KEY `transferencias_tienda_origen_id_estado_index` (`tienda_origen_id`,`estado`),
  KEY `transferencias_producto_id_foreign` (`producto_id`),
  KEY `transferencias_enviada_por_foreign` (`enviada_por`),
  KEY `transferencias_recibida_por_foreign` (`recibida_por`),
  KEY `transferencias_rechazada_por_foreign` (`rechazada_por`),
  CONSTRAINT `transferencias_enviada_por_foreign` FOREIGN KEY (`enviada_por`) REFERENCES `users` (`id`),
  CONSTRAINT `transferencias_producto_id_foreign` FOREIGN KEY (`producto_id`) REFERENCES `productos` (`id`),
  CONSTRAINT `transferencias_rechazada_por_foreign` FOREIGN KEY (`rechazada_por`) REFERENCES `users` (`id`),
  CONSTRAINT `transferencias_recibida_por_foreign` FOREIGN KEY (`recibida_por`) REFERENCES `users` (`id`),
  CONSTRAINT `transferencias_tienda_destino_id_foreign` FOREIGN KEY (`tienda_destino_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `transferencias_tienda_origen_id_foreign` FOREIGN KEY (`tienda_origen_id`) REFERENCES `tiendas` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `caja_movimientos` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `caja_id` bigint unsigned NOT NULL,
  `tienda_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `tipo` enum('INGRESO','EGRESO') COLLATE utf8mb4_unicode_ci NOT NULL,
  `monto` decimal(12,2) NOT NULL,
  `metodo` enum('EFECTIVO','YAPE','PLIN','TARJETA','TRANSFERENCIA') COLLATE utf8mb4_unicode_ci NOT NULL,
  `nota` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `caja_movimientos_user_id_foreign` (`user_id`),
  KEY `caja_movimientos_tienda_id_created_at_index` (`tienda_id`,`created_at`),
  KEY `caja_movimientos_caja_id_tipo_index` (`caja_id`,`tipo`),
  CONSTRAINT `caja_movimientos_caja_id_foreign` FOREIGN KEY (`caja_id`) REFERENCES `cajas` (`id`),
  CONSTRAINT `caja_movimientos_tienda_id_foreign` FOREIGN KEY (`tienda_id`) REFERENCES `tiendas` (`id`),
  CONSTRAINT `caja_movimientos_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Auxiliares
CREATE TABLE IF NOT EXISTS `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `password_reset_tokens` (
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `personal_access_tokens` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tokenable_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `tokenable_id` bigint unsigned NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `abilities` text COLLATE utf8mb4_unicode_ci,
  `last_used_at` timestamp NULL DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `personal_access_tokens_token_unique` (`token`),
  KEY `personal_access_tokens_tokenable_type_tokenable_id_index` (`tokenable_type`,`tokenable_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
