The UZDI database is a PostgreSQL instance structured across six named schemas, each corresponding to a distinct business domain. The entire schema is defined in a single DDL file —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Zapiony/PUCE_UZDI_2026/llms.txt
Use this file to discover all available pages before exploring further.
DDL_UZDI_FINAL.sql — located at the repository root. TypeORM is configured with synchronize: false, meaning the database structure is always governed by this DDL file and never auto-generated by the ORM.
Initialization
Create the database
Connect to your PostgreSQL server and create the application database:Or using the
psql interactive shell:Apply the DDL script
Run the DDL file from the repository root against the new database. This creates all six schemas, tables, constraints, indexes, and trigger functions in a single pass:The script is idempotent for schema creation (
CREATE SCHEMA IF NOT EXISTS) but not for tables — do not run it twice against a database that already has data unless you first drop the schemas using the commented DROP SCHEMA … CASCADE statements at the top of the file.Schema Reference
| Schema | Purpose | Key tables |
|---|---|---|
estructura_institucional | Geographic and organizational hierarchy | provincia, canton, uzdi |
seguridad | Users, profiles, permissions, sessions, and audit history | prsn, prfl, accn, prms, sesn, historial, tipo_persona |
adolescente | Core adolescent registry and case management | adolescente, expediente, medida_socioeducativa, infraccion, etnia, nacionalidad, estado_civil, gdo |
contexto_familiar | Family representatives and relationship records | representante, adolescente_representante, tipo_parentesco |
talleres_actividades | Workshops and attendance tracking | taller, asistencia_taller |
gestion_documental | Expedient document management | documento_expediente, tipo_documento |
DDL Conventions
BOOLEAN as CHAR(1) ('V'/'F')
All boolean fields in the database are stored as CHAR(1) with a CHECK constraint that allows only 'V' (verdadero / true) or 'F' (falso / false). Native SQL BOOLEAN is not used.
BooleanVF value transformer (defined in src/common/transformers/boolean-vf.transformer.ts) to convert transparently between 'V'/'F' at the database layer and true/false in TypeScript. See the Backend Modules page for usage details.
expediente.estado CHECK Constraint
The estado column on adolescente.expediente is restricted to exactly three string values:
| Value | Meaning |
|---|---|
'En proceso' | Measure is active and progressing on schedule |
'Atraso' | Adolescent is behind on fulfilling the measure |
'Incomparecencia' | Adolescent has not presented as required |
Timestamp Columns (fcCrea / fcMod)
Most tables include "fcCrea" TIMESTAMP DEFAULT NOW() and "fcMod" TIMESTAMP DEFAULT NOW(). The fcMod column is kept current automatically by the fn_actualizar_fcmod trigger (see below). Note that these column names are quoted identifiers with camelCase — they must be quoted in raw SQL queries.
Audit Functions and Triggers
The DDL defines two PostgreSQL trigger functions in theseguridad schema that fire automatically on DML operations.
seguridad.fn_registrar_historial
Fires AFTER INSERT OR UPDATE OR DELETE on every audited table (all tables except seguridad.historial itself, to prevent recursion). It writes one row to seguridad.historial for every affected row:
app.usuario_id is not set (or cannot be cast to INT4), usua_id defaults to 0.
seguridad.fn_actualizar_fcmod
Fires BEFORE UPDATE on all tables that have a "fcMod" column. It simply sets NEW."fcMod" = NOW() before the row is written, so application code never needs to manage this timestamp manually.
TypeORM Configuration
TypeORM is configured inAppModule via TypeOrmModule.forRoot():
| Option | Value | Reason |
|---|---|---|
type | 'postgres' | PostgreSQL driver via pg package |
url | process.env.DATABASE_URL | Full connection string from .env |
autoLoadEntities | true | Entities are registered automatically when their feature module is imported |
synchronize | false | Schema is managed exclusively by DDL_UZDI_FINAL.sql |