Sistema Contenedor Ibiza v2.0 - Despliegue Docker
This commit is contained in:
81
database.sql
Normal file
81
database.sql
Normal file
@@ -0,0 +1,81 @@
|
||||
-- Sistema de Gestión de Contenedores - Base de Datos
|
||||
-- Creación de base de datos y tablas
|
||||
-- NOTA: Se usan DROP TABLE para asegurar una instalación limpia.
|
||||
|
||||
USE contenedor_ibiza1;
|
||||
|
||||
-- Desactivar checks de llaves foráneas temporalmente para permitir drops
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- Eliminar tablas si existen para evitar conflictos de estructura
|
||||
DROP TABLE IF EXISTS assignments;
|
||||
DROP TABLE IF EXISTS schedules;
|
||||
DROP TABLE IF EXISTS users;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
-- Tabla de usuarios
|
||||
CREATE TABLE users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
full_name VARCHAR(100) NOT NULL,
|
||||
role ENUM('admin', 'coordinador', 'ayudante') NOT NULL DEFAULT 'ayudante',
|
||||
active TINYINT(1) NOT NULL DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_role (role),
|
||||
INDEX idx_active (active)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Tabla de horarios del contenedor
|
||||
CREATE TABLE schedules (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
day_of_week TINYINT NOT NULL COMMENT '0=Domingo, 1=Lunes, ..., 6=Sábado',
|
||||
opening_time_1 TIME NULL COMMENT 'Primer horario de apertura',
|
||||
opening_time_2 TIME NULL COMMENT 'Segundo horario de apertura',
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY unique_day (day_of_week)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Tabla de asignaciones/rotaciones
|
||||
CREATE TABLE assignments (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
week_number INT NOT NULL COMMENT 'Número de semana del año (1-53)',
|
||||
year INT NOT NULL,
|
||||
start_date DATE NOT NULL COMMENT 'Fecha de inicio (siempre domingo)',
|
||||
end_date DATE NOT NULL COMMENT 'Fecha de fin (siempre sábado)',
|
||||
order_position INT NOT NULL DEFAULT 0 COMMENT 'Posición en el orden para drag & drop',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
UNIQUE KEY unique_week (year, week_number),
|
||||
INDEX idx_user (user_id),
|
||||
INDEX idx_dates (start_date, end_date),
|
||||
INDEX idx_year_week (year, week_number)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Insertar horarios por defecto
|
||||
INSERT INTO schedules (day_of_week, opening_time_1, opening_time_2) VALUES
|
||||
(0, '19:00:00', '22:00:00'), -- Domingo
|
||||
(1, '06:30:00', '09:00:00'), -- Lunes
|
||||
(2, '19:00:00', '22:00:00'), -- Martes
|
||||
(3, '06:30:00', '09:00:00'), -- Miércoles
|
||||
(4, '19:00:00', '22:00:00'), -- Jueves
|
||||
(5, '06:30:00', '06:30:00'), -- Viernes
|
||||
(6, NULL, NULL); -- Sábado (cerrado)
|
||||
|
||||
-- Insertar usuario administrador por defecto
|
||||
-- Password: admin123
|
||||
INSERT INTO users (username, password, full_name, role, active) VALUES
|
||||
('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Administrador', 'admin', 1);
|
||||
|
||||
-- Insertar usuarios helpers de ejemplo
|
||||
INSERT INTO users (username, password, full_name, role, active) VALUES
|
||||
('ana', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Ana García', 'ayudante', 1),
|
||||
('esperanza', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Esperanza López', 'ayudante', 1),
|
||||
('mary', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Mary Martínez', 'ayudante', 1),
|
||||
('bety', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Bety Rodríguez', 'ayudante', 1),
|
||||
('mariela', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Mariela Sánchez', 'ayudante', 1),
|
||||
('coord1', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'Coordinador Ejemplo', 'coordinador', 1);
|
||||
Reference in New Issue
Block a user