Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajustes sobre el modelo LTI #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
183 changes: 183 additions & 0 deletions backend/prisma/migrations/migracion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
-- Tablas normalizadas a 3NF

-- Tabla COMPANY (sin cambios)
CREATE TABLE COMPANY (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL
);

-- Tabla EMPLOYEE (sin cambios significativos)
CREATE TABLE EMPLOYEE (
id SERIAL PRIMARY KEY,
company_id INTEGER NOT NULL,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
role VARCHAR(50) NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
FOREIGN KEY (company_id) REFERENCES COMPANY(id)
);

-- Tabla INTERVIEW_FLOW (sin cambios)
CREATE TABLE INTERVIEW_FLOW (
id SERIAL PRIMARY KEY,
description TEXT NOT NULL
);

-- Tabla POSITION (normalizada)
CREATE TABLE POSITION (
id SERIAL PRIMARY KEY,
company_id INTEGER NOT NULL,
interview_flow_id INTEGER NOT NULL,
title VARCHAR(100) NOT NULL,
description TEXT,
status VARCHAR(50) NOT NULL,
is_visible BOOLEAN NOT NULL DEFAULT TRUE,
location VARCHAR(100),
employment_type VARCHAR(50),
application_deadline DATE,
contact_info VARCHAR(255),
FOREIGN KEY (company_id) REFERENCES COMPANY(id),
FOREIGN KEY (interview_flow_id) REFERENCES INTERVIEW_FLOW(id)
);

-- Nueva tabla POSITION_DETAILS
CREATE TABLE POSITION_DETAILS (
position_id INTEGER PRIMARY KEY,
job_description TEXT,
requirements TEXT,
responsibilities TEXT,
salary_min NUMERIC,
salary_max NUMERIC,
benefits TEXT,
company_description TEXT,
FOREIGN KEY (position_id) REFERENCES POSITION(id)
);

-- Tabla INTERVIEW_TYPE (sin cambios)
CREATE TABLE INTERVIEW_TYPE (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT
);

-- Tabla INTERVIEW_STEP (sin cambios)
CREATE TABLE INTERVIEW_STEP (
id SERIAL PRIMARY KEY,
interview_flow_id INTEGER NOT NULL,
interview_type_id INTEGER NOT NULL,
name VARCHAR(100) NOT NULL,
order_index INTEGER NOT NULL,
FOREIGN KEY (interview_flow_id) REFERENCES INTERVIEW_FLOW(id),
FOREIGN KEY (interview_type_id) REFERENCES INTERVIEW_TYPE(id)
);

-- Tabla CANDIDATE (sin cambios significativos)
CREATE TABLE CANDIDATE (
id SERIAL PRIMARY KEY,
firstName VARCHAR(100) NOT NULL,
lastName VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
phone VARCHAR(15),
address VARCHAR(100)
);

-- Tabla APPLICATION (sin cambios)
CREATE TABLE APPLICATION (
id SERIAL PRIMARY KEY,
position_id INTEGER NOT NULL,
candidate_id INTEGER NOT NULL,
application_date DATE NOT NULL,
status VARCHAR(50) NOT NULL,
notes TEXT,
FOREIGN KEY (position_id) REFERENCES POSITION(id),
FOREIGN KEY (candidate_id) REFERENCES CANDIDATE(id)
);

-- Tabla INTERVIEW (sin cambios)
CREATE TABLE INTERVIEW (
id SERIAL PRIMARY KEY,
application_id INTEGER NOT NULL,
interview_step_id INTEGER NOT NULL,
employee_id INTEGER NOT NULL,
interview_date DATE NOT NULL,
result VARCHAR(50),
score INTEGER,
notes TEXT,
FOREIGN KEY (application_id) REFERENCES APPLICATION(id),
FOREIGN KEY (interview_step_id) REFERENCES INTERVIEW_STEP(id),
FOREIGN KEY (employee_id) REFERENCES EMPLOYEE(id)
);

-- Tabla EDUCATION (sin cambios)
CREATE TABLE EDUCATION (
id SERIAL PRIMARY KEY,
institution VARCHAR(100) NOT NULL,
title VARCHAR(250) NOT NULL,
startDate DATE NOT NULL,
endDate DATE,
candidateId INTEGER NOT NULL,
FOREIGN KEY (candidateId) REFERENCES CANDIDATE(id)
);

-- Tabla WORK_EXPERIENCE (sin cambios)
CREATE TABLE WORK_EXPERIENCE (
id SERIAL PRIMARY KEY,
company VARCHAR(100) NOT NULL,
position VARCHAR(100) NOT NULL,
description VARCHAR(200),
startDate DATE NOT NULL,
endDate DATE,
candidateId INTEGER NOT NULL,
FOREIGN KEY (candidateId) REFERENCES CANDIDATE(id)
);

-- Tabla RESUME (sin cambios)
CREATE TABLE RESUME (
id SERIAL PRIMARY KEY,
filePath VARCHAR(500) NOT NULL,
fileType VARCHAR(50) NOT NULL,
uploadDate DATE NOT NULL,
candidateId INTEGER NOT NULL,
FOREIGN KEY (candidateId) REFERENCES CANDIDATE(id)
);

-- Índices para optimizar consultas

-- Índices para EMPLOYEE
CREATE INDEX idx_employee_company ON EMPLOYEE(company_id);
CREATE INDEX idx_employee_email ON EMPLOYEE(email);

-- Índices para POSITION
CREATE INDEX idx_position_company ON POSITION(company_id);
CREATE INDEX idx_position_interview_flow ON POSITION(interview_flow_id);
CREATE INDEX idx_position_status ON POSITION(status);
CREATE INDEX idx_position_location ON POSITION(location);

-- Índices para INTERVIEW_STEP
CREATE INDEX idx_interview_step_flow ON INTERVIEW_STEP(interview_flow_id);
CREATE INDEX idx_interview_step_type ON INTERVIEW_STEP(interview_type_id);

-- Índices para CANDIDATE
CREATE INDEX idx_candidate_email ON CANDIDATE(email);
CREATE INDEX idx_candidate_name ON CANDIDATE(firstName, lastName);

-- Índices para APPLICATION
CREATE INDEX idx_application_position ON APPLICATION(position_id);
CREATE INDEX idx_application_candidate ON APPLICATION(candidate_id);
CREATE INDEX idx_application_date ON APPLICATION(application_date);
CREATE INDEX idx_application_status ON APPLICATION(status);

-- Índices para INTERVIEW
CREATE INDEX idx_interview_application ON INTERVIEW(application_id);
CREATE INDEX idx_interview_step ON INTERVIEW(interview_step_id);
CREATE INDEX idx_interview_employee ON INTERVIEW(employee_id);
CREATE INDEX idx_interview_date ON INTERVIEW(interview_date);

-- Índices para EDUCATION
CREATE INDEX idx_education_candidate ON EDUCATION(candidateId);

-- Índices para WORK_EXPERIENCE
CREATE INDEX idx_work_experience_candidate ON WORK_EXPERIENCE(candidateId);

-- Índices para RESUME
CREATE INDEX idx_resume_candidate ON RESUME(candidateId);
162 changes: 146 additions & 16 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,152 @@ datasource db {
url = env("DATABASE_URL")
}

model Company {
id Int @id @default(autoincrement())
name String @db.VarChar(100)
employees Employee[]
positions Position[]
}

model Employee {
id Int @id @default(autoincrement())
companyId Int
name String @db.VarChar(100)
email String @unique @db.VarChar(255)
role String @db.VarChar(50)
isActive Boolean @default(true)
company Company @relation(fields: [companyId], references: [id])
interviews Interview[]

@@index([companyId])
@@index([email])
}

model InterviewFlow {
id Int @id @default(autoincrement())
description String
positions Position[]
steps InterviewStep[]
}

model Position {
id Int @id @default(autoincrement())
companyId Int
interviewFlowId Int
title String @db.VarChar(100)
description String?
status String @db.VarChar(50)
isVisible Boolean @default(true)
location String? @db.VarChar(100)
employmentType String? @db.VarChar(50)
applicationDeadline DateTime?
contactInfo String? @db.VarChar(255)
company Company @relation(fields: [companyId], references: [id])
interviewFlow InterviewFlow @relation(fields: [interviewFlowId], references: [id])
details PositionDetails?
applications Application[]

@@index([companyId])
@@index([interviewFlowId])
@@index([status])
@@index([location])
}

model PositionDetails {
positionId Int @id
jobDescription String?
requirements String?
responsibilities String?
salaryMin Float?
salaryMax Float?
benefits String?
companyDescription String?
position Position @relation(fields: [positionId], references: [id])
}

model InterviewType {
id Int @id @default(autoincrement())
name String @db.VarChar(100)
description String?
steps InterviewStep[]
}

model InterviewStep {
id Int @id @default(autoincrement())
interviewFlowId Int
interviewTypeId Int
name String @db.VarChar(100)
orderIndex Int
interviewFlow InterviewFlow @relation(fields: [interviewFlowId], references: [id])
interviewType InterviewType @relation(fields: [interviewTypeId], references: [id])
interviews Interview[]

@@index([interviewFlowId])
@@index([interviewTypeId])
}

model Candidate {
id Int @id @default(autoincrement())
firstName String @db.VarChar(100)
lastName String @db.VarChar(100)
email String @unique @db.VarChar(255)
phone String? @db.VarChar(15)
address String? @db.VarChar(100)
educations Education[]
workExperiences WorkExperience[]
resumes Resume[]
id Int @id @default(autoincrement())
firstName String @db.VarChar(100)
lastName String @db.VarChar(100)
email String @unique @db.VarChar(255)
phone String? @db.VarChar(15)
address String? @db.VarChar(100)
educations Education[]
workExperiences WorkExperience[]
resumes Resume[]
applications Application[]

@@index([email])
@@index([firstName, lastName])
}

model Application {
id Int @id @default(autoincrement())
positionId Int
candidateId Int
applicationDate DateTime
status String @db.VarChar(50)
notes String?
position Position @relation(fields: [positionId], references: [id])
candidate Candidate @relation(fields: [candidateId], references: [id])
interviews Interview[]

@@index([positionId])
@@index([candidateId])
@@index([applicationDate])
@@index([status])
}

model Interview {
id Int @id @default(autoincrement())
applicationId Int
interviewStepId Int
employeeId Int
interviewDate DateTime
result String? @db.VarChar(50)
score Int?
notes String?
application Application @relation(fields: [applicationId], references: [id])
interviewStep InterviewStep @relation(fields: [interviewStepId], references: [id])
employee Employee @relation(fields: [employeeId], references: [id])

@@index([applicationId])
@@index([interviewStepId])
@@index([employeeId])
@@index([interviewDate])
}

model Education {
id Int @id @default(autoincrement())
institution String @db.VarChar(100)
title String @db.VarChar(250)
startDate DateTime
endDate DateTime?
candidateId Int
candidate Candidate @relation(fields: [candidateId], references: [id])
id Int @id @default(autoincrement())
institution String @db.VarChar(100)
title String @db.VarChar(250)
startDate DateTime
endDate DateTime?
candidateId Int
candidate Candidate @relation(fields: [candidateId], references: [id])

@@index([candidateId])
}

model WorkExperience {
Expand All @@ -45,6 +171,8 @@ model WorkExperience {
endDate DateTime?
candidateId Int
candidate Candidate @relation(fields: [candidateId], references: [id])

@@index([candidateId])
}

model Resume {
Expand All @@ -54,4 +182,6 @@ model Resume {
uploadDate DateTime
candidateId Int
candidate Candidate @relation(fields: [candidateId], references: [id])

@@index([candidateId])
}
Loading