-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDDL.sql
More file actions
79 lines (68 loc) · 2.33 KB
/
DDL.sql
File metadata and controls
79 lines (68 loc) · 2.33 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
70
71
72
73
74
75
76
77
78
79
create database projeto_ia;
use projeto_ia;
CREATE TABLE `papel` (
`id` bigint NOT NULL AUTO_INCREMENT,
`nome` varchar(70) NOT NULL,
`descricao` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `usuario` (
`id` bigint NOT NULL AUTO_INCREMENT,
`nome` varchar(100) DEFAULT NULL,
`email` varchar(100) NOT NULL,
`password` text NOT NULL,
`id_papel` bigint DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_papel_em_usuario_idx` (`id_papel`),
CONSTRAINT `id_papel_em_usuario` FOREIGN KEY (`id_papel`) REFERENCES `papel` (`id`)
);
CREATE TABLE `area` (
`id` bigint NOT NULL AUTO_INCREMENT,
`nome` varchar(100) DEFAULT NULL,
`descricao` varchar(1000) DEFAULT NULL,
`status` tinyint DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `redzone` (
`id` bigint NOT NULL AUTO_INCREMENT,
`nome` varchar(45) NOT NULL,
`descricao` varchar(1000) DEFAULT NULL,
`data_cadastro` datetime DEFAULT NULL,
`id_area` bigint DEFAULT NULL,
`status` tinyint NOT NULL,
PRIMARY KEY (`id`),
KEY `id_area_in_redzone_fk_idx` (`id_area`),
CONSTRAINT `id_area_in_redzone_fk` FOREIGN KEY (`id_area`) REFERENCES `area` (`id`)
);
CREATE TABLE `entrada_redzone` (
`id` bigint NOT NULL AUTO_INCREMENT,
`data` datetime DEFAULT NULL,
`id_redzone` bigint DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_redzone_entrada_idx` (`id_redzone`),
CONSTRAINT `id_redzone_entrada` FOREIGN KEY (`id_redzone`) REFERENCES `redzone` (`id`)
);
CREATE TABLE `saida_redzone` (
`id` bigint NOT NULL AUTO_INCREMENT,
`data` datetime DEFAULT NULL,
`id_redzone` bigint DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `id_redzone_saida_idx` (`id_redzone`),
CONSTRAINT `id_redzone_saida` FOREIGN KEY (`id_redzone`) REFERENCES `redzone` (`id`)
);
create table usuario_area(
id_usuario bigint not null,
id_area bigint not null,
primary key(id_usuario, id_area));
create table usuario_redzone(
id_usuario bigint not null,
id_redzone bigint not null,
primary key(id_usuario, id_redzone));
create table usuario_password_token(
id bigint not null auto_increment primary key,
id_usuario bigint not null,
token varchar(50) not null,
datahora_expiracao datetime not null,
foreign key(id_usuario) references usuario(id));
insert into usuario(nome, email, password, id_papel) values
('Administrador', 'admin@admin.com', '$2a$10$hGOrv4ya8KeuA3Vc4FUkKuMHM2FangSnjuJhYCizxKwHtWqIpb7iO', 1);