@@ -28,7 +28,7 @@ No Makefile/linter config present, no test suite — use plain `go` toolchain co
1.`sync_state` table is auto-bootstrapped at startup (`Pool.BootstrapSchema`, seeds `id=1` students row) — no manual migration step required, though the SQL files under `migrations/` are kept for reference/manual runs.
2. Mongo `students` collection must exist with a `$jsonSchema` validator requiring `student_id` int and `enrollment_id` int. A `deleted_students` collection archives students removed at the source — no schema setup needed for it.
3. Required env vars: `PG_DSN`, `MONGO_URI`, `MONGO_DB`. Optional: `SYNC_INTERVAL` (default `5m`), `PORT` (default `8080`). Per-pipeline PG function name (or raw `PGQuery`) / Mongo collection / deleted-collection / id field / `sync_state` id are **not** env vars — they're declared in `internal/infrastructure/config/pipelines.go` (`Pipelines []PipelineDef`). Add a new sync pipeline by adding an entry there; `internal/infrastructure/pipeline.Build` loops over `config.Pipelines` to wire reader/upserter/mover/state/service/scheduler for each.
3. Required env vars: `PG_DSN`, `MONGO_URI`, `MONGO_DB`. Optional: `SYNC_INTERVAL` (default `5m`), `PORT` (default `8080`), `SCHEDULERS_ENABLED` (default `true`; `false` apaga todos los schedulers y deja solo los triggers HTTP) y `SYNC_<NAME>_ENABLED` (default `true`; `false` apaga el scheduler solo de ese módulo, que igual queda accesible por HTTP) y la configuración explícita de pools: `PG_POOL_MAX_CONNS`/`PG_POOL_MIN_CONNS`/`PG_POOL_MAX_CONN_LIFETIME`/`PG_POOL_MAX_CONN_IDLE_TIME` (pgxpool) y `MONGO_POOL_MAX_SIZE`/`MONGO_POOL_MIN_SIZE`/`MONGO_POOL_MAX_IDLE_TIME` (driver de Mongo); vacío o `0` deja el valor por defecto del driver. Per-pipeline PG function name (or raw `PGQuery`) / Mongo collection / deleted-collection / id field / `sync_state` id are **not** env vars — they're declared in `internal/infrastructure/config/pipelines.go` (`Pipelines []PipelineDef`). Add a new sync pipeline by adding an entry there; `internal/infrastructure/pipeline.Build` loops over `config.Pipelines` to wire reader/upserter/mover/state/service/scheduler for each.
4. Per-pipeline schedule (interval vs. fixed daily time) IS configurable via env vars, unlike the other pipeline settings above: `SYNC_<NAME>_MODE` (`interval` default, or `daily`), `SYNC_<NAME>_INTERVAL` (falls back to `SYNC_INTERVAL`), `SYNC_<NAME>_TIME` (`HH:MM`, required when `MODE=daily`). `<NAME>` is the pipeline name uppercased (`SYNC_STUDENTS_MODE`, `SYNC_PAYMENT_PLANS_MODE`, `SYNC_PARENTS_MODE`). Built by `config.ScheduleFor` into an `internal/usecase.Schedule` (`IntervalSchedule` or `DailySchedule`), consumed by `usecase.NewScheduler`. Example — run every pipeline once a day at 1am (current `.env`):
-**Registro eliminado**: id presente en Mongo pero ya no devuelto por el origen Postgres → el documento se mueve (no solo se elimina) a la colección de archivo (`deleted_students`) con una marca `deleted_at`, contado como `Deleted`.
El estado persistido (`sync_state`) solo avanza si el ciclo completo (hash/upsert + reconciliación de borrados) tiene éxito; cualquier fallo se corta y se reporta vía `/api/v1/sync/<módulo>/status`.
## ENV Configuration
Crea un archivo `.env` en la raíz del proyecto basado en el siguiente ejemplo:
log.Printf("[balotarios_incremental] Paso 3: actualizar balotario en Postgres to_update=false con matricula_id: %d y balotario_id: %d",ref.MatriculaID,ref.BalotarioID)