Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
Warnings:

- The values [DISCENTE] on the enum `Role` will be removed. If these variants are still used in the database, this will fail.
- You are about to drop the column `cursoId` on the `Disciplina` table. All the data in the column will be lost.
- You are about to drop the column `discenteId` on the `Disciplina` table. All the data in the column will be lost.
- You are about to drop the column `docenteId` on the `Disciplina` table. All the data in the column will be lost.
- You are about to drop the column `status` on the `Disciplina` table. All the data in the column will be lost.
- You are about to drop the `Curso` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Discente` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `DisciplinaEmCurso` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Docente` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `HistoricoAlunoDisciplina` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `LivroEmprestadoBiblioteca` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `codigo` to the `Disciplina` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "SituacaoDisciplina" AS ENUM ('APROVADO', 'EM_PROGRESSO', 'TRANCADA', 'REPROVADO', 'DISPENSA', 'REPROVADO_POR_FALTA');

-- AlterEnum
BEGIN;
CREATE TYPE "Role_new" AS ENUM ('ADMIN', 'ALUNO', 'DOCENTE');
ALTER TABLE "User" ALTER COLUMN "role" DROP DEFAULT;
ALTER TABLE "User" ALTER COLUMN "role" TYPE "Role_new" USING ("role"::text::"Role_new");
ALTER TYPE "Role" RENAME TO "Role_old";
ALTER TYPE "Role_new" RENAME TO "Role";
DROP TYPE "Role_old";
ALTER TABLE "User" ALTER COLUMN "role" SET DEFAULT 'ALUNO';
COMMIT;

-- DropForeignKey
ALTER TABLE "Curso" DROP CONSTRAINT "Curso_universidadeId_fkey";

-- DropForeignKey
ALTER TABLE "Discente" DROP CONSTRAINT "Discente_cursoId_fkey";

-- DropForeignKey
ALTER TABLE "Discente" DROP CONSTRAINT "Discente_livroId_fkey";

-- DropForeignKey
ALTER TABLE "Discente" DROP CONSTRAINT "Discente_userId_fkey";

-- DropForeignKey
ALTER TABLE "Disciplina" DROP CONSTRAINT "Disciplina_cursoId_fkey";

-- DropForeignKey
ALTER TABLE "Disciplina" DROP CONSTRAINT "Disciplina_discenteId_fkey";

-- DropForeignKey
ALTER TABLE "Disciplina" DROP CONSTRAINT "Disciplina_docenteId_fkey";

-- DropForeignKey
ALTER TABLE "DisciplinaEmCurso" DROP CONSTRAINT "DisciplinaEmCurso_discenteId_fkey";

-- DropForeignKey
ALTER TABLE "DisciplinaEmCurso" DROP CONSTRAINT "DisciplinaEmCurso_disciplinaId_fkey";

-- DropForeignKey
ALTER TABLE "DisciplinaEmCurso" DROP CONSTRAINT "DisciplinaEmCurso_docenteId_fkey";

-- DropForeignKey
ALTER TABLE "Docente" DROP CONSTRAINT "Docente_cursoId_fkey";

-- DropForeignKey
ALTER TABLE "Docente" DROP CONSTRAINT "Docente_userId_fkey";

-- DropForeignKey
ALTER TABLE "HistoricoAlunoDisciplina" DROP CONSTRAINT "HistoricoAlunoDisciplina_discenteId_fkey";

-- DropForeignKey
ALTER TABLE "HistoricoAlunoDisciplina" DROP CONSTRAINT "HistoricoAlunoDisciplina_disciplinaId_fkey";

-- DropForeignKey
ALTER TABLE "HistoricoAlunoDisciplina" DROP CONSTRAINT "HistoricoAlunoDisciplina_docenteId_fkey";

-- AlterTable
ALTER TABLE "Disciplina" DROP COLUMN "cursoId",
DROP COLUMN "discenteId",
DROP COLUMN "docenteId",
DROP COLUMN "status",
ADD COLUMN "alunoId" INTEGER,
ADD COLUMN "cargaHoraria" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "docente" TEXT NOT NULL DEFAULT 'Desconhecido',
ADD COLUMN "situacao" "SituacaoDisciplina" DEFAULT 'EM_PROGRESSO',
DROP COLUMN "codigo",
ADD COLUMN "codigo" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "User" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ALTER COLUMN "role" SET DEFAULT 'ALUNO';

-- DropTable
DROP TABLE "Curso";

-- DropTable
DROP TABLE "Discente";

-- DropTable
DROP TABLE "DisciplinaEmCurso";

-- DropTable
DROP TABLE "Docente";

-- DropTable
DROP TABLE "HistoricoAlunoDisciplina";

-- DropTable
DROP TABLE "LivroEmprestadoBiblioteca";

-- DropEnum
DROP TYPE "DisciplinaEmCursoStatus";

-- DropEnum
DROP TYPE "DisciplinaStatus";

-- CreateTable
CREATE TABLE "Aluno" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"nome" TEXT NOT NULL,
"matricula" VARCHAR(9) NOT NULL,
"curso" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Aluno_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Aluno_userId_key" ON "Aluno"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "Aluno_matricula_key" ON "Aluno"("matricula");

-- AddForeignKey
ALTER TABLE "Aluno" ADD CONSTRAINT "Aluno_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Disciplina" ADD CONSTRAINT "Disciplina_alunoId_fkey" FOREIGN KEY ("alunoId") REFERENCES "Aluno"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Warnings:

- You are about to drop the column `userId` on the `Aluno` table. All the data in the column will be lost.
- You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost.
- A unique constraint covering the columns `[usuarioId]` on the table `Aluno` will be added. If there are existing duplicate values, this will fail.
- Added the required column `usuarioId` to the `Aluno` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "Aluno" DROP CONSTRAINT "Aluno_userId_fkey";

-- DropIndex
DROP INDEX "Aluno_userId_key";

-- AlterTable
ALTER TABLE "Aluno" DROP COLUMN "userId",
ADD COLUMN "usuarioId" INTEGER NOT NULL;

-- DropTable
DROP TABLE "User";

-- CreateTable
CREATE TABLE "Usuario" (
"id" SERIAL NOT NULL,
"nome" TEXT NOT NULL,
"token" TEXT,
"role" "Role" NOT NULL DEFAULT 'ALUNO',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Usuario_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Aluno_usuarioId_key" ON "Aluno"("usuarioId");

-- AddForeignKey
ALTER TABLE "Aluno" ADD CONSTRAINT "Aluno_usuarioId_fkey" FOREIGN KEY ("usuarioId") REFERENCES "Usuario"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Aluno" ALTER COLUMN "curso" SET DEFAULT 'Universidade Federal de Campina Grande';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Disciplina" ALTER COLUMN "codigo" SET DATA TYPE TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Aluno" ADD COLUMN "universidade" TEXT NOT NULL DEFAULT 'Universidade Federal de Campina Grande',
ALTER COLUMN "curso" SET DEFAULT 'Ciência da Computação';
152 changes: 39 additions & 113 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,140 +8,66 @@ datasource db {
}

enum Role {
ADMIN // Administrador do sistema
DISCENTE // Aluno de alguma instituição que usa o sistema
DOCENTE // Professor de alguma instituição que usa o sistema
ADMIN
ALUNO
DOCENTE
}

enum DisciplinaStatus {
APENAS_MEDIA_APROVADO // A disciplina foi registrada como paga com êxito e aprovado no sistema
APENAS_MEDIA_REPROVADO // A disciplina foi registrada como nota insuficiente e reprovado no sistema
REPROVADO_POR_FALTA // A disciplina foi registrada como aluno reprovado por falta
TRANCADA // A disciplina foi registrada como trancada pelo aluno
enum SituacaoDisciplina {
APROVADO
EM_PROGRESSO
}

enum DisciplinaEmCursoStatus {
EM_PROGRESSO // A disciplina está em curso
TRANCADA // O aluno trancou a disciplina
TRANCADA
REPROVADO
DISPENSA
REPROVADO_POR_FALTA
}

model Universidade {
id Int @id @default(autoincrement())
sigla String // A sigla da universidade. Ex: 'UFCG'
sigla String // 'UFCG', 'UFPB', 'UFRJ'
nome String
cidade String
estado String
createdAt DateTime @default(now())
cursos Curso[]
}

model User {
model Usuario {
id Int @id @default(autoincrement())
nome String
token String?
role Role @default(DISCENTE)
token String?
role Role @default(ALUNO)
aluno Aluno?
createdAt DateTime @default(now())
discente Discente?
docente Docente?
updatedAt DateTime @default(now())
}

model Discente {
id Int @id @default(autoincrement())
nome String
matricula String @unique @db.VarChar(9)
cursoId Int
userId Int @unique
livroId Int? @unique
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
curso Curso @relation(fields: [cursoId], references: [id])
livros LivroEmprestadoBiblioteca? @relation(fields: [livroId], references: [id])
disciplinasEmCurso DisciplinaEmCurso[]
historicos HistoricoAlunoDisciplina[]
Disciplina Disciplina[]
}

model LivroEmprestadoBiblioteca {
id Int @id @default(autoincrement())
nomeDoLivro String
dataQueFoiPego String
dataQuePrecisaSerEntregue String
dataQueAlunoQuerSerLembrado String
anotacoesSobreOLivro String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
discente Discente?
}


model Docente {
id Int @id @default(autoincrement())
nome String
cursoId Int
userId Int @unique
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
curso Curso @relation(fields: [cursoId], references: [id])
disciplinas Disciplina[]
disciplinasEmCurso DisciplinaEmCurso[]
historicos HistoricoAlunoDisciplina[]
}

model Curso {
id Int @id @default(autoincrement())
universidadeId Int
nome String
createdAt DateTime @default(now())
universidade Universidade @relation(fields: [universidadeId], references: [id])
discentes Discente[]
docentes Docente[]
disciplinas Disciplina[]
model Aluno {
id Int @id @default(autoincrement())
usuarioId Int @unique
nome String
matricula String @unique @db.VarChar(9)
curso String @default("Ciência da Computação")
universidade String @default("Universidade Federal de Campina Grande")
usuario Usuario @relation(fields: [usuarioId], references: [id])
historicoAcademico Disciplina[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
}

model Disciplina {
id Int @id @default(autoincrement())
codigo String?
nome String
creditos Int // Créditos são definidos por horas. Ex: "Cáculo I possui 4 horas semanais, portanto 4 créditos."
semestre String // Semestre em que a disciplina foi cursada
id Int @id @default(autoincrement())
codigo String
nome String
creditos Int
cargaHoraria Int @default(0)
semestre String
situacao SituacaoDisciplina? @default(EM_PROGRESSO)
quantidadeProvas Int
quantidadeFaltas Int
mediaFinal Float?
docenteId Int?
discenteId Int?
status DisciplinaStatus
cursoId Int
createdAt DateTime @default(now())
docente Docente? @relation(fields: [docenteId], references: [id])
discente Discente? @relation(fields: [discenteId], references: [id])
curso Curso @relation(fields: [cursoId], references: [id])
historicos HistoricoAlunoDisciplina[]
disciplinasEmCurso DisciplinaEmCurso[]
horario String?
}

model HistoricoAlunoDisciplina {
id Int @id @default(autoincrement())
discenteId Int
docenteId Int?
disciplinaId Int
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
discente Discente @relation(fields: [discenteId], references: [id])
docente Docente? @relation(fields: [docenteId], references: [id])
disciplina Disciplina @relation(fields: [disciplinaId], references: [id])
}

model DisciplinaEmCurso {
id Int @id @default(autoincrement())
discenteId Int
docenteId Int?
disciplinaId Int
notaDoDiscente Float?
status DisciplinaEmCursoStatus
discente Discente @relation(fields: [discenteId], references: [id])
docente Docente? @relation(fields: [docenteId], references: [id])
disciplina Disciplina @relation(fields: [disciplinaId], references: [id])
mediaFinal Float?
docente String @default("Desconhecido")
alunoId Int?
aluno Aluno? @relation(fields: [alunoId], references: [id])
horario String?
createdAt DateTime @default(now())
}

Loading