-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor database schema to use more descriptive table and column names
- Loading branch information
1 parent
24d0eb6
commit 1816e2e
Showing
2 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,120 @@ | ||
CREATE TABLE accounts ( | ||
user_id SERIAL PRIMARY KEY, | ||
username VARCHAR (50) UNIQUE NOT NULL, | ||
password VARCHAR (50) NOT NULL, | ||
email VARCHAR (255) UNIQUE NOT NULL, | ||
created_at TIMESTAMP NOT NULL, | ||
last_login TIMESTAMP | ||
CREATE TABLE PESSOA ( | ||
ID SERIAL PRIMARY KEY, | ||
NOME VARCHAR (100) NOT NULL, | ||
EMAIL VARCHAR (100) NOT NULL, | ||
SENHA VARCHAR (50) NOT NULL, | ||
CELULAR VARCHAR (50) NOT NULL | ||
); | ||
|
||
CREATE TABLE PROFESSOR ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_PESSOA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_PESSOA) REFERENCES PESSOA(ID) | ||
); | ||
|
||
CREATE TABLE ALUNO ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_PESSOA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_PESSOA) REFERENCES PESSOA(ID) | ||
); | ||
|
||
CREATE TABLE RESPONSAVEL ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_PESSOA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_PESSOA) REFERENCES PESSOA(ID) | ||
); | ||
|
||
CREATE TABLE COORDENADOR ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_PESSOA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_PESSOA) REFERENCES PESSOA(ID) | ||
); | ||
|
||
CREATE TABLE ESCOLA ( | ||
ID SERIAL PRIMARY KEY, | ||
NOME VARCHAR (100) NOT NULL, | ||
ID_COORDENADOR INTEGER NOT NULL, | ||
FOREIGN KEY (ID_COORDENADOR) REFERENCES COORDENADOR(ID) | ||
); | ||
|
||
CREATE TABLE TURMA ( | ||
ID SERIAL PRIMARY KEY, | ||
NOME VARCHAR (100) NOT NULL, | ||
ID_ESCOLA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_ESCOLA) REFERENCES ESCOLA(ID) | ||
); | ||
|
||
CREATE TABLE DISCIPLINA ( | ||
ID SERIAL PRIMARY KEY, | ||
NOME VARCHAR (100) NOT NULL, | ||
ID_ESCOLA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_ESCOLA) REFERENCES ESCOLA(ID) | ||
); | ||
|
||
CREATE TABLE TURMA_DISCIPLINA ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_TURMA INTEGER NOT NULL, | ||
ID_DISCIPLINA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_TURMA) REFERENCES TURMA(ID), | ||
FOREIGN KEY (ID_DISCIPLINA) REFERENCES DISCIPLINA(ID) | ||
); | ||
|
||
CREATE TABLE TURMA_ALUNO ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_TURMA INTEGER NOT NULL, | ||
ID_ALUNO INTEGER NOT NULL, | ||
FOREIGN KEY (ID_TURMA) REFERENCES TURMA(ID), | ||
FOREIGN KEY (ID_ALUNO) REFERENCES ALUNO(ID) | ||
); | ||
|
||
CREATE TABLE DISCIPLINA_PROFESSOR ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_DISCIPLINA INTEGER NOT NULL, | ||
ID_PROFESSOR INTEGER NOT NULL, | ||
FOREIGN KEY (ID_DISCIPLINA) REFERENCES DISCIPLINA(ID), | ||
FOREIGN KEY (ID_PROFESSOR) REFERENCES PROFESSOR(ID) | ||
); | ||
|
||
CREATE TABLE RESPONSAVEL_ALUNO ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_RESPONSAVEL INTEGER NOT NULL, | ||
ID_ALUNO INTEGER NOT NULL, | ||
FOREIGN KEY (ID_RESPONSAVEL) REFERENCES RESPONSAVEL(ID), | ||
FOREIGN KEY (ID_ALUNO) REFERENCES ALUNO(ID) | ||
); | ||
|
||
CREATE TABLE OCORRENCIA ( | ||
ID SERIAL PRIMARY KEY, | ||
DESCRICAO VARCHAR (100) NOT NULL, | ||
DATA DATE NOT NULL, | ||
ID_ALUNO INTEGER NOT NULL, | ||
ID_PROFESSOR INTEGER NOT NULL, | ||
ID_TIPO_OCORRENCIA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_ALUNO) REFERENCES ALUNO(ID), | ||
FOREIGN KEY (ID_PROFESSOR) REFERENCES PROFESSOR(ID), | ||
FOREIGN KEY (ID_TIPO_OCORRENCIA) REFERENCES TIPO_OCORRENCIA(ID) | ||
); | ||
|
||
CREATE TABLE TIPO_OCORRENCIA ( | ||
ID SERIAL PRIMARY KEY, | ||
NOME VARCHAR (100) NOT NULL | ||
); | ||
|
||
CREATE TABLE NOTIFICACAO ( | ||
ID SERIAL PRIMARY KEY, | ||
MENSAGEM VARCHAR (255) NOT NULL, | ||
DATA DATE NOT NULL, | ||
ID_ALUNO INTEGER NOT NULL, | ||
ID_RESPONSAVEL INTEGER NOT NULL, | ||
ENVIADA BOOLEAN NOT NULL, | ||
FOREIGN KEY (ID_ALUNO) REFERENCES ALUNO(ID), | ||
FOREIGN KEY (ID_RESPONSAVEL) REFERENCES RESPONSAVEL(ID) | ||
); | ||
|
||
CREATE TABLE NOTIFICACAO_OCORRENCIA ( | ||
ID SERIAL PRIMARY KEY, | ||
ID_NOTIFICACAO INTEGER NOT NULL, | ||
ID_OCORRENCIA INTEGER NOT NULL, | ||
FOREIGN KEY (ID_NOTIFICACAO) REFERENCES NOTIFICACAO(ID), | ||
FOREIGN KEY (ID_OCORRENCIA) REFERENCES OCORRENCIA(ID) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
INSERT INTO accounts (username, password, email, created_at) VALUES ('johndoe', 'password', '[email protected]', NOW()); | ||