2024-12-11 12:43:57 +01:00
|
|
|
CREATE TYPE role AS ENUM ('estudiante', 'profesor', 'admin');
|
2024-12-09 10:43:12 +01:00
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
CREATE TABLE usuarios (
|
|
|
|
id_usuario INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
|
|
|
email VARCHAR(255) UNIQUE NOT NULL,
|
2024-12-09 10:43:12 +01:00
|
|
|
nombre VARCHAR(255) NOT NULL,
|
|
|
|
apellido1 VARCHAR(255),
|
|
|
|
apellido2 VARCHAR(255),
|
2024-12-11 12:43:57 +01:00
|
|
|
password VARCHAR(255) NOT NULL,
|
|
|
|
rol role NOT NULL
|
2024-12-09 10:43:12 +01:00
|
|
|
);
|
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
CREATE TABLE cuestionarios (
|
2024-12-09 10:43:12 +01:00
|
|
|
id_cuestionario INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
2024-12-11 12:43:57 +01:00
|
|
|
id_usuario INT NOT NULL,
|
2024-12-09 10:43:12 +01:00
|
|
|
titulo VARCHAR(255) NOT NULL,
|
|
|
|
descripcion VARCHAR(255),
|
2024-12-11 12:43:57 +01:00
|
|
|
CONSTRAINT fk_usuario FOREIGN KEY(id_usuario) REFERENCES USUARIOS(id_usuario)
|
2024-12-09 10:43:12 +01:00
|
|
|
);
|
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
CREATE TABLE preguntas (
|
2024-12-09 10:43:12 +01:00
|
|
|
id_pregunta INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
|
|
|
id_cuestionario INT NOT NULL,
|
|
|
|
enunciado VARCHAR(255) NOT NULL,
|
|
|
|
CONSTRAINT fk_cuestionario FOREIGN KEY(id_cuestionario) REFERENCES CUESTIONARIOS(id_cuestionario)
|
|
|
|
);
|
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
CREATE TABLE respuestas (
|
2024-12-09 10:43:12 +01:00
|
|
|
id_respuesta INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
|
|
|
id_pregunta INT NOT NULL,
|
|
|
|
respuesta VARCHAR(255) NOT NULL,
|
|
|
|
es_verdadera BOOLEAN NOT NULL,
|
|
|
|
CONSTRAINT fk_pregunta FOREIGN KEY(id_pregunta) REFERENCES PREGUNTAS(id_pregunta)
|
|
|
|
);
|
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
CREATE TABLE juega (
|
2024-12-09 10:43:12 +01:00
|
|
|
id_intento INT PRIMARY KEY,
|
2024-12-11 12:43:57 +01:00
|
|
|
id_usuario INT NOT NULL,
|
2024-12-09 10:43:12 +01:00
|
|
|
id_cuestionario INT NOT NULL,
|
|
|
|
num_correctas INT NOT NULL,
|
2024-12-11 12:43:57 +01:00
|
|
|
CONSTRAINT fk_usuario FOREIGN KEY(id_usuario) REFERENCES USUARIOS(id_usuario),
|
2024-12-09 10:43:12 +01:00
|
|
|
CONSTRAINT id_cuestionario FOREIGN KEY(id_cuestionario) REFERENCES CUESTIONARIOS(id_cuestionario)
|
2024-12-06 09:03:49 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
-- add test data
|
2024-12-11 12:43:57 +01:00
|
|
|
INSERT INTO usuarios (nombre, apellido1, apellido2, email, password, rol)
|
|
|
|
VALUES ('Raúl', 'Bulgariu', 'Suciu', 'raul@bulgariu.xyz', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f', 'admin'),
|
|
|
|
('Jacinto', 'Sánchez', 'Villa', 'j.sanchezvilla@gmail.com', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f', 'profesor'),
|
|
|
|
('David', 'Balaguer', 'Garcia', 'david@gmail.com', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f', 'profesor'),
|
|
|
|
('Aaron', 'Martinez', '', 'aaron@martinez.xyz', 'ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f', 'estudiante');
|
2024-12-09 10:43:12 +01:00
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
INSERT INTO CUESTIONARIOS (id_usuario, titulo, descripcion)
|
|
|
|
SELECT id_usuario, 'Examen SOM', 'Cuestionario con preguntas sobre SOM'
|
|
|
|
FROM usuarios
|
|
|
|
WHERE email = 'j.sanchezvilla@gmail.com';
|
2024-12-09 10:43:12 +01:00
|
|
|
|
2024-12-11 12:43:57 +01:00
|
|
|
INSERT INTO CUESTIONARIOS (id_usuario, titulo, descripcion)
|
|
|
|
SELECT id_usuario, 'Examen OFI', 'Cuestionario con preguntas sobre OFI'
|
|
|
|
FROM usuarios
|
|
|
|
WHERE email = 'david@gmail.com';
|
2024-12-09 10:43:12 +01:00
|
|
|
|
|
|
|
INSERT INTO PREGUNTAS (id_cuestionario, enunciado)
|
|
|
|
VALUES (1, 'Qué comando muestra los archivos del directorio actual?'),
|
|
|
|
(1, 'Como podemos editar un archivo de texto?'),
|
|
|
|
(2, 'Es GIMP un editor de texto?');
|
|
|
|
|
|
|
|
INSERT INTO RESPUESTAS (id_pregunta, respuesta, es_verdadera)
|
|
|
|
VALUES (1, 'whoami', false),
|
|
|
|
(1, 'ls', true),
|
|
|
|
(1, 'chmod', false),
|
|
|
|
(1, 'sudo', false),
|
|
|
|
(2, 'nano', true),
|
|
|
|
(2, 'cat', false),
|
|
|
|
(2, 'vim', true),
|
|
|
|
(2, 'less', false),
|
|
|
|
(3, 'Verdadero', false),
|
|
|
|
(3, 'Falso', true);
|
|
|
|
|