diff --git a/database/00_schema.sql b/database/00_schema.sql index f803dab..9376c26 100644 --- a/database/00_schema.sql +++ b/database/00_schema.sql @@ -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) ); \ No newline at end of file diff --git a/database/01_seed.sql b/database/01_seed.sql index a2a16d5..e69de29 100644 --- a/database/01_seed.sql +++ b/database/01_seed.sql @@ -1 +0,0 @@ -INSERT INTO accounts (username, password, email, created_at) VALUES ('johndoe', 'password', 'test@email.com', NOW()); \ No newline at end of file