-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCubeX_Database.sql
500 lines (441 loc) · 20.4 KB
/
CubeX_Database.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*REALIZADO POR : ESTELA DE VEGA MARTIN 1ºDAM*/
/**************DISENIO FISICO CUBE_X***********/
DROP DATABASE IF EXISTS CubeX_DB;
CREATE DATABASE CubeX_DB;
USE CubeX_DB;
/*TABLAS*/
/*TABLA CON TODOS LOS USUARIOS, SEAN SOCIOS O NO*/
DROP TABLE IF EXISTS CUBE_USERS;
CREATE TABLE CUBE_USERS (
ID_USER INT AUTO_INCREMENT PRIMARY KEY,
NAME_USER VARCHAR(45) UNIQUE NOT NULL,
PASSWORD_USER VARCHAR(15) NOT NULL,
/*EL USUARIO AL ENTRAR TENDRA UN NIVEL 0, CUANDO HAYA REALIZADO TIEMPOS SE IRA INCREMENTANDO.
POR CADA TIEMPO SE LE SUMARA 25 EXP, CUANDO LLEGUE A 100 SE LE SUMARA UN NIVEL*/
LEVEL_USER INT DEFAULT 0 NOT NULL,
ROLE_USER VARCHAR(6) NOT NULL CHECK (ROLE_USER IN ('MEMBER', 'USER')) DEFAULT 'USER',
MAIL VARCHAR(100) NOT NULL,
REGISTRATION_DATE DATE NOT NULL,
URL_IMAGEN VARCHAR(100)
);
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('a', 'Ps.contains(8)', 'a@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('b', 'Ps.contains(8)', 'b@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('n', 'Ps.contains(8)', 'n@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('m', 'Ps.contains(8)', 'm@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('j', 'Ps.contains(8)', 'j@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('k', 'Ps.contains(8)', 'k@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('l', 'Ps.contains(8)', 'l@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('s', 'Ps.contains(8)', 's@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('p', 'Ps.contains(8)', 'p@gmail.com', current_date() );
insert into cube_users (NAME_USER, PASSWORD_USER, MAIL, REGISTRATION_DATE)
VALUES ('o', 'Ps.contains(8)', 'o@gmail.com', current_date() );
INSERT INTO CUBE_USERS (NAME_USER, PASSWORD_USER, MAIL, ROLE_USER, REGISTRATION_DATE)
VALUES ('admin', 'Admin(9)', 'admin@admin.com', 'MEMBER', '2024-04-25'); -- USUARIO POR DEFECTO
/*TABLA CON LA INFORMACION DE LOS SOCIOS*/
DROP TABLE IF EXISTS MEMBERS;
CREATE TABLE MEMBERS (
ID_MEMBER INT AUTO_INCREMENT PRIMARY KEY,
ID_USER INT NOT NULL,
/*SE INCREMENTARA 10 MODENAS CADA 6 MESES QUE SEA MIEMBRO*/
DISCOUNT INT DEFAULT 0 NOT NULL,
REGISTRATION_DATE DATE NOT NULL,
CONSTRAINT fk_member FOREIGN KEY (ID_USER) REFERENCES CUBE_USERS(ID_USER)
ON DELETE CASCADE
);
INSERT INTO MEMBERS (ID_USER, REGISTRATION_DATE)
VALUES ((SELECT ID_USER FROM CUBE_USERS WHERE NAME_USER LIKE 'admin'), '2024-04-25'); -- USUARIO POR DEFECTO
/*TABLA CON LOS TIPOS DE CUBOS*/
DROP TABLE IF EXISTS CUBE_TYPE;
CREATE TABLE CUBE_TYPE (
ID_TYPE INT AUTO_INCREMENT PRIMARY KEY,
NAME_TYPE VARCHAR(55) UNIQUE NOT NULL
);
INSERT INTO CUBE_TYPE VALUES (1,'2x2x2');
INSERT INTO CUBE_TYPE VALUES (2,'3x3x3');
INSERT INTO CUBE_TYPE VALUES (3,'4x4x4');
INSERT INTO CUBE_TYPE VALUES (4,'5x5x5');
INSERT INTO CUBE_TYPE VALUES (5,'6x6x6');
INSERT INTO CUBE_TYPE VALUES (6,'7x7x7');
INSERT INTO CUBE_TYPE VALUES (7,'PYRAMINX');
INSERT INTO CUBE_TYPE VALUES (8,'MEGAMINX');
INSERT INTO CUBE_TYPE VALUES (9,'SKEWB');
INSERT INTO CUBE_TYPE VALUES (10,'SQUARE-1');
INSERT INTO CUBE_TYPE VALUES (11,'CLOCK');
INSERT INTO CUBE_TYPE VALUES (12,'3x3x3 MIRROR');
INSERT INTO CUBE_TYPE VALUES (13,'5x5x5 BLIND');
INSERT INTO CUBE_TYPE VALUES (14,'3x3x3 ONE-HANDED');
INSERT INTO CUBE_TYPE VALUES (15,'3x3x3 BLIND');
INSERT INTO CUBE_TYPE VALUES (16,'3x3x3 MULTIBLIND');
INSERT INTO CUBE_TYPE VALUES (17,'4x4x4 BLIND');
INSERT INTO CUBE_TYPE VALUES (18,'PYRAMORPHIX');
INSERT INTO CUBE_TYPE VALUES (19,'MASTERMORPHIX');
INSERT INTO CUBE_TYPE VALUES (20,'3x3x3 FEWEST MOVES CHALLENGE');
COMMIT;
/*TABLA CON LOS METODOS DE CUBOS*/
DROP TABLE IF EXISTS METHOD_CUBE;
CREATE TABLE METHOD_CUBE (
ID_METHOD INT AUTO_INCREMENT PRIMARY KEY,
NAME_METHOD VARCHAR(55) UNIQUE NOT NULL
);
INSERT INTO METHOD_CUBE VALUES (1,'ORTEGA METHOD');
INSERT INTO METHOD_CUBE VALUES (2,'CORNERS LAST LAYER');
INSERT INTO METHOD_CUBE VALUES (3,'BEGINNER�S METHOD');
INSERT INTO METHOD_CUBE VALUES (4,'REDUCED FRIDRICH METHOD');
INSERT INTO METHOD_CUBE VALUES (5,'FRIDRICH METHOD');
INSERT INTO METHOD_CUBE VALUES (6,'ROUX METHOD');
INSERT INTO METHOD_CUBE VALUES (7,'ZBOROWSKI-ZOLTE METHOD');
INSERT INTO METHOD_CUBE VALUES (8,'PETRUS METHOD');
INSERT INTO METHOD_CUBE VALUES (9,'WALTERMAN METHOD');
INSERT INTO METHOD_CUBE VALUES (10,'HEISE METHOD');
INSERT INTO METHOD_CUBE VALUES (11,'HOYA METHOD');
INSERT INTO METHOD_CUBE VALUES (12,'ZBOROWSKI-BRUCHEM LAST LAYER METHOD');
INSERT INTO METHOD_CUBE VALUES (13,'YAU METHOD');
INSERT INTO METHOD_CUBE VALUES (14,'INTUITIVE METHOD');
INSERT INTO METHOD_CUBE VALUES (15,'REDUX METHOD');
INSERT INTO METHOD_CUBE VALUES (16,'REDUCTION METHOD');
INSERT INTO METHOD_CUBE VALUES (17,'KEYHOLE METHOD');
INSERT INTO METHOD_CUBE VALUES (18,'LAYER-BY-LAYER METHOD');
INSERT INTO METHOD_CUBE VALUES (19,'RIDO METHOD');
INSERT INTO METHOD_CUBE VALUES (20,'EDGE PERMUTATION METHOD');
INSERT INTO METHOD_CUBE VALUES (21,'VANDENBERGH METHOD');
INSERT INTO METHOD_CUBE VALUES (22,'SHAPE-SHIFTING METHOD');
INSERT INTO METHOD_CUBE VALUES (23,'TOP-DOWN METHOD');
INSERT INTO METHOD_CUBE VALUES (24,'PATTERN METHOD');
INSERT INTO METHOD_CUBE VALUES (25,'OLD POCHMANN METHOD');
INSERT INTO METHOD_CUBE VALUES (26,'M2 METHOD');
INSERT INTO METHOD_CUBE VALUES (27,'CORNERS-FIRST METHOD');
INSERT INTO METHOD_CUBE VALUES (28,'GROUPING TECHNIQUE');
INSERT INTO METHOD_CUBE VALUES (29,'DIVIDE AND CONQUER APPROACH METHOD');
INSERT INTO METHOD_CUBE VALUES (30,'STARTING POSITION STRATEGY METHOD');
INSERT INTO METHOD_CUBE VALUES (31,'ADVANCED METHOD');
INSERT INTO METHOD_CUBE VALUES (32,'ADVANCED REDUCTION METHOD');
INSERT INTO METHOD_CUBE VALUES (33,'CENTERS SOLVING METHOD');
INSERT INTO METHOD_CUBE VALUES (34,'EDGE PAIRING TECHNIQUES');
INSERT INTO METHOD_CUBE VALUES (35,'BACKTRACKING TECHNIQUES');
INSERT INTO METHOD_CUBE VALUES (36,'EXHAUSTIVE SEARCH TECHNIQUES');
INSERT INTO METHOD_CUBE VALUES (37,'ALGORYTHM OPTIMIZATION TECHNIQUES');
INSERT INTO METHOD_CUBE VALUES (38,'MOVE ANALYSIS TECHNIQUES');
INSERT INTO METHOD_CUBE VALUES (39,'OTHER');
COMMIT;
/*TABLA CON LOS DIFERENTES METODOS DE LOS TIPOS DE CUBOS*/
DROP TABLE IF EXISTS TYPE_METHOD_TIENE;
CREATE TABLE TYPE_METHOD_TIENE(
ID_TYPE INT NOT NULL,
ID_METHOD INT NOT NULL,
CONSTRAINT pk_tiene_MeTy PRIMARY KEY (ID_TYPE, ID_METHOD),
CONSTRAINT fk_type_tiene FOREIGN KEY (ID_TYPE) REFERENCES CUBE_TYPE(ID_TYPE),
CONSTRAINT fk_method_tiene FOREIGN KEY (ID_METHOD) REFERENCES METHOD_CUBE(ID_METHOD)
);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 1);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 2);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (1, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 6);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 7);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 9);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 10);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 11);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 12);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 15);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 17);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (2, 20);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 6);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 10);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 19);
INSERT INTO TYPE_METHOD_TIENE VALUES (3, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 6);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 10);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 21);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 22);
INSERT INTO TYPE_METHOD_TIENE VALUES (4, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (5, 23);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (6, 23);
INSERT INTO TYPE_METHOD_TIENE VALUES (7, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (7, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (7, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 22);
INSERT INTO TYPE_METHOD_TIENE VALUES (8, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (9, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (9, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (9, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (9, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (9, 31);
INSERT INTO TYPE_METHOD_TIENE VALUES (10, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (10, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (10, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (10, 22);
INSERT INTO TYPE_METHOD_TIENE VALUES (10, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (10, 31);
INSERT INTO TYPE_METHOD_TIENE VALUES (11, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (11, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (11, 28);
INSERT INTO TYPE_METHOD_TIENE VALUES (11, 29);
INSERT INTO TYPE_METHOD_TIENE VALUES (11, 30);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 6);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 7);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 9);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 10);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 11);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 12);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 15);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 17);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (12, 20);
INSERT INTO TYPE_METHOD_TIENE VALUES (13, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (13, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (13, 15);
INSERT INTO TYPE_METHOD_TIENE VALUES (13, 32);
INSERT INTO TYPE_METHOD_TIENE VALUES (13, 33);
INSERT INTO TYPE_METHOD_TIENE VALUES (13, 34);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 6);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 7);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 9);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 10);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 11);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 12);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 15);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 17);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (14, 20);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 3);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 4);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 5);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 6);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 7);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 8);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 9);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 10);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 11);
INSERT INTO TYPE_METHOD_TIENE VALUES (15, 12);
INSERT INTO TYPE_METHOD_TIENE VALUES (16, 15);
INSERT INTO TYPE_METHOD_TIENE VALUES (16, 23);
INSERT INTO TYPE_METHOD_TIENE VALUES (16, 25);
INSERT INTO TYPE_METHOD_TIENE VALUES (16, 26);
INSERT INTO TYPE_METHOD_TIENE VALUES (17, 13);
INSERT INTO TYPE_METHOD_TIENE VALUES (17, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (17, 15);
INSERT INTO TYPE_METHOD_TIENE VALUES (17, 32);
INSERT INTO TYPE_METHOD_TIENE VALUES (17, 33);
INSERT INTO TYPE_METHOD_TIENE VALUES (17, 34);
INSERT INTO TYPE_METHOD_TIENE VALUES (18, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (18, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (18, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (19, 14);
INSERT INTO TYPE_METHOD_TIENE VALUES (19, 16);
INSERT INTO TYPE_METHOD_TIENE VALUES (19, 18);
INSERT INTO TYPE_METHOD_TIENE VALUES (19, 24);
INSERT INTO TYPE_METHOD_TIENE VALUES (19, 28);
INSERT INTO TYPE_METHOD_TIENE VALUES (20, 28);
INSERT INTO TYPE_METHOD_TIENE VALUES (20, 34);
INSERT INTO TYPE_METHOD_TIENE VALUES (20, 36);
INSERT INTO TYPE_METHOD_TIENE VALUES (20, 37);
INSERT INTO TYPE_METHOD_TIENE VALUES (20, 38);
COMMIT;
/*TABLA PARA LAS SESIONES DEL USUARIO*/
DROP TABLE IF EXISTS SESSIONS;
CREATE TABLE SESSIONS (
ID_SESSION INT AUTO_INCREMENT PRIMARY KEY,
ID_USER INT NOT NULL, -- EL USUARIO QUE HA CREADO ESA SESION
NAME_SESSION VARCHAR(45) NOT NULL,
CREATION_DATE DATE NOT NULL,
ID_TYPE INT NOT NULL,
CONSTRAINT fk_user_session FOREIGN KEY (ID_USER) REFERENCES CUBE_USERS(ID_USER),
CONSTRAINT fk_type_session FOREIGN KEY (ID_TYPE) REFERENCES CUBE_TYPE(ID_TYPE),
-- ESTABLEZCO EL NOMBRE DE LA SESSION SIN EL UNIQUE PARA QUE OTRO USUARIO
-- PUEDA TENER EL MISMO NOMBRE DE LA SESION QUE OTRO, PERO QUE UN USUARIO
-- NO PUEDA TENER UNA SESSION CON EL MISMO NOMBRE
CONSTRAINT UNIQUE_SESSION_NAME UNIQUE (NAME_SESSION, ID_USER)
);
/*TABLA PARA GUARDAR LAS MEDIAS, MEJORES Y PEORES TIEMPOS DE LOS USUARIOS*/
DROP TABLE IF EXISTS AVERAGE;
CREATE TABLE AVERAGE (
ID_AVERAGE INT AUTO_INCREMENT PRIMARY KEY,
AVG_MINUTES INT,
AVG_SECONDS DECIMAL(5, 3),
PERIOD_AVG INT,
PB_MINUTES INT,
PB_SECONDS DECIMAL(5, 3),
WORST_MINUTES INT,
WORST_SECONDS DECIMAL(5, 3),
ID_SESSION INT,
ID_COMPE INT,
ID_CHAMP INT,
CONSTRAINT fk_session_average FOREIGN KEY (ID_SESSION) REFERENCES SESSIONS(ID_SESSION),
CONSTRAINT fk_compe_average FOREIGN KEY (ID_COMPE) REFERENCES COMPETITION(ID_COMPE),
CONSTRAINT fk_champ_average FOREIGN KEY (ID_CHAMP) REFERENCES CHAMPIONSHIP(ID_CHAMP)
);
/*TABLA PARA LOS CAMPEONATOS DE CUBOS. LOS CAMPEONATOS SON GRATIS Y ABIERTO A TODOS
LOS USUARIOS, PERO HAY CAMPEONATOS EXCLUSIVOS CREADOS POR SOCIOS PARA SOCIOS DONDE
PUEDEN PONER UN PRECIO PARA QUE SE UNEN LOS SOCIOS*/
DROP TABLE IF EXISTS CHAMPIONSHIP;
CREATE TABLE CHAMPIONSHIP (
ID_CHAMP INT AUTO_INCREMENT PRIMARY KEY,
ID_USER INT NOT NULL, -- USUARIO QUE HA CREADO LA COMPETENCIA
NAME_CHAMP VARCHAR(45) UNIQUE NOT NULL,
PRICE INT DEFAULT 0 NOT NULL, -- EL PRECIO SOLO SE MODIFICARA SI ES SOCIO
NUMBER_PART INT NOT NULL CHECK (NUMBER_PART >= 2),
DESCRIPTION_CHAMP VARCHAR(255) NOT NULL,
REGISTRATION_DATE DATE NOT NULL, -- HE PUESTO LA FECHA EN EL CAMPEONATO
/*SOLO LOS MIEMBROS PUEDAN CREAR COMPETICIONES EXCLUSIVAS PARA MIEMBROS CON PRECIOS*/
MEMBERS_ONLY BOOLEAN DEFAULT 0 NOT NULL,
CONSTRAINT fk_user_champ FOREIGN KEY (ID_USER) REFERENCES CUBE_USERS(ID_USER)
);
/*TABLA DE LAS CATEGORIAS DE LAS COMPETICIONES CON SU GANADOR*/
DROP TABLE IF EXISTS CUBE_CHAMP_PERTENECE;
CREATE TABLE CUBE_CHAMP_PERTENECE(
ID_TYPE INT NOT NULL,
ID_CHAMP INT NOT NULL,
WINNER VARCHAR(45),
CONSTRAINT pk_CubChaPertenece PRIMARY KEY (ID_TYPE, ID_CHAMP),
CONSTRAINT fk_type_pertenece FOREIGN KEY (ID_TYPE) REFERENCES CUBE_TYPE(ID_TYPE),
CONSTRAINT fk_champ_pertenece FOREIGN KEY (ID_CHAMP) REFERENCES CHAMPIONSHIP(ID_CHAMP)
);
/*TABLA DE USUARIOS QUE PARTICIPAN EN EL CAMPEONATO*/
DROP TABLE IF EXISTS USER_CHAMP_COMPETE;
CREATE TABLE USER_CHAMP_COMPETE(
ID_USER INT NOT NULL,
ID_CHAMP INT NOT NULL,
CONSTRAINT pk_compete PRIMARY KEY (ID_USER, ID_CHAMP),
CONSTRAINT fk_user_compete FOREIGN KEY (ID_USER) REFERENCES CUBE_USERS(ID_USER),
CONSTRAINT fk_champ_compete FOREIGN KEY (ID_CHAMP) REFERENCES CHAMPIONSHIP(ID_CHAMP)
);
/*TABAL PARA LAS COMPETICIONES ENTRE UN USUARIOS Y OTRA PERSONA, COMO UN DUELO.*/
DROP TABLE IF EXISTS COMPETITION;
CREATE TABLE COMPETITION(
ID_COMPE INT AUTO_INCREMENT PRIMARY KEY,
ID_USER INT NOT NULL, -- EL ID_USER QUE HA CREADO LA COMPETICION
CUBER1 VARCHAR(45) NOT NULL, -- EL MISMO NOMBRE QUE TIENE EL USUARIO CON EL ID QUE HA CREADO LA COMPETITION
CUBER2 VARCHAR(45) NOT NULL,
WINNER VARCHAR(45),
REGISTRATION_DATE DATE NOT NULL, -- HE PUESTO LA FECHA EN COMPETITION
CONSTRAINT ch_NoEqualName CHECK (CUBER1 NOT LIKE CUBER2),
CONSTRAINT fk_user_compe FOREIGN KEY (ID_USER) REFERENCES CUBE_USERS(ID_USER)
);
-- TIMES
/*TABLA PARA GUARDAR LOS TIEMPOS DE LAS SESIONES*/
DROP TABLE IF EXISTS TIMES_TRAINING;
CREATE TABLE TIMES_TRAINING(
ID_TIMES_TRAINING INT AUTO_INCREMENT PRIMARY KEY,
DESCRIPTION_SCRAMBLE VARCHAR(455) UNIQUE NOT NULL,
MINUTES1 INT NOT NULL,
SECONDS1 DECIMAL(5, 3) NOT NULL,
COMMENTS1 VARCHAR(255),
REGISTRATION_DATE DATE NOT NULL,
ID_SESSION INT,
CONSTRAINT fk_session_times FOREIGN KEY (ID_SESSION) REFERENCES SESSIONS(ID_SESSION)
);
USE CUBEX_DB;
SELECT MINUTES1, SECONDS1 FROM TIMES_TRAINING WHERE ID_SESSION = 10;
SELECT ID_SESSION FROM SESSIONS WHERE NAME_SESSION = 'general';
/*TABLA PARA GUARDAR LOS TIEMPOS DE LAS COMPETICIONES*/
DROP TABLE IF EXISTS TIMES_COMPETITION;
CREATE TABLE TIMES_COMPETITION(
ID_TIMES_COMPE INT AUTO_INCREMENT PRIMARY KEY,
DESCRIPTION_SCRAMBLE VARCHAR(455) UNIQUE NOT NULL,
MINUTES1 INT NOT NULL,
SECONDS1 DECIMAL(5, 3) NOT NULL,
MINUTES2 INT NOT NULL,
SECONDS2 DECIMAL(5, 3) NOT NULL,
COMMENTS1 VARCHAR(255),
COMMENTS2 VARCHAR(255),
ID_COMPE INT,
ID_TYPE INT NOT NULL,
CONSTRAINT fk_type_time FOREIGN KEY (ID_TYPE) REFERENCES CUBE_TYPE(ID_TYPE),
CONSTRAINT fk_compe_times FOREIGN KEY (ID_COMPE) REFERENCES COMPETITION(ID_COMPE)
);
/*TABLA PARA GUARDAR LOS TIEMPOS DE LOS COMPEONATOS*/
DROP TABLE IF EXISTS TIMES_CHAMPSIONSHIP;
CREATE TABLE TIMES_CHAMPSIONSHIP(
ID_TIMES_VERSUS INT AUTO_INCREMENT PRIMARY KEY,
ID_USER INT NOT NULL,
DESCRIPTION_SCRAMBLE VARCHAR(455) UNIQUE NOT NULL,
MINUTES1 INT NOT NULL,
SECONDS1 DECIMAL(5, 3) NOT NULL,
COMMENTS1 VARCHAR(255),
ID_CHAMP INT,
ID_TYPE INT NOT NULL,
CONSTRAINT fk_typeTimes FOREIGN KEY (ID_TYPE) REFERENCES CUBE_TYPE(ID_TYPE),
CONSTRAINT fk_champ_user FOREIGN KEY (ID_USER) REFERENCES CUBE_USERS(ID_USER),
CONSTRAINT fk_champ_times FOREIGN KEY (ID_CHAMP) REFERENCES CHAMPIONSHIP(ID_CHAMP)
);
/*TABLA PARA GUARDAR LAS MEDIAS, MEJORES Y PEORES TIEMPOS DE LOS USUARIOS*/
DROP TABLE IF EXISTS AVERAGE;
CREATE TABLE AVERAGE (
ID_AVERAGE INT AUTO_INCREMENT PRIMARY KEY,
AVG_MINUTES INT,
AVG_SECONDS DECIMAL(5, 3),
PERIOD_AVG INT,
PB_MINUTES INT,
PB_SECONDS DECIMAL(5, 3),
WORST_MINUTES INT,
WORST_SECONDS DECIMAL(5, 3),
ID_SESSION INT,
ID_COMPE INT,
ID_CHAMP INT,
CONSTRAINT fk_session_average FOREIGN KEY (ID_SESSION) REFERENCES SESSIONS(ID_SESSION),
CONSTRAINT fk_compe_average FOREIGN KEY (ID_COMPE) REFERENCES COMPETITION(ID_COMPE),
CONSTRAINT fk_champ_average FOREIGN KEY (ID_CHAMP) REFERENCES CHAMPIONSHIP(ID_CHAMP)
);