-- ============================================================
-- Patch: Login + Usuarios (Garrafones)
-- Fecha: 2026-03-04
-- ============================================================

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `pass_hash` varchar(255) NOT NULL,
  `role` enum('admin','user') NOT NULL DEFAULT 'user',
  `activo` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_users_username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Usuario admin inicial (cámbiale la contraseña al primer login)
-- user: admin
-- pass: admin123
INSERT INTO `users` (`username`,`pass_hash`,`role`,`activo`)
VALUES ('admin','$2y$10$Td0Gdfq34Gpa2L0qNbaD/ua5.XEogOiqOJ169rPp43uZctGz/4M/G','admin',1)
ON DUPLICATE KEY UPDATE role=VALUES(role), activo=VALUES(activo);
