Commit graph

16 commits

Author SHA1 Message Date
Cursor Agent
3171cddd68
fix(core): RPC jsonb payload, Liquibase splits, worker needs_badge
- Pass JS objects to postgres jsonb params in callCoreFn (not JSON.stringify)
- Use splitStatements:false on RPC function changesets for Liquibase
- Fix needs_badge default in _worker_normalize when field is omitted
- Add scripts/crud-smoke-test.sh for API CRUD verification
- Fix findExistingWorker return type in main.ts

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-04 01:20:49 +00:00
Cursor Agent
b58791aea4
refactor(core): finish RPC migration for budget, excel import, and docs
- Replace remaining budget.ts prepare() with fn_budget_replace and fn_project_update
- Migrate excel.ts findExisting, document store, assign, and catalogs to RPC
- Add 015-rpc-documents.sql for project/company/worker document metadata
- Document RPC envelope conventions in db/README.md
- Add http_errors_test and front api-response composables

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-04 00:01:57 +00:00
Cursor Agent
cff428d283
Refactor payroll_http and excel to use core RPC functions
- Replace db.prepare() in payroll_http with callCoreFn for attendance,
  loans, loan receipts, and legacy payroll period routes
- Use respondRpc/respondApiError for standardized HTTP responses
- Add fn_loan_list/get, fn_loan_payment_get, and fn_payroll_period_* RPCs
  to 013-rpc-payroll.sql with grants
- Refactor excel storeDocument to fn_worker_document_store (S3 stays in TS)
- Refactor importExcel and upsertWorker to fn_workers_import_batch

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 23:57:36 +00:00
Cursor Agent
d2be5c5b76
Add payroll and import RPC changesets (013, 014)
Port key payroll operations from api/payroll.ts to plpgsql RPCs with
round_money helper, internal recalc/ensure logic, and core.rpc_* envelope.

Add batch worker import and post-S3 document metadata store RPCs with
Spanish validation messages and panels_core_app grants.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 23:52:42 +00:00
Cursor Agent
17936ce777
Add PostgreSQL RPC functions for workers domain
Port worker list/get/create/update, pipeline, assign/unassign, find-existing,
refresh-pipeline, and checklist-raw from api/main.ts and api/db.ts with
Spanish RPC envelopes, IMSS flag helpers, and panels_core_app grants.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 23:52:05 +00:00
Cursor Agent
7f2e84e47c
Add budget and badge RPC functions (changesets 011-012)
Implement core.fn_budget_* for list, chapter/item CRUD, and atomic
replace import; core.fn_badge_job_* for create, list, get, and delivery
tracking. All functions use SECURITY INVOKER, rpc envelope helpers, Spanish
messages, and GRANT EXECUTE to panels_core_app.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 23:50:46 +00:00
Cursor Agent
a73090bd11
Add PostgreSQL RPC functions for projects domain (009-rpc-projects)
Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 23:48:40 +00:00
Cursor Agent
02098d37b3
Add PostgreSQL RPC functions for companies CRUD
Implement fn_company_list, fn_company_get, fn_company_get_by_code,
fn_company_create, fn_company_update, and fn_next_company_code with
shared validation helpers mirroring api/companies.ts logic. Uses RPC
envelope helpers from 006-rpc-infra.sql with detailed Spanish error
messages and GRANT EXECUTE for panels_core_app.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 23:48:29 +00:00
Cursor Agent
42bba34469
api: --allow-sys para el SDK de AWS/R2 en Deno
El cliente S3 lee osRelease; sin --allow-sys el ping a R2 falla
con NotCapable aunque endpoint y bucket estén bien.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 05:49:14 +00:00
Cursor Agent
05d1a8c133
migrate: rechazar CONTAINER ID y fallar si el host no resuelve
Coolify no imprime stdout de Liquibase; el job migrate seguía
saliendo 1 por DNS. Preflight deja el host JDBC en los logs del
contenedor y corta si parece un ID de 12 caracteres.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 05:24:51 +00:00
Cursor Agent
a45675b6a6
deploy: Liquibase automático en cada deploy (job migrate)
Coolify usa docker-compose.yml: migrate aplica schema (!dev) y la API
espera a que termine. Postgres/Redis locales quedan en docker-compose.local.yml.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-03 04:54:15 +00:00
Cursor Agent
1ac04996b6
ops: generar accesos por ambiente y verificar Postgres, Redis y Contabo
Scripts create-accesses / verify-connectivity para un Postgres+Redis+bucket
por ambiente. /v1/health y el arranque de la API incluyen sonda de storage.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-02 21:22:39 +00:00
Cursor Agent
d36c287a82
db/infra: ETL de datos, backups y limpieza de despliegue (fase 5-7)
Fase 5 (migracion de datos):
- api/scripts/migrate-sqlite-to-postgres.ts: ETL unico SQLite -> Postgres.
  Pre-flight (CURP/RFC duplicados case-insensitive, FKs huerfanas,
  tenant_id invalido, fechas mal formateadas) -> carga por base/esquema
  con credenciales _owner (setval de secuencias, OVERRIDING SYSTEM VALUE,
  ON CONFLICT DO NOTHING idempotente) -> verificacion de conteos y sumas
  de dinero con tolerancia. Probado end-to-end contra un dataset SQLite
  legacy sintetico y un Postgres limpio (solo schema+catalogos, sin
  contexto dev): 100% de las filas migradas, sumas de dinero exactas,
  snapshot de uploaded_by/created_by resuelto correctamente.
- db/RUNBOOK-corte.md: checklist go/no-go para el corte por ambiente.
- Fix de bug real encontrado al probar: sin --context-filter explicito,
  Liquibase corre TAMBIEN los changesets context=dev (comportamiento por
  defecto, no "modo seguro") -- documentado en db/README.md con el
  ejemplo correcto (--context-filter='!dev' para staging/produccion).

Fase 5b: patron de compensacion para createTenant ya resuelto en el
rewrite de saas.ts (fase 3/4).

Fase 6 (backups): db/backups/ con plantillas pgBackRest por base,
politica de retencion, nota de persistencia minima de Redis (RDB, sin
retencion de negocio), checklist de simulacro de restauracion mensual,
y la validacion pendiente de si Coolify permite WAL archiving antes de
comprometerse a PITR real.

Fase 7 (limpieza y CI):
- Dockerfile.api simplificado (sin JRE/Liquibase/FFI). Dockerfile.migrate
  y Dockerfile.provision nuevos, de un solo uso, para el paso explicito
  de deploy (nunca sirven trafico).
- docker-compose.yml: postgres+redis+provision+migrate para dev local
  end-to-end; api ya no arranca hasta que migrate termina bien.
- docs/coolify.md y .env.example actualizados al modelo de 2 bases +
  Redis + Contabo.
- api/schema.sql eliminado (desincronizado, competia con Liquibase como
  fuente de verdad).
- .github/workflows/ci.yml: Postgres+Redis de servicio, aprovisiona
  roles/ACLs, dry-run de Liquibase (updateSQL) antes de aplicar,
  verify-isolation.sh, deno check + deno test, build de los dos frontends.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-02 21:05:07 +00:00
Cursor Agent
b87b0205a8
db: migrar infraestructura de BD a Postgres (fase 0-1)
- Fase 0: scripts de aprovisionamiento (db/provision/) para roles, dos
  bases de datos separadas (panels_platform / panels_product con
  esquemas iam+core) y ACLs de Redis por modulo, con verificacion
  automatizada de aislamiento (verify-isolation.sh) y setup local
  reproducible (dev-local.sh).
- Fase 1: changelogs de Liquibase reescritos para Postgres
  (db/platform, db/iam, db/core reemplazan db/app + los changesets
  SQLite de platform). Baseline como estado final (no replay literal),
  tipos traducidos (IDENTITY, TIMESTAMPTZ/DATE, NUMERIC, BOOLEAN,
  CITEXT), contexts dev vs. schema/catalogos, RLS por tenant_id como
  defensa en profundidad, uploaded_by/created_by como snapshot
  desnormalizado (sin FK hacia iam).
- Migraciones ya no corren en el arranque de la API: paso explicito de
  deploy via db/update.sh con credenciales _owner.

Verificado end-to-end contra Postgres 16 + Redis local.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-02 20:00:49 +00:00
085366c287 Nominas 2026-08-25 20:21:49 -05:00
70d89609f4 first commit 2026-08-21 16:55:01 -05:00