-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
-- Usuarios Table | ||
CREATE TABLE Usuarios ( | ||
usuario_id INT AUTO_INCREMENT PRIMARY KEY, | ||
nombre VARCHAR(100) NOT NULL, | ||
correo VARCHAR(100) UNIQUE NOT NULL, | ||
contrasena VARCHAR(100) NOT NULL | ||
); | ||
|
||
-- Compras Table | ||
CREATE TABLE Compras ( | ||
compra_id INT AUTO_INCREMENT PRIMARY KEY, | ||
usuario_id INT NOT NULL, | ||
fecha_compra DATE NOT NULL, | ||
estado INT NOT NULL DEFAULT 1, -- 1: Pedido Confirmado, 2: Insumos Listos, 3: Maquila en Proceso, 4: Barniz, 5: Armado, 6: En Camino, 7: Entrega | ||
direccion_envio VARCHAR(255) NOT NULL, | ||
FOREIGN KEY (usuario_id) REFERENCES Usuarios(usuario_id) | ||
); | ||
|
||
-- Productos Table | ||
CREATE TABLE Productos ( | ||
producto_id INT AUTO_INCREMENT PRIMARY KEY, | ||
nombre VARCHAR(100) NOT NULL, | ||
descripcion TEXT, | ||
precio DECIMAL(10, 2) NOT NULL, | ||
categoria VARCHAR(100), | ||
imagen_url VARCHAR(255) | ||
); | ||
|
||
-- Compra_Productos Table | ||
CREATE TABLE Compra_Productos ( | ||
compra_producto_id INT AUTO_INCREMENT PRIMARY KEY, | ||
compra_id INT NOT NULL, | ||
producto_id INT NOT NULL, | ||
cantidad INT NOT NULL, | ||
FOREIGN KEY (compra_id) REFERENCES Compras(compra_id), | ||
FOREIGN KEY (producto_id) REFERENCES Productos(producto_id) | ||
); | ||
|
||
-- Carrito Table | ||
CREATE TABLE Carrito ( | ||
carrito_id INT AUTO_INCREMENT PRIMARY KEY, | ||
usuario_id INT NOT NULL, | ||
producto_id INT NOT NULL, | ||
cantidad INT NOT NULL, | ||
FOREIGN KEY (usuario_id) REFERENCES Usuarios(usuario_id), | ||
FOREIGN KEY (producto_id) REFERENCES Productos(producto_id) | ||
); | ||
|
||
-- Roles Table | ||
CREATE TABLE Roles ( | ||
rol_id INT AUTO_INCREMENT PRIMARY KEY, | ||
nombre VARCHAR(100) NOT NULL | ||
); | ||
|
||
-- Empleados Table | ||
CREATE TABLE Empleados ( | ||
empleado_id INT AUTO_INCREMENT PRIMARY KEY, | ||
nombre VARCHAR(100) NOT NULL, | ||
correo VARCHAR(100) UNIQUE NOT NULL, | ||
contrasena VARCHAR(100) NOT NULL, | ||
rol_id INT NOT NULL, | ||
FOREIGN KEY (rol_id) REFERENCES Roles(rol_id) | ||
); | ||
|
||
-- Add default roles | ||
INSERT INTO Roles (nombre) | ||
VALUES ('Carpintero'), ('Diseñador'), ('Admin'); | ||
|
||
-- Example to add a new employee | ||
INSERT INTO Empleados (nombre, correo, contrasena, rol_id) | ||
VALUES ('Carlos Martinez', '[email protected]', 'password123', 1); -- Assigning the role of Carpintero | ||
|
||
-- Query to retrieve employees and their roles | ||
SELECT e.nombre, r.nombre AS rol | ||
FROM Empleados e | ||
JOIN Roles r ON e.rol_id = r.rol_id; |
Empty file.