-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.sql
142 lines (132 loc) · 3.79 KB
/
blog.sql
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
CREATE DATABASE blogPersonal DEFAULT CHARACTER SET utf8;
USE blogPersonal;
CREATE TABLE usuarios (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
nombre VARCHAR(25) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
foto TEXT CHARACTER SET utf8 NOT NULL,
fecha_registro DATETIME NOT NULL,
activo TINYINT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE entradas (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
autor_id INT NOT NULL,
titulo VARCHAR(255) NOT NULL,
texto TEXT CHARACTER SET utf8 NOT NULL,
fecha DATETIME NOT NULL,
activa TINYINT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(autor_id)
REFERENCES usuarios(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);
CREATE TABLE comentarios (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
autor_id INT NOT NULL,
entrada_id INT NOT NULL,
titulo VARCHAR(255) NOT NULL,
texto TEXT CHARACTER SET utf8 NOT NULL,
fecha DATETIME NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(autor_id)
REFERENCES usuarios(id)
ON UPDATE CASCADE
ON DELETE RESTRICT,
FOREIGN KEY(entrada_id)
REFERENCES entradas(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);
CREATE TABLE lenguajeProg (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
nombre VARCHAR(255) NOT NULL,
imagen TEXT CHARACTER SET utf8 NOT NULL,
color1 VARCHAR(255) NOT NULL,
color2 VARCHAR(255) NOT NULL,
activo TINYINT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE entradasProgs (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
autor_id INT NOT NULL,
lenguaje_id INT NOT NULL,
titulo VARCHAR(255) NOT NULL,
texto TEXT CHARACTER SET utf8 NOT NULL,
imagen TEXT CHARACTER SET utf8 NOT NULL,
fecha DATETIME NOT NULL,
activa TINYINT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(lenguaje_id)
REFERENCES lenguajeProg(id)
ON UPDATE CASCADE
ON DELETE RESTRICT,
FOREIGN KEY(autor_id)
REFERENCES usuarios(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);
CREATE TABLE comentariosProgs (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
autor_id INT NOT NULL,
entrada_progs_id INT NOT NULL,
titulo VARCHAR(255) NOT NULL,
texto TEXT CHARACTER SET utf8 NOT NULL,
fecha DATETIME NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(autor_id)
REFERENCES usuarios(id)
ON UPDATE CASCADE
ON DELETE RESTRICT,
FOREIGN KEY(entrada_progs_id)
REFERENCES entradasProgs(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);
CREATE TABLE ubicacion (
id INT NOT NULL AUTO_INCREMENT,
nombre VARCHAR(100) NOT NULL ,
direccion VARCHAR(80) NOT NULL,
lat FLOAT(10,6) NOT NULL,
lng FLOAT(10,6) NOT NULL,
tipo VARCHAR(30) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE entradasImg (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
autor_id INT NOT NULL,
titulo VARCHAR(255) NOT NULL,
texto TEXT CHARACTER SET utf8 NOT NULL,
imagen TEXT CHARACTER SET utf8 NOT NULL,
fecha DATETIME NOT NULL,
ubicacion INT NOT NULL,
activa TINYINT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(autor_id)
REFERENCES usuarios(id)
ON UPDATE CASCADE
ON DELETE RESTRICT,
FOREIGN KEY(ubicacion)
REFERENCES ubicacion(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);
CREATE TABLE comentariosImg (
id INT NOT NULL UNIQUE AUTO_INCREMENT,
autor_id INT NOT NULL,
entrada_img_id INT NOT NULL,
titulo VARCHAR(255) NOT NULL,
texto TEXT CHARACTER SET utf8 NOT NULL,
fecha DATETIME NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(autor_id)
REFERENCES usuarios(id)
ON UPDATE CASCADE
ON DELETE RESTRICT,
FOREIGN KEY(entrada_img_id)
REFERENCES entradasImg(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
);