feat(database): expand schema with complete recruitment system (db_hso)#14
feat(database): expand schema with complete recruitment system (db_hso)#14Helysalgado wants to merge 5 commits intoLIDR-academy:mainfrom
Conversation
WalkthroughThis PR introduces a comprehensive recruitment system database schema with 12 new tables (Company, Employee, Position, Application, Interview, InterviewType, InterviewFlow, InterviewStep), five ENUMs, extensive relationships with cascade delete rules, supporting Prisma models, SQL migration, seed test data, validation queries, and detailed schema documentation. Changes
Sequence Diagram(s)sequenceDiagram
actor Candidate
participant App as Application
participant Position
participant Interview
participant Employee
participant Result
Candidate->>App: Submits Application
App->>Position: References Position
activate Position
Position-->>App: Returns InterviewFlow
deactivate Position
App->>Interview: Creates Interview Records<br/>(per InterviewStep)
activate Interview
Interview->>Employee: Assigns to Employee
Employee-->>Interview: Confirms Assignment
Interview->>Result: Records Result & Score
Result-->>Interview: Stores in DB
deactivate Interview
Interview-->>App: Updates Application Status
activate App
App-->>Candidate: Notifies Outcome
deactivate App
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (6)
backend/prisma/validation-queries.sql (4)
19-33: Query 1 (email index): Correct but consider FILTER alternative.The EXPLAIN ANALYZE and LEFT JOIN pattern for counting applications is sound. However, using a FILTER clause on COUNT would be more idiomatic PostgreSQL:
-COUNT(a.id) as total_applications +COUNT(a.id) FILTER (WHERE a.id IS NOT NULL) as total_applicationsThis is a minor style improvement; current form is correct.
74-114: Query 3: Verify PostgreSQL version for json_agg(DISTINCT ...) compatibility.The query uses
json_agg(DISTINCT ...)to build JSON objects from multi-joined rows. This syntax requires PostgreSQL 9.4+ but has subtle behavior:DISTINCTon complex objects (like JSONB) may not work as expected in all versions or may be inefficient.Consider as a safer alternative using window functions or subqueries to deduplicate before aggregation, especially if portability across PostgreSQL versions is a concern:
-- Example: Subquery approach for Education WITH candidate_education AS ( SELECT DISTINCT ON (e.id) c.id as candidate_id, jsonb_build_object(...) as edu_obj FROM ... ) SELECT ..., json_agg(edu_obj) as education FROM ...If your target is PostgreSQL 14+, the current form is acceptable.
227-278: Query 6: Foreign key integrity checks are comprehensive but incomplete.The orphan detection for Education, WorkExperience, Application, and Interview is thorough. However, two potential gaps:
- Resume table: The PR summary mentions Resume but no orphan check exists for it. Verify this is intentional (e.g., if Resume is a document reference with different lifecycle).
- InterviewFlow and InterviewType: Not validated for orphaned records (though Position.interviewFlowId is a FK, InterviewFlow records themselves could be unused).
Consider adding:
-- InterviewFlow without Position reference SELECT 'InterviewFlow sin Position', COUNT(*) FROM "InterviewFlow" intf WHERE NOT EXISTS (SELECT 1 FROM "Position" p WHERE p."interviewFlowId" = intf.id) UNION ALL -- InterviewType without InterviewStep reference SELECT 'InterviewType sin uso', COUNT(*) FROM "InterviewType" it WHERE NOT EXISTS (SELECT 1 FROM "InterviewStep" ist WHERE ist."interviewTypeId" = it.id)
437-450: Validation summary is well-documented.The checklist clearly articulates what each query validates. Consider augmenting with:
- PostgreSQL version requirement (e.g., "PostgreSQL 12.x+")
- Expected execution time ranges (ms) for each EXPLAIN ANALYZE query
- Example seed data row counts (e.g., "Assumes ~100 candidates, ~50 positions, ~20 applications" from seed-test-data.sql)
These additions would help developers understand when performance regressions occur.
backend/docs/prompts-cursor-db-plan-hso_bp.md (1)
17-119: Add language specifications to all fenced code blocks.Markdown linting (MD040) requires language identifiers for code blocks. This improves readability and enables syntax highlighting. Apply the following language tags:
- Lines with SQL statements →
sql- Lines with Prisma schema →
prisma- Lines with bash commands →
bash- Lines with TypeScript code →
typescriptFor example:
- ``` + ```bash git checkout -b db-hsoThis will ensure compliance with markdown standards and improve code visibility for readers using markdown renderers. Also applies to: 134-146, 162-173, 186-199, 214-223, 230-232, 247-254, 266-276, 285-292, 304-310, 323-330 </blockquote></details> <details> <summary>prompts/prompts-hso.md (1)</summary><blockquote> `47-49`: **Add language specifications to all fenced code blocks.** All code blocks throughout this file lack language identifiers (bash, sql, prisma, typescript), which triggers MD040 linting errors and reduces syntax highlighting. Apply consistent language tags to: - Bash commands → `bash` - SQL queries → `sql` - Prisma schema → `prisma` - TypeScript code → `typescript` Also applies to: 61-68, 94-104, 128-136, 167-176, 192-195, 212-226, 248-250, 256-261, 265-271, 276-291, 294-300, 305-310, 316-320, 323-328, 332-337, 343-352 </blockquote></details> </blockquote></details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
🎯 Objetivo
Expandir la base de datos del sistema LTI de un gestor básico de candidatos (4 modelos) a un sistema completo de reclutamiento end-to-end.
📊 Resumen de Cambios
Antes
Después
🆕 Nuevos Modelos
🎨 ENUMs Creados
PositionStatus: DRAFT | OPEN | CLOSED | ON_HOLDEmploymentType: FULL_TIME | PART_TIME | CONTRACT | TEMPORARY | INTERNSHIPApplicationStatus: PENDING | REVIEWING | INTERVIEWED | ACCEPTED | REJECTED | WITHDRAWNInterviewResult: PENDING | PASSED | FAILED | NO_SHOWEmployeeRole: RECRUITER | HIRING_MANAGER | INTERVIEWER | ADMIN🏗️ Buenas Prácticas Aplicadas
Normalización
Performance
Decimalpara salarios,ENUMpara estados)Integridad Referencial
Decisiones de Diseño Destacadas
Applicationcon UNIQUE(positionId, candidateId)- Un candidato aplica una sola vez por posiciónInterviewStepcon UNIQUE(interviewFlowId, orderIndex)- Orden correcto garantizadoInterviewFlowyInterviewSteppara máxima flexibilidad📁 Archivos Modificados/Creados
Core (Requeridos)
backend/prisma/schema.prisma- 243 líneas, 12 modelosbackend/prisma/migrations/20251117233207_db_hso/migration.sql- 298 líneas SQLprompts/prompts-hso.md- Documentación completa del procesoDocumentación Extra (Valor Agregado)
backend/docs/database-dictionary.md- 702 líneas, diccionario profesionalbackend/docs/er-diagram.md- 554 líneas, diagramas Mermaid completosbackend/prisma/seed-test-data.sql- 17 registros de prueba realistasbackend/prisma/validation-queries.sql- 10 queries de validación con EXPLAIN ANALYZETotal: ~2,800 líneas de código y documentación
🧪 Testing/Validación
Migración
20251117233207_db_hsoDatos de Prueba
Queries Validadas
Query de prueba ejecutada:
Resultado: ✅ Juan Pérez → Desarrollador Full Stack Senior → REVIEWING → PASSED (85 pts) → María García
📚 Documentación
Diccionario de Datos (
database-dictionary.md)Diagrama ER (
er-diagram.md)Proceso Completo (
prompts-hso.md)🎯 Checklist de QA
🔄 Cambios Breaking
Razón: Modificaciones en modelos existentes (agregado de índices, onDelete, timestamps en Candidate)
Acción requerida:
🚀 Próximos Pasos (Post-Merge)
Inmediato
npx prisma generateCorto Plazo
Mediano Plazo
🤝 Revisores
Por favor validar:
📖 Referencias
backend/docs/prompts-cursor-db-plan-hso_bp.mdbackend/docs/database-dictionary.mdbackend/docs/er-diagram.mdprompts/prompts-hso.mdbackend/prisma/migrations/20251117233207_db_hso/migration.sql🏷️ Labels Sugeridos
feature- Nueva funcionalidaddatabase- Cambios en base de datosbreaking-change- Requiere reset de BDdocumentation- Incluye docs extensasDesarrollado en rama:
db-hsoModelo de IA: Claude Sonnet 4.5
IDE: Cursor
Ejercicio: AI4Devs - Módulo de Bases de Datos
Summary by CodeRabbit
New Features
Documentation
Chores