Feat/backend health rollback bonus scaling 697 698 699 715#851
Merged
Wilfred007 merged 5 commits intoMay 29, 2026
Merged
Conversation
Two migration files shared the 040_ prefix (040_api_database_scaling_part27.sql and 040_optimize_transaction_log_indexes.sql). The resequence script was run to restore a contiguous, unique numbering scheme: 040_optimize_transaction_log_indexes.sql → 041_… 041_circuit_breaker_part11.sql → 042_… V15__scaling_indexes.sql → 043_… Rollback files were created for the three previously untracked migrations (040_api_database_scaling_part27, 041_optimize_transaction_log_indexes, and 042_circuit_breaker_part11) before resequencing so both directories stay in sync. Also adds a root eslint.config.js (ESLint v10 flat config) so the lint-staged pre-commit hook can run without erroring on non-JS files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds two Kubernetes-style health probe endpoints to the Express app:
GET /api/v1/health/live — liveness: returns 200 immediately, no dependency
checks. Used by k8s/Docker to confirm the process
is alive without risk of cascading timeouts.
GET /api/v1/health/ready — readiness: checks PostgreSQL and Redis reachability,
returns 200 when all deps are up, 503 otherwise.
Prevents load-balancer traffic until the instance is
ready to serve requests.
Both probes are also available on the short /health/live and /health/ready paths
for backward compatibility with non-versioned infrastructure.
Tests: added 8 new test cases covering 200/503 responses, dependency failures,
and confirming the liveness probe does not call pool.query.
Closes Gildado#697
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ldado#698) Adds the database migration rollback infrastructure required by Issue Gildado#698: Migration files: 044_migration_rollback_audit.sql — creates migration_rollback_log table to persist an immutable audit trail of every rollback event. New service/controller/routes: MigrationStatusService — reads schema_migrations + migration_rollback_log to produce a full status report (applied, pending, rollback history). Gracefully degrades if the log table does not exist yet. MigrationStatusController — three endpoints backed by the service. migrationStatusRoutes — registered at /api/v1/migrations/. API endpoints: GET /api/v1/migrations/status — full report: applied + pending + history GET /api/v1/migrations/applied — applied migrations with checksums & dates GET /api/v1/migrations/rollbacks — rollback event log (most recent first) Tests: 8 unit tests covering getApplied, getStatus (pending detection, missing table graceful handling), getRollbackHistory (limit clamping, error resilience). Closes Gildado#698 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…do#699) Extends the payroll engine to track why a bonus was issued and, for performance-based bonuses, record the employee's performance score. Migration 045_add_performance_bonus_fields.sql: ALTER TABLE payroll_items ADD COLUMN bonus_type VARCHAR(50) CHECK (bonus_type IN ('performance','referral','project','retention','spot','other')) ALTER TABLE payroll_items ADD COLUMN performance_score NUMERIC(5,2) CHECK (0–100) Partial indexes on both columns for efficient filtered queries. Service changes (PayrollBonusService): • addBonusItem / addBatchBonusItems — now accept bonus_type and performance_score and persist them with each bonus item. • listBonusesByType(orgId, bonusType) — filter bonus history by category. • getPerformanceBonusesByScore(orgId, minScore) — list performance bonuses above a score threshold, ordered score-descending. Controller changes (PayrollBonusController): • listBonusesByType → GET /api/v1/payroll-bonus/bonuses/by-type/:bonusType • getPerformanceBonuses → GET /api/v1/payroll-bonus/bonuses/performance Tests: 18 new unit tests covering bonus creation with/without type+score, batch inserts, transaction rollback on error, listBonusesByType filtering, getPerformanceBonusesByScore, and deletePayrollItem totals recalculation. Closes Gildado#699 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ldado#715) Migration 046_api_database_scaling_part25.sql: • api_latency_histogram table — stores pre-bucketed p50/p95/p99 latency observations per endpoint, with a 30-day auto-prune function. • idx_employees_list_covering — covering index on employees (org, status, created_at) to avoid heap fetches on the high-traffic employee list API. • idx_transactions_list_covering — covering index on transactions for the same reason. New API endpoints (scalingRoutes.ts): GET /api/v1/scaling/latency-percentiles — compute p50/p95/p99 per endpoint from the histogram table over a configurable time window. Params: limit (default 20, max 100), windowMinutes (default 60, max 1440). GET /api/v1/scaling/pool-history — time-series snapshots from db_pool_health so operators can spot connection-pool saturation trends without Grafana. Params: limit (default 20, max 200). Tests: 8 new integration tests for latency-percentiles (200 response, empty result, limit capping, windowMinutes parameter) and pool-history (200, limit capping, 500 on DB error). Closes Gildado#715 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@xeladev4 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Summary
Closes #697 , Closes #698 , Closes #699 , Closes #715
Four backend issues addressed in one branch:
What Changed
Chore — Re-sequence migrations (prerequisite)
040_prefix, which the migration runner rejects with a fatal duplicate-prefix error.040_api_database_scaling_part27,041_optimize_transaction_log_indexes,042_circuit_breaker_part11,043_V15__scaling_indexes).node scripts/resequence-migrations.mjs(the prescribed fix perCONTRIBUTING.md) to restore unique, contiguous numbering.eslint.config.js(ESLint v10 flat config) so the pre-commitlint-stagedhook no longer errors on non-JS staged files.#697 — Health Check Endpoints
HealthController.getLiveness()— returns{ status: "alive", uptime, timestamp }with no dependency checks; safe for k8s liveness probes that must never block.HealthController.getReadiness()— checks PostgreSQL and Redis; returns200 { status: "ready" }or503 { status: "not_ready" }.app.ts:GET /api/v1/health/liveGET /api/v1/health/readyGET /health/liveGET /health/ready#698 — Database Migration Rollback Strategy
044_migration_rollback_audit.sql— createsmigration_rollback_logtable: an immutable audit trail of every rollback event (filename, timestamp, user, reason, execution_ms).MigrationStatusService— readsschema_migrationsandmigration_rollback_logto surface a full status report. Gracefully returns an empty rollback history if the log table does not exist yet (safe for pre-044 databases).MigrationStatusController+migrationStatusRoutes:GET /api/v1/migrations/status— full report: applied, pending (with rollback availability flag), rollback historyGET /api/v1/migrations/applied— applied migrations with checksums and timestampsGET /api/v1/migrations/rollbacks— rollback event log, most recent first (?limit=capped at 100)#699 — Performance Bonuses in Payroll Engine
045_add_performance_bonus_fields.sql:payroll_items.bonus_type VARCHAR(50)—CHECKconstrained to('performance','referral','project','retention','spot','other').payroll_items.performance_score NUMERIC(5,2)— 0–100 range check;NULLfor non-performance bonuses.PayrollBonusServiceupdates:addBonusItem/addBatchBonusItems— now accept and persistbonus_typeandperformance_score.listBonusesByType(orgId, bonusType)— filter bonus history by category.getPerformanceBonusesByScore(orgId, minScore)— list performance bonuses above a score threshold, ordered score-descending.PayrollBonusController— two new methods:listBonusesByType,getPerformanceBonuses.payrollBonusRoutes— two new routes:GET /api/v1/payroll-bonus/bonuses/by-type/:bonusTypeGET /api/v1/payroll-bonus/bonuses/performance?minScore=payrollBonusService.test.tscovering create, add (with/without new fields), batch insert, transaction rollback on error, listBonusesByType, getPerformanceBonusesByScore, deletePayrollItem.#715 — API & Database Scaling Part 25
046_api_database_scaling_part25.sql:api_latency_histogramtable — stores pre-bucketed latency observations per endpoint/method, with a 30-day auto-prune function.idx_employees_list_covering— covering index onemployees(organization_id, status, created_at DESC) INCLUDE (first_name, last_name, email, wallet_address)to avoid heap fetches on the high-traffic employee list query.idx_transactions_list_covering— covering index ontransactions(organization_id, status, created_at DESC) INCLUDE (amount, type).scalingRoutes.ts— two new Part 25 endpoints:GET /api/v1/scaling/latency-percentiles— computes p50/p95/p99 per endpoint fromapi_latency_histogramover a configurable time window (?limit=,?windowMinutes=).GET /api/v1/scaling/pool-history— time-series snapshots fromdb_pool_healthfor connection-pool saturation trend analysis (?limit=).Checklist
Testing
For the migration runner dry-run:
cd backend npm run db:migrate:dry-runDocumentation
backend/src/db/MIGRATION_GUIDE.md); the newmigration_rollback_logtable extends that infrastructure.Accessibility / Responsiveness
N/A — backend API changes only.
Notes
Migration checklist (per
CONTRIBUTING.md):NNN_short_description.sql)IF NOT EXISTS/IF EXISTSfor idempotencybackend/src/db/rollbacks/The pre-existing duplicate
040_prefix is fixed as part of this PR via the prescribedresequence-migrations.mjsscript. The two affected migration files were already merged tomainby previous contributors; this PR adds their missing rollback files before resequencing, as required.