Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Distribuidos-Org/ms-alumnos/llms.txt
Use this file to discover all available pages before exploring further.
ms-alumnos persists all student data to a PostgreSQL database using TypeORM. The connection is configured in AppModule via TypeOrmModule.forRoot(), with synchronize: true enabled so that TypeORM automatically creates and alters the database schema to match the entity definitions on every application startup. This keeps the development workflow frictionless — no migration files need to be run manually — but carries important caveats in production environments (see Synchronize in production).
Connection configuration
The TypeORM connection is configured insrc/app.module.ts using environment variables that are validated at startup by src/config/envs.ts:
| Property | Value | Description |
|---|---|---|
type | 'postgres' | Selects the PostgreSQL driver. |
host | DB_HOST env var | Hostname or IP of the PostgreSQL server (e.g. localhost or a Docker service name). |
port | DB_PORT env var | Port the PostgreSQL server listens on — coerced to a number with the unary + operator. |
username | DB_USER env var | Database user account. |
password | DB_PASSWORD env var | Password for the database user. |
database | DB_NAME env var | Name of the target PostgreSQL database. |
entities | glob pattern | TypeORM discovers entity classes by scanning all files matching **/*.entity{.ts,.js} relative to the compiled output directory. |
synchronize | true | Automatically applies schema changes (CREATE TABLE, ALTER COLUMN, etc.) derived from entity metadata on every startup. |
Alumnos table schema
Thealumnos table is defined by the Alumno TypeORM entity at src/alumnos/entities/alumno.entity.ts:
| Column name | TypeScript property | Type | Constraints | Notes |
|---|---|---|---|---|
alumno_id | alumnoId | SERIAL (auto-increment integer) | Primary key | Auto-generated by the database on insert. |
nombre | nombre | VARCHAR(50) | NOT NULL | Student’s first name. |
apellido_paterno | apellidoPaterno | VARCHAR(50) | NOT NULL | Paternal surname. |
apellido_materno | apellidoMaterno | VARCHAR(50) | Nullable | Maternal surname — optional in Peruvian naming conventions. |
dni | dni | VARCHAR(8) | NOT NULL, UNIQUE | Peruvian national identity document number (exactly 8 characters). |
edad | edad | INT | Nullable | Age in years. Optional. |
email | email | VARCHAR(100) | NOT NULL, UNIQUE | Contact email address. Must be unique across all students. |
celular | celular | VARCHAR(15) | Nullable | Mobile phone number. Optional. |
universidad | universidad | VARCHAR(100) | NOT NULL, DEFAULT 'UNMSM' | University name; defaults to Universidad Nacional Mayor de San Marcos. |
facultad | facultad | VARCHAR(100) | Nullable | Faculty or school within the university. Optional. |
profesion | profesion | VARCHAR(50) | Nullable | Declared profession or degree programme. Optional. |
grado | grado | VARCHAR(50) | Nullable | Academic grade or degree level. Optional. |
egresado_local | egresadoLocal | BOOLEAN | NOT NULL, DEFAULT true | Whether the student graduated from a local (Peruvian) institution. |
contrasena | contrasena | VARCHAR(60) | NOT NULL | Stores a bcrypt hash of the student’s password. The 60-character length matches the bcrypt output length. |
Password hashing
TheAlumno entity registers a @BeforeInsert() lifecycle hook that automatically hashes the contrasena field before TypeORM issues the INSERT statement:
bcrypt.hash with a cost factor of 10, which produces a 60-character hash string — matching the VARCHAR(60) column definition exactly. Because the hook runs transparently as part of the TypeORM entity lifecycle, callers can pass a plain-text password in CreateAlumnoDto and the service layer never needs to handle hashing manually.
Docker Compose
Adocker-compose.yml is provided at the project root to spin up a local PostgreSQL instance for development:
DB_USER, DB_NAME, DB_PASSWORD, and DB_PORT from a .env file in the same directory. The db_data named volume ensures that database contents survive container restarts.
To start the database:
npm run start:dev). Because synchronize: true is set, TypeORM will create the alumnos table automatically on first run.