Skip to content

Commit

Permalink
Refactor database schema to use more descriptive table and column names
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciobellon committed Apr 12, 2024
1 parent 24d0eb6 commit 1816e2e
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 8 deletions.
126 changes: 119 additions & 7 deletions database/00_schema.sql
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)
);
1 change: 0 additions & 1 deletion database/01_seed.sql
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());

0 comments on commit 1816e2e

Please sign in to comment.