-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.sql
138 lines (117 loc) · 2.8 KB
/
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
--
-- AuthDB
--
--
-- Criando database AuthDB
--
CREATE DATABASE authdb;
--
-- Selecionando database AuthDB
--
USE authdb;
--
-- Criando a tabela usuários
--
CREATE TABLE users (
code INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
cpf VARCHAR(255) NOT NULL UNIQUE,
phone VARCHAR(255),
isStudent INTEGER NOT NULL,
studentType VARCHAR(255) NOT NULL,
isPaid INTEGER NOT NULL
);
--
-- Atribuindo valores padrões para os campos da table users
--
ALTER TABLE users MODIFY COLUMN isStudent INTEGER DEFAULT 0;
ALTER TABLE users MODIFY COLUMN studentType INTEGER DEFAULT "nd";
ALTER TABLE users MODIFY COLUMN isPaid INTEGER DEFAULT 0;
--
-- Criando a tabela Empresas
--
CREATE TABLE bussiness (
code INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
cnpj VARCHAR(255) NOT NULL UNIQUE,
phone VARCHAR(255),
isPaid INTEGER NOT NULL
);
--
-- Atribuindo valores padrões para os campos da table users
--
ALTER TABLE bussiness MODIFY COLUMN isPaid INTEGER DEFAULT 0;
--
-- Criando a tabela Módulos
--
CREATE TABLE modules(
code INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255)
);
--
-- Inserindo módulos iniciais a tabela modules
--
INSERT INTO modules (name) values ("Associação");
INSERT INTO modules (name) values ("Administrador");
--
-- Criando a tabela Acesso
--
CREATE TABLE access(
user INTEGER,
bussiness INTEGER,
module INTEGER,
FOREIGN KEY (user) REFERENCES users(code),
FOREIGN KEY (bussiness) REFERENCES bussiness(code),
FOREIGN KEY (module) REFERENCES modules(code)
);
--
-- Criando a tabela Declaração de Estudante
--
CREATE TABLE studentStatement(
code INTEGER AUTO_INCREMENT PRIMARY KEY,
path VARCHAR(255),
user INTEGER,
createdAt VARCHAR(255),
status VARCHAR(255),
FOREIGN KEY(user) REFERENCES users(code)
);
--
-- Criando a tabela de boletos
--
CREATE TABLE bankingBillets (
code INTEGER AUTO_INCREMENT PRIMARY KEY,
charge_id VARCHAR(255) NOT NULL UNIQUE,
cpf VARCHAR(255),
cnpj VARCHAR(255),
expire_at VARCHAR(255) NOT NULL,
created_at VARCHAR(255) NOT NULL,
value double NOT NULL
);
--
-- Criando a tabela de boletos
--
CREATE TABLE comprovante_pessoa(
code INTEGER AUTO_INCREMENT PRIMARY KEY,
user INTEGER NOT NULL,
status VARCHAR(255) NOT NULL,
year VARCHAR(255) NOT NULL,
charge_id VARCHAR(255) NOT NULL,
path VARCHAR(255) NOT NULL,
FOREIGN KEY (user) REFERENCES users(code)
);
--
-- Criando a tabela de boletos
--
CREATE TABLE comprovante_pessoa(
code INTEGER AUTO_INCREMENT PRIMARY KEY,
bussiness INTEGER NOT NULL,
status VARCHAR(255) NOT NULL,
year VARCHAR(255) NOT NULL,
charge_id VARCHAR(255) NOT NULL,
path VARCHAR(255) NOT NULL,
FOREIGN KEY (bussiness) REFERENCES bussiness(code)
);