-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdb.txt
More file actions
69 lines (62 loc) · 1.67 KB
/
db.txt
File metadata and controls
69 lines (62 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
CREATE TABLE tipo_usuario (
id SERIAL PRIMARY KEY,
nombre VARCHAR(50) NOT NULL
);
CREATE TABLE usuarios (
id SERIAL PRIMARY KEY,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
picture TEXT,
nombre VARCHAR(100),
direccion TEXT,
tipo_usuario_id INT,
FOREIGN KEY (tipo_usuario_id) REFERENCES tipo_usuario(id)
);
CREATE TABLE categorias (
id SERIAL PRIMARY KEY,
nombre VARCHAR(100) NOT NULL
);
CREATE TABLE productos (
id SERIAL PRIMARY KEY,
titulo VARCHAR(100) NOT NULL,
descripcion TEXT,
precio DECIMAL(10,2) NOT NULL,
categoria_id INT,
size VARCHAR(10),
stock INT DEFAULT 0,
imagen TEXT,
vendedor_id INT,
FOREIGN KEY (categoria_id) REFERENCES categorias(id),
FOREIGN KEY (vendedor_id) REFERENCES usuarios(id)
);
CREATE TABLE carritos (
id SERIAL PRIMARY KEY,
usuario_id INT,
FOREIGN KEY (usuario_id) REFERENCES usuarios(id)
);
CREATE TABLE carrito_items (
id SERIAL PRIMARY KEY,
carrito_id INT,
producto_id INT,
cantidad INT NOT NULL,
FOREIGN KEY (carrito_id) REFERENCES carritos(id),
FOREIGN KEY (producto_id) REFERENCES productos(id)
);
CREATE TABLE pedidos (
id SERIAL PRIMARY KEY,
usuario_id INT,
total DECIMAL(10,2),
status VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (usuario_id) REFERENCES usuarios(id)
);
CREATE TABLE pedido_items (
id SERIAL PRIMARY KEY,
pedido_id INT,
producto_id INT,
cantidad INT NOT NULL,
precio_unitario DECIMAL(10,2),
size VARCHAR(10),
FOREIGN KEY (pedido_id) REFERENCES pedidos(id),
FOREIGN KEY (producto_id) REFERENCES productos(id)
);